From ef1526a1acb6a977d4243995622e108178f3cd75 Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Sun, 5 May 2024 18:19:56 +0200 Subject: [PATCH] refactor: move currency to money package and add new type Price, refactor api and use price there too --- api/v1/openapi.yaml | 59 +++++------- internal/faker/faker.go | 56 ++++++------ internal/{currency => money}/currency.go | 2 +- internal/money/price.go | 8 ++ internal/server/api.gen.go | 112 +++++++++++------------ internal/server/api.go | 17 ++-- pkg/training/model.go | 10 +- 7 files changed, 127 insertions(+), 137 deletions(-) rename internal/{currency => money}/currency.go (90%) create mode 100644 internal/money/price.go diff --git a/api/v1/openapi.yaml b/api/v1/openapi.yaml index d74c83f..5d7b908 100644 --- a/api/v1/openapi.yaml +++ b/api/v1/openapi.yaml @@ -350,32 +350,17 @@ components: path: gitlab.mareshq.com/hq/yggdrasil/pkg/training TrainingPrice: - type: object - properties: - currency: - type: string - enum: - - CZK - - EUR - - USD - x-go-type: currency.Currency - x-go-type-package: - path: gitlab.mareshq.com/hq/yggdrasil/internal/currency - amount: - type: number - minimum: 0 - x-go-type: decimal.Decimal - x-go-type-package: - path: github.com/shopspring/decimal - type: - type: string - enum: - - OPEN - - CORPORATE - required: - - currency - - amount - - type + allOf: + - $ref: "#/components/schemas/Price" + - type: object + properties: + type: + type: string + enum: + - OPEN + - CORPORATE + required: + - type CreateTrainingDateRequest: $ref: "#/components/schemas/NewTrainingDate" @@ -443,7 +428,7 @@ components: format: int8 minimum: 1 price: - $ref: "#/components/schemas/TrainingDatePrice" + $ref: "#/components/schemas/Price" required: - trainingID - date @@ -465,7 +450,14 @@ components: required: - id - TrainingDatePrice: + TrainingDateID: + type: string + format: uuid + x-go-type: training.TrainingDateID + x-go-type-import: + path: gitlab.mareshq.com/hq/yggdrasil/pkg/training + + Price: type: object properties: currency: @@ -474,9 +466,9 @@ components: - CZK - EUR - USD - x-go-type: currency.Currency + x-go-type: money.Currency x-go-type-package: - path: gitlab.mareshq.com/hq/yggdrasil/internal/currency + path: gitlab.mareshq.com/hq/yggdrasil/internal/money amount: type: number minimum: 0 @@ -487,13 +479,6 @@ components: - currency - amount - TrainingDateID: - type: string - format: uuid - x-go-type: training.TrainingDateID - x-go-type-import: - path: gitlab.mareshq.com/hq/yggdrasil/pkg/training - ProblemDetails: type: object description: > diff --git a/internal/faker/faker.go b/internal/faker/faker.go index 278ce4c..fefe3a8 100644 --- a/internal/faker/faker.go +++ b/internal/faker/faker.go @@ -5,7 +5,7 @@ import ( "time" "github.com/shopspring/decimal" - "gitlab.mareshq.com/hq/yggdrasil/internal/currency" + "gitlab.mareshq.com/hq/yggdrasil/internal/money" "gitlab.mareshq.com/hq/yggdrasil/pkg/training" ) @@ -30,22 +30,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(450), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(2000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(9900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(49000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -57,22 +57,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(200), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(1000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(4900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(24000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -84,22 +84,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(200), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(1000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(4900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(24000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -111,22 +111,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(200), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(1000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(4900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(24000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -138,22 +138,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(200), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(1000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(4900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(24000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -165,22 +165,22 @@ func (f *Faker) GenerateFakeData() error { Pricing: []training.TrainingPrice{ { Amount: decimal.NewFromInt(450), - Currency: currency.USD, + Currency: money.USD, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(2000), - Currency: currency.USD, + Currency: money.USD, Type: training.CorporateTrainingPrice, }, { Amount: decimal.NewFromInt(9900), - Currency: currency.CZK, + Currency: money.CZK, Type: training.OpenTrainingPrice, }, { Amount: decimal.NewFromInt(49000), - Currency: currency.CZK, + Currency: money.CZK, Type: training.CorporateTrainingPrice, }, }, @@ -219,9 +219,9 @@ func (f *Faker) GenerateFakeData() error { amount = decimal.NewFromInt(9900) } - cur := currency.CZK + cur := money.CZK if online { - cur = currency.EUR + cur = money.EUR if t.Days == 2 { amount = decimal.NewFromInt(450) @@ -238,7 +238,7 @@ func (f *Faker) GenerateFakeData() error { Location: location, Address: "TBD", Capacity: 12, - Price: training.TrainingDatePrice{ + Price: money.Price{ Amount: amount, Currency: cur, }, diff --git a/internal/currency/currency.go b/internal/money/currency.go similarity index 90% rename from internal/currency/currency.go rename to internal/money/currency.go index 208fbfc..4b5e35b 100644 --- a/internal/currency/currency.go +++ b/internal/money/currency.go @@ -1,4 +1,4 @@ -package currency +package money type Currency string diff --git a/internal/money/price.go b/internal/money/price.go new file mode 100644 index 0000000..aea08f2 --- /dev/null +++ b/internal/money/price.go @@ -0,0 +1,8 @@ +package money + +import "github.com/shopspring/decimal" + +type Price struct { + Amount decimal.Decimal + Currency Currency +} diff --git a/internal/server/api.gen.go b/internal/server/api.gen.go index 9139831..fbcec88 100644 --- a/internal/server/api.gen.go +++ b/internal/server/api.gen.go @@ -18,7 +18,7 @@ import ( "github.com/gofiber/fiber/v2" "github.com/oapi-codegen/runtime" "github.com/shopspring/decimal" - "gitlab.mareshq.com/hq/yggdrasil/internal/currency" + "gitlab.mareshq.com/hq/yggdrasil/internal/money" "gitlab.mareshq.com/hq/yggdrasil/pkg/training" ) @@ -71,14 +71,20 @@ type NewTraining struct { // NewTrainingDate defines model for NewTrainingDate. type NewTrainingDate struct { - Address string `json:"address"` - Capacity int8 `json:"capacity"` - Date time.Time `json:"date"` - Days int8 `json:"days"` - IsOnline bool `json:"isOnline"` - Location string `json:"location"` - Price TrainingDatePrice `json:"price"` - StartTime string `json:"startTime"` + Address string `json:"address"` + Capacity int8 `json:"capacity"` + Date time.Time `json:"date"` + Days int8 `json:"days"` + IsOnline bool `json:"isOnline"` + Location string `json:"location"` + Price Price `json:"price"` + StartTime string `json:"startTime"` +} + +// Price defines model for Price. +type Price struct { + Amount decimal.Decimal `json:"amount"` + Currency money.Currency `json:"currency"` } // ProblemDetails Schema that carries the details of an error in an HTTP response. See https://datatracker.ietf.org/doc/html/rfc7807 for more information. @@ -110,33 +116,27 @@ type Training struct { // TrainingDate defines model for TrainingDate. type TrainingDate struct { - Address string `json:"address"` - Capacity int8 `json:"capacity"` - Date time.Time `json:"date"` - Days int8 `json:"days"` - Id TrainingDateID `json:"id"` - IsOnline bool `json:"isOnline"` - Location string `json:"location"` - Price TrainingDatePrice `json:"price"` - StartTime string `json:"startTime"` + Address string `json:"address"` + Capacity int8 `json:"capacity"` + Date time.Time `json:"date"` + Days int8 `json:"days"` + Id TrainingDateID `json:"id"` + IsOnline bool `json:"isOnline"` + Location string `json:"location"` + Price Price `json:"price"` + StartTime string `json:"startTime"` } // TrainingDateID defines model for TrainingDateID. type TrainingDateID = training.TrainingDateID -// TrainingDatePrice defines model for TrainingDatePrice. -type TrainingDatePrice struct { - Amount decimal.Decimal `json:"amount"` - Currency currency.Currency `json:"currency"` -} - // TrainingID defines model for TrainingID. type TrainingID = training.TrainingID // TrainingPrice defines model for TrainingPrice. type TrainingPrice struct { Amount decimal.Decimal `json:"amount"` - Currency currency.Currency `json:"currency"` + Currency money.Currency `json:"currency"` Type TrainingPriceType `json:"type"` } @@ -1344,37 +1344,37 @@ func (sh *strictHandler) ListTrainingUpcomingDates(ctx *fiber.Ctx, trainingID Tr // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xaX3PbuBH/Khi0b6VFpZebu9FT3Si90zSNVcfuQ9M8QORKREICNLC0o/Hok/Sp36X9", - "Xh0AJEVSlEhZ0li+8ZNlkNj97f/Fgo80kEkqBQjUdPRIU6ZYAgjK/nejGBdcLMYMYTI2KyHoQPEUuRR0", - "VD4n5gUyGVOPcrOeMoyoRwVLgI4o1ql4VMFdxhWEdIQqA4/qIIKEGf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", + "nXPqFoq+5NFUdX1S6Eqcrpa1j922rx/8vmhU1hE1Aeu+JD6t2pyl23/G4NrDOotje70SzNVvKTZUqdUj", + "tUJzu0b6xy0fODhA4Sua3KlO2Mobpgv33UV7NmyNgsoxzwsb7+Uipu0oqrXgYGXe/0qk/ALYn5E0a2Gk", + "3nvtT8rL17b2rrpXbRseDESP2pbZV/asba/kV07dvq61NZ363XWxWQyPMy9sPujcUj5L+x1NxVwVyq5W", + "p19HO3YzgaNLG5s/53rVtrg21diWPmwAHnF/TIp52fMSwuqSm7Ls0Hbt7XFe76eLCdCOzZqx1jF2bBbY", + "fm3bURj/IM1eV2QeXUpvNH89yO3RAb4Wv4fuG3cuAMODAulbAP63mshOF91eOHYYtbR+L/YmWsv2L9ze", + "TIvZMpDpHKkZKfZ7BEdKQ00ZsJiE8ACxTBMQmH+7UBubj3w/Ns9FUuPoh+FwaPnKF2tKPC+8RRM2lRnW", + "xkX5ZH2Fb3m7/G8AAAD//6DZ/Q5BMwAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/internal/server/api.go b/internal/server/api.go index 7bc021b..de279af 100644 --- a/internal/server/api.go +++ b/internal/server/api.go @@ -5,6 +5,7 @@ import ( "time" "github.com/gofiber/fiber/v2" + "gitlab.mareshq.com/hq/yggdrasil/internal/money" "gitlab.mareshq.com/hq/yggdrasil/pkg/training" ) @@ -211,7 +212,7 @@ func (h *APIHandlers) ListTrainingDates(ctx context.Context, req ListTrainingDat Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, @@ -222,7 +223,7 @@ func (h *APIHandlers) ListTrainingDates(ctx context.Context, req ListTrainingDat } func (h *APIHandlers) CreateTrainingDate(ctx context.Context, req CreateTrainingDateRequestObject) (CreateTrainingDateResponseObject, error) { - price := training.TrainingDatePrice{ + price := money.Price{ Amount: req.Body.Price.Amount, Currency: req.Body.Price.Currency, } @@ -267,7 +268,7 @@ func (h *APIHandlers) CreateTrainingDate(ctx context.Context, req CreateTraining Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, @@ -320,7 +321,7 @@ func (h *APIHandlers) GetTrainingDate(ctx context.Context, req GetTrainingDateRe Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, @@ -328,7 +329,7 @@ func (h *APIHandlers) GetTrainingDate(ctx context.Context, req GetTrainingDateRe } func (h *APIHandlers) UpdateTrainingDate(ctx context.Context, req UpdateTrainingDateRequestObject) (UpdateTrainingDateResponseObject, error) { - price := training.TrainingDatePrice{ + price := money.Price{ Amount: req.Body.Price.Amount, Currency: req.Body.Price.Currency, } @@ -374,7 +375,7 @@ func (h *APIHandlers) UpdateTrainingDate(ctx context.Context, req UpdateTraining Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, @@ -416,7 +417,7 @@ func (h *APIHandlers) ListAllUpcomingTrainingDates(ctx context.Context, req List Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, @@ -449,7 +450,7 @@ func (h *APIHandlers) ListTrainingUpcomingDates(ctx context.Context, req ListTra Location: td.Location, Address: td.Address, Capacity: td.Capacity, - Price: TrainingDatePrice{ + Price: Price{ Amount: td.Price.Amount, Currency: td.Price.Currency, }, diff --git a/pkg/training/model.go b/pkg/training/model.go index e129fb2..b86b50d 100644 --- a/pkg/training/model.go +++ b/pkg/training/model.go @@ -5,7 +5,7 @@ import ( "github.com/google/uuid" "github.com/shopspring/decimal" - "gitlab.mareshq.com/hq/yggdrasil/internal/currency" + "gitlab.mareshq.com/hq/yggdrasil/internal/money" ) type TrainingID = uuid.UUID @@ -24,7 +24,7 @@ type Training struct { type TrainingPrice struct { Amount decimal.Decimal - Currency currency.Currency + Currency money.Currency Type TrainingPriceType } @@ -52,10 +52,6 @@ type TrainingDate struct { Location string Address string Capacity int8 - Price TrainingDatePrice + Price money.Price } -type TrainingDatePrice struct { - Amount decimal.Decimal - Currency currency.Currency -}