Skip to content

Commit

Permalink
destroy cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
agiledragon committed Jul 1, 2018
1 parent 0a39ded commit 8bfe495
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
12 changes: 8 additions & 4 deletions cargo/app/service/cargo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import (
)

func CreateCargo(cargoId string, afterDays uint) {
service.GetCargoServiceInstance().Create(cargoId, afterDays)
service.GetCargoService().Create(cargoId, afterDays)
}

func DelayCargo(cargoId string, days uint) {
service.GetCargoServiceInstance().Delay(cargoId, days)
service.GetCargoService().Delay(cargoId, days)
}

func GetCargoAfterDays(cargoId string) uint {
return service.GetCargoServiceInstance().GetAfterDays(cargoId)
}
return service.GetCargoService().GetAfterDays(cargoId)
}

func DestroyCargo(cargoId string) {
service.GetCargoService().DestroyCargo(cargoId)
}
8 changes: 4 additions & 4 deletions cargo/domain/model/base/entity.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package base

type Entity struct {
Id string
id string
}

func NewEntity(id string) Entity {
return Entity{Id: id}
return Entity{id: id}
}

func (t *Entity) GetId() string {
return t.Id
return t.id
}

func (t *Entity) Equal(other *Entity) bool {
return t.Id == other.Id
return t.id == other.id
}

func (t *Entity) NotEqual(other *Entity) bool {
Expand Down
8 changes: 6 additions & 2 deletions cargo/domain/service/cargo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type CargoService struct {

var cs = &CargoService{}
var once sync.Once
func GetCargoServiceInstance() *CargoService {
func GetCargoService() *CargoService {
once.Do(func() {
cs.repo = model.GetCargoRepo()
cs.provider = model.GetCargoProvider()
Expand Down Expand Up @@ -42,4 +42,8 @@ func (t *CargoService) GetAfterDays(cargoId string) uint {
panic("not found cargo by cargoId")
}
return cargo.GetAfterDays()
}
}

func (t *CargoService) DestroyCargo(cargoId string) {
t.repo.Remove(cargoId)
}
5 changes: 4 additions & 1 deletion cargo/test/cargo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
. "github.com/smartystreets/goconvey/convey"
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model"
"github.com/agiledragon/ddd-sample-in-golang/cargo/app/service"
"fmt"
)

type SpyCargoProvider struct {
Expand Down Expand Up @@ -45,12 +46,14 @@ func TestCargo(t *testing.T) {
const cargoId = "1"

Convey("TestCargo", t, func() {

Convey("create cargo", func() {
const afterDays = 10
service.CreateCargo(cargoId, afterDays)
So(provider.cargoId, ShouldEqual, cargoId)
So(provider.afterDays, ShouldEqual, afterDays)
So(service.GetCargoAfterDays(cargoId), ShouldEqual, afterDays)
service.DestroyCargo(cargoId)
})

Convey("delay cargo", func() {
Expand All @@ -61,7 +64,7 @@ func TestCargo(t *testing.T) {
So(provider.cargoId, ShouldEqual, cargoId)
So(provider.afterDays, ShouldEqual, afterDays + days)
So(service.GetCargoAfterDays(cargoId), ShouldEqual, afterDays + days)

service.DestroyCargo(cargoId)
})
})
}
Expand Down

0 comments on commit 8bfe495

Please sign in to comment.