Skip to content

Commit

Permalink
minor fix & update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
irahardianto committed Dec 16, 2017
1 parent c73c3f7 commit 0d1ecb5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,44 @@ Every implementation should only be by using interface, there should be no direc

- PlayerService -> implement IPlayerRepository, instead of direct PlayerRepository

type PlayerService struct {
PlayerRepository interfaces.IPlayerRepository
}

func (service *PlayerService) GetScores(player1Name string, player2Name string) (string, error) {
type PlayerService struct {
PlayerRepository interfaces.IPlayerRepository
}

baseScore := [4]string{"Love", "Fifteen", "Thirty", "Forty"}
var result string
func (service *PlayerService) GetScores(player1Name string, player2Name string) (string, error) {

player1, err := service.PlayerRepository.GetPlayerByName(player1Name)
if err != nil {
//Handle error
}
baseScore := [4]string{"Love", "Fifteen", "Thirty", "Forty"}
var result string

player2, err := service.PlayerRepository.GetPlayerByName(player2Name)
if err != nil {
//Handle error
}
player1, err := service.PlayerRepository.GetPlayerByName(player1Name)
if err != nil {
//Handle error
}

if player1.Score < 4 && player2.Score < 4 && !(player1.Score+player2.Score == 6) {
player2, err := service.PlayerRepository.GetPlayerByName(player2Name)
if err != nil {
//Handle error
}

s := baseScore[player1.Score]
if player1.Score < 4 && player2.Score < 4 && !(player1.Score+player2.Score == 6) {

if player1.Score == player2.Score {
result = s + "-All"
} else {
result = s + "-" + baseScore[player2.Score]
}
}
s := baseScore[player1.Score]

if player1.Score == player2.Score {
result = "Deuce"
}
if player1.Score == player2.Score {
result = s + "-All"
} else {
result = s + "-" + baseScore[player2.Score]
}
}

return result, nil
}
if player1.Score == player2.Score {
result = "Deuce"
}

return result, nil
}

If you look into the implementation of these lines

scores, err := controller.PlayerService.GetScores(player1Name, player2Name)
Expand Down
2 changes: 1 addition & 1 deletion infrastructures/SQLiteHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (handler *SQLiteHandler) Execute(statement string) {
handler.Conn.Exec(statement)
}

func (handler *SQLiteHandler) Query(statement string) (interfaces.Row, error) {
func (handler *SQLiteHandler) Query(statement string) (interfaces.IRow, error) {
//fmt.Println(statement)
rows, err := handler.Conn.Query(statement)

Expand Down
6 changes: 3 additions & 3 deletions interfaces/IDbHandler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package interfaces

type DbHandler interface {
type IDbHandler interface {
Execute(statement string)
Query(statement string) (Row, error)
Query(statement string) (IRow, error)
}

type Row interface {
type IRow interface {
Scan(dest ...interface{}) error
Next() bool
}
3 changes: 1 addition & 2 deletions repositories/PlayerRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package repositories

import (
"github.com/afex/hystrix-go/hystrix"
"github.com/irahardianto/service-pattern-go/infrastructures"
"github.com/irahardianto/service-pattern-go/interfaces"
"github.com/irahardianto/service-pattern-go/models"

Expand Down Expand Up @@ -36,7 +35,7 @@ func (repository *PlayerRepositoryWithCircuitBreaker) GetPlayerByName(name strin
}

type PlayerRepository struct {
infrastructures.SQLiteHandler
interfaces.IDbHandler
}

func (repository *PlayerRepository) GetPlayerByName(name string) (models.PlayerModel, error) {
Expand Down
2 changes: 1 addition & 1 deletion servicecontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (k *kernel) InjectPlayerController() controllers.PlayerController {
sqliteHandler := &infrastructures.SQLiteHandler{}
sqliteHandler.Conn = sqlConn

playerRepository := &repositories.PlayerRepository{*sqliteHandler}
playerRepository := &repositories.PlayerRepository{sqliteHandler}

playerService := &services.PlayerService{}
playerService.PlayerRepository = &repositories.PlayerRepositoryWithCircuitBreaker{playerRepository}
Expand Down

0 comments on commit 0d1ecb5

Please sign in to comment.