diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2d7ba9d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +#v1.0.0 + +INTERNAL: + +- Добавлено версионирование модели данных. На данный момент модель под версией 1 + +FIX: + +- При пустой корзине во время оплаты(/cart/pay) больше не будет возвращаться 500, а будет возвращаться 406 + +#v1.0.0 diff --git a/api/openapi/v1/openapi.yaml b/api/openapi/v1/openapi.yaml index a3c1d62..58c552d 100644 --- a/api/openapi/v1/openapi.yaml +++ b/api/openapi/v1/openapi.yaml @@ -412,6 +412,12 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + "406": + description: корзина пустая + content: + application/json: + schema: + $ref: "#/components/schemas/Error" /wallet: patch: diff --git a/internal/interface/controller/http/cart_client/controllers.go b/internal/interface/controller/http/cart_client/controllers.go index 11e5ec7..af97427 100644 --- a/internal/interface/controller/http/cart_client/controllers.go +++ b/internal/interface/controller/http/cart_client/controllers.go @@ -135,6 +135,10 @@ func (receiver *CartController) Pay(ctx *fiber.Ctx) error { receiver.logger.Info("account for pay", zap.Any("acc", account)) + if len(account.Cart) == 0 { + return ctx.Status(fiber.StatusNotAcceptable).SendString("cart is empty") + } + tariffs, err := receiver.hubAdminClient.GetTariffs(ctx.Context(), accessToken, account.Cart) if err != nil { return receiver.middleWare.ErrorOld(ctx, err) diff --git a/internal/models/account.go b/internal/models/account.go index d1ffe9a..bca4e23 100644 --- a/internal/models/account.go +++ b/internal/models/account.go @@ -15,6 +15,7 @@ type Account struct { DeletedAt *time.Time `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"` From string `json:"from" bson:"from"` Partner string `json:"partner" bson:"partner"` + Version uint32 `json:"version" bson:"version"` } func (receiver *Account) Sanitize() *Account { @@ -32,6 +33,7 @@ func (receiver *Account) Sanitize() *Account { //receiver.Partner = "" receiver.DeletedAt = nil receiver.Deleted = false + receiver.Version = mongoVersion return receiver } diff --git a/internal/models/config.go b/internal/models/config.go index 7b2d27c..a0de81a 100644 --- a/internal/models/config.go +++ b/internal/models/config.go @@ -43,9 +43,9 @@ type ServiceConfiguration struct { PubKey string `env:"PUBLIC_KEY"` PrivKey string `env:"PRIVATE_KEY"` ModuleLogger string `env:"MODULE_LOGGER"` - NotificationBotToken string `env:"NOTIFICATION_BOT_TOKEN"` - NotificationChannel int64 `env:"NOTIFICATION_CHANNEL"` - AdminURL string `env:"ADMIN_FRONT_URL"` + NotificationBotToken string `env:"NOTIFICATION_BOT_TOKEN"` + NotificationChannel int64 `env:"NOTIFICATION_CHANNEL"` + AdminURL string `env:"ADMIN_FRONT_URL"` } type KafkaConfiguration struct { @@ -131,3 +131,5 @@ type PlainAuth struct { Username string `env:"MAIL_AUTH_USERNAME,required"` Password string `env:"MAIL_AUTH_PASSWORD,required"` } + +const mongoVersion uint32 = 1 diff --git a/internal/models/currency.go b/internal/models/currency.go index 082c84b..86595ce 100644 --- a/internal/models/currency.go +++ b/internal/models/currency.go @@ -12,6 +12,7 @@ type CurrencyList struct { CreatedAt time.Time `json:"createdAt" bson:"createdAt"` UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` DeletedAt *time.Time `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"` + Version uint32 `json:"version" bson:"version"` } func (receiver *CurrencyList) Sanitize() *CurrencyList { @@ -22,6 +23,7 @@ func (receiver *CurrencyList) Sanitize() *CurrencyList { receiver.UpdatedAt = now receiver.DeletedAt = nil receiver.Deleted = false + receiver.Version = mongoVersion return receiver } diff --git a/internal/models/history.go b/internal/models/history.go index 57f8628..37a502e 100644 --- a/internal/models/history.go +++ b/internal/models/history.go @@ -7,11 +7,12 @@ type History struct { UserID string `json:"userId" bson:"userId"` Comment string `json:"comment" bson:"comment"` Key string `json:"key" bson:"key"` - RawDetails RawDetails `json:"rawDetails" bson:"rawDetails"` + RawDetails RawDetails `json:"rawDetails" bson:"rawDetails"` Deleted bool `json:"isDeleted" bson:"isDeleted"` CreatedAt time.Time `json:"createdAt" bson:"createdAt"` UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` DeletedAt *time.Time `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"` + Version uint32 `json:"version" bson:"version"` } type TariffID struct { @@ -33,7 +34,7 @@ type ReportHistory struct { type RawDetails struct { Tariffs []Tariff `json:"tariffs" bson:"tariffs"` Price int64 `json:"price" bson:"price"` - Comment string `json:"comment" bson:"comment"` + Comment string `json:"comment" bson:"comment"` } func (receiver *History) Sanitize() *History { @@ -44,6 +45,7 @@ func (receiver *History) Sanitize() *History { receiver.UpdatedAt = now receiver.DeletedAt = nil receiver.Deleted = false + receiver.Version = mongoVersion return receiver } diff --git a/internal/models/templategen.go b/internal/models/templategen.go index 4d293db..a0b793a 100644 --- a/internal/models/templategen.go +++ b/internal/models/templategen.go @@ -1,13 +1,13 @@ package models type RespGeneratorService struct { - DocNumber string `json:"docnumber"` + DocNumber string `json:"docnumber"` Date string `json:"date"` OrgTaxNum string `json:"orgtaxnum"` - OrgName string `json:"orgname"` + OrgName string `json:"orgname"` Name string `json:"name"` Amount string `json:"amount"` - Price string `json:"price"` - Sum string `json:"sum"` - Unit string `json:"unit"` + Price string `json:"price"` + Sum string `json:"sum"` + Unit string `json:"unit"` }