Skip to content

Commit

Permalink
GetId to Id
Browse files Browse the repository at this point in the history
  • Loading branch information
agiledragon committed Jul 14, 2018
1 parent a3a1ee2 commit f99758f
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 111 deletions.
10 changes: 5 additions & 5 deletions cargo/app/service/cargo_api.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package service

import (
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/service"
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/service"
)

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

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

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

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

type AggregateRoot struct {
Entity
Entity
}

func NewAggregateRoot(id string) AggregateRoot {
return AggregateRoot{NewEntity(id)}
}
return AggregateRoot{NewEntity(id)}
}
14 changes: 7 additions & 7 deletions cargo/domain/model/base/entity.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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
func (t *Entity) Id() string {
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 {
return !t.Equal(other)
}
return !t.Equal(other)
}
3 changes: 1 addition & 2 deletions cargo/domain/model/base/value_object.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package base

type ValueObject struct {

}
}
16 changes: 8 additions & 8 deletions cargo/domain/model/cargo.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package model

import (
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model/base"
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model/base"
)

type Cargo struct {
base.AggregateRoot
Delivery Delivery
base.AggregateRoot
Delivery Delivery
}

func newCargo(cargoId string, delivery Delivery) *Cargo {
return &Cargo{AggregateRoot: base.NewAggregateRoot(cargoId), Delivery: delivery}
return &Cargo{AggregateRoot: base.NewAggregateRoot(cargoId), Delivery: delivery}
}

func (t *Cargo) Delay(days uint) {
afterDays := t.GetAfterDays() + days
t.Delivery = Delivery{AfterDays: afterDays}
afterDays := t.GetAfterDays() + days
t.Delivery = Delivery{AfterDays: afterDays}
}

func (t *Cargo) GetAfterDays() uint {
return t.Delivery.AfterDays
}
return t.Delivery.AfterDays
}
7 changes: 3 additions & 4 deletions cargo/domain/model/cargo_factory.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package model

type CargoFactory struct {

}

func (t CargoFactory) Create(cargoId string, afterDays uint) *Cargo {
delivery := Delivery{AfterDays: afterDays}
return newCargo(cargoId, delivery)
}
delivery := Delivery{AfterDays: afterDays}
return newCargo(cargoId, delivery)
}
6 changes: 3 additions & 3 deletions cargo/domain/model/cargo_provider.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package model

type CargoProvider interface {
Confirm(cargo *Cargo)
Confirm(cargo *Cargo)
}

var p CargoProvider = nil

func SetCargoProvider(provider CargoProvider) {
p = provider
p = provider
}

func GetCargoProvider() CargoProvider {
return p
return p
}
12 changes: 6 additions & 6 deletions cargo/domain/model/cargo_repo.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package model

type CargoRepo interface {
Add(cargo *Cargo)
Get(cargoId string) *Cargo
Update(cargo *Cargo)
Remove(cargoId string)
Add(cargo *Cargo)
Get(cargoId string) *Cargo
Update(cargo *Cargo)
Remove(cargoId string)
}

var r CargoRepo = nil

func SetCargoRepo(repo CargoRepo) {
r = repo
r = repo
}

func GetCargoRepo() CargoRepo {
return r
return r
}
7 changes: 3 additions & 4 deletions cargo/domain/model/delivery.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package model

import (
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model/base"
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model/base"
)

type Delivery struct {
base.ValueObject
AfterDays uint
base.ValueObject
AfterDays uint
}

51 changes: 26 additions & 25 deletions cargo/domain/service/cargo_service.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
package service

import (
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model"
"sync"
"github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model"
"sync"
)

type CargoService struct {
repo model.CargoRepo
provider model.CargoProvider
repo model.CargoRepo
provider model.CargoProvider
}

var cs = &CargoService{}
var once sync.Once

func GetCargoService() *CargoService {
once.Do(func() {
cs.repo = model.GetCargoRepo()
cs.provider = model.GetCargoProvider()
})
return cs
once.Do(func() {
cs.repo = model.GetCargoRepo()
cs.provider = model.GetCargoProvider()
})
return cs
}

func (t *CargoService) Create(cargoId string, afterDays uint) {
cargo := model.CargoFactory{}.Create(cargoId, afterDays)
t.repo.Add(cargo)
t.provider.Confirm(cargo)
cargo := model.CargoFactory{}.Create(cargoId, afterDays)
t.repo.Add(cargo)
t.provider.Confirm(cargo)
}

func (t *CargoService) Delay(cargoId string, days uint) {
cargo := t.repo.Get(cargoId)
if cargo == nil {
panic("not found cargo by cargoId")
}
cargo.Delay(days)
t.repo.Update(cargo)
t.provider.Confirm(cargo)
cargo := t.repo.Get(cargoId)
if cargo == nil {
panic("not found cargo by cargoId")
}
cargo.Delay(days)
t.repo.Update(cargo)
t.provider.Confirm(cargo)
}

func (t *CargoService) GetAfterDays(cargoId string) uint {
cargo := t.repo.Get(cargoId)
if cargo == nil {
panic("not found cargo by cargoId")
}
return cargo.GetAfterDays()
cargo := t.repo.Get(cargoId)
if cargo == nil {
panic("not found cargo by cargoId")
}
return cargo.GetAfterDays()
}

func (t *CargoService) DestroyCargo(cargoId string) {
t.repo.Remove(cargoId)
t.repo.Remove(cargoId)
}
3 changes: 1 addition & 2 deletions cargo/infra/cargo_provider_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package infra
import "github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model"

type CargoProviderImpl struct {

}

func (t *CargoProviderImpl) Confirm(cargo *model.Cargo) {

}
}
5 changes: 2 additions & 3 deletions cargo/infra/cargo_repo_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package infra
import "github.com/agiledragon/ddd-sample-in-golang/cargo/domain/model"

type CargoRepoImpl struct {

}

func (t *CargoRepoImpl) Add(cargo *model.Cargo) {

}

func (t *CargoRepoImpl) Get(cargoId string) *model.Cargo {
return nil
return nil
}

func (t *CargoRepoImpl) Update(cargo *model.Cargo) {
Expand All @@ -20,4 +19,4 @@ func (t *CargoRepoImpl) Update(cargo *model.Cargo) {

func (t *CargoRepoImpl) Remove(CargoId string) {

}
}
Loading

0 comments on commit f99758f

Please sign in to comment.