Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
irahardianto committed Dec 16, 2017
1 parent 0d1ecb5 commit ac6115f
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,30 @@ The aim of the architecture is to produce a system that are:

Every implementation should only be by using interface, there should be no direct access from the implementor to implementation, that way we can inject its dependency and replace it with mock object during unit tests. For example:

- PlayerController -> implement IPlayerService, instead of direct PlayerService
PlayerController -> implement IPlayerService, instead of direct PlayerService


type PlayerController struct {
PlayerService interfaces.IPlayerService
PlayerHelper helpers.PlayerHelper
}

func (controller *PlayerController) GetPlayerScore(res http.ResponseWriter, req *http.Request) {
type PlayerController struct {
PlayerService interfaces.IPlayerService
PlayerHelper helpers.PlayerHelper
}

player1Name := chi.URLParam(req, "player1")
player2Name := chi.URLParam(req, "player2")
func (controller *PlayerController) GetPlayerScore(res http.ResponseWriter, req *http.Request) {

scores, err := controller.PlayerService.GetScores(player1Name, player2Name)
if err != nil {
//Handle error
}
player1Name := chi.URLParam(req, "player1")
player2Name := chi.URLParam(req, "player2")

response := controller.PlayerHelper.BuildScoresVM(scores)
scores, err := controller.PlayerService.GetScores(player1Name, player2Name)
if err != nil {
//Handle error
}
response := controller.PlayerHelper.BuildScoresVM(scores)

json.NewEncoder(res).Encode(response)
}
json.NewEncoder(res).Encode(response)
}

- PlayerService -> implement IPlayerRepository, instead of direct PlayerRepository
PlayerService -> implement IPlayerRepository, instead of direct PlayerRepository


type PlayerService struct {
Expand All @@ -120,15 +120,15 @@ Every implementation should only be by using interface, there should be no direc
//Handle error
}

if player1.Score < 4 && player2.Score < 4 && !(player1.Score+player2.Score == 6) {
if player1.Score < 4 && player2.Score < 4 && !(player1.Score+player2.Score == 6) {

s := baseScore[player1.Score]
s := baseScore[player1.Score]

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

if player1.Score == player2.Score {
Expand Down

0 comments on commit ac6115f

Please sign in to comment.