Refactoring

This commit is contained in:
Piotr Biernat 2024-12-06 16:44:42 +01:00
parent 2cf4d4c25d
commit 5a5f643be8
18 changed files with 62 additions and 66 deletions

20
basket/model/basket.go Normal file
View File

@ -0,0 +1,20 @@
package basket
import (
"time"
)
type BasketModel struct {
State string `db:"state" json:"state"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
}
type BasketItemModel struct {
BasketID string `db:"basket_id" json:"basket_id"`
ProductID int `db:"product_id" json:"product_id"`
Quantity int `db:"quantity" json:"quantity"`
Price float64 `db:"price" json:"price"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
}

View File

@ -1,22 +0,0 @@
package basket
import (
"github.com/jackc/pgtype"
)
type BasketModel struct {
// ID string `db:"id" json:"id"`
State string `db:"state" json:"state"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
}
type BasketItemModel struct {
// ID string `db:"id" json:"id"`
BasketID string `db:"basket_id" json:"basket_id"`
ProductID int `db:"product_id" json:"product_id"`
Quantity int `db:"quantity" json:"quantity"`
Price float64 `db:"price" json:"price"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
}

View File

@ -4,11 +4,11 @@ import (
"time"
)
type GetProductRequest struct {
type GetProductRequestDTO struct {
ProductID int `json:"product_id"`
}
type GetProductResponse struct {
type GetProductResponseDTO struct {
ID int `json:"id"`
PID string `json:"pid"`
Name string `json:"name"`
@ -17,30 +17,30 @@ type GetProductResponse struct {
UpdatedAt time.Duration `json:"updated_at,omitempty"`
}
type GetProductListRequest struct {
type GetProductListRequestDTO struct {
CategoryID int `json:"category_id"`
}
type GetProductListResponse struct {
Products []GetProductResponse `json:"products"`
type GetProductListResponseDTO struct {
Products []GetProductResponseDTO `json:"products"`
}
type AddProductToBasketRequest struct {
type AddProductToBasketRequestDTO struct {
ProductID int `json:"product_id"`
Quantity int `json:"quantity"`
}
type AddProductToBasketResponse struct {
type AddProductToBasketResponseDTO struct {
ProductID int `json:"product_id"`
BasketID string `json:"basket_id"`
}
type RemoveProductFromBasketRequest struct {
type RemoveProductFromBasketRequestDTO struct {
ProductID int `json:"product_id"`
Quantity int `json:"quantity"`
}
type RemoveProductFromBasketResponse struct {
type RemoveProductFromBasketResponseDTO struct {
ProductID int `json:"product_id"`
BasketID string `json:"basket_id"`
}

View File

@ -1,12 +0,0 @@
package model
import "github.com/jackc/pgtype"
type ProductModel struct {
// ID int `db:"id"`
PID string `db:"pid"`
Name string `db:"name"`
Price float64 `db:"price"`
CreatedAt pgtype.Timestamp `db:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at,omitempty"`
}

13
catalog/model/product.go Normal file
View File

@ -0,0 +1,13 @@
package model
import (
"time"
)
type ProductModel struct {
PID string `db:"pid"`
Name string `db:"name"`
Price float64 `db:"price"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at,omitempty"`
}

View File

@ -4,6 +4,6 @@ type ErrorResponseDTO struct {
Error string `json:"error"`
}
func Error(err string) *ErrorResponseDTO { // FIXME Can DTOs have functions?
func NewError(err string) *ErrorResponseDTO { // FIXME Can DTOs have functions?
return &ErrorResponseDTO{err}
}

View File

@ -34,7 +34,7 @@ func (c *Currency) Get() *Currency {
return curr
}
return c.getDefault()
return c.Default()
}
func (c *Currency) Equals(oc *Currency) bool {

View File

@ -1,20 +0,0 @@
package order
import "github.com/jackc/pgtype"
type OrderModel struct {
// ID string `db:"id" json:"id"`
State string `db:"state" json:"state"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
}
type OrderItemModel struct {
// ID string `db:"id" json:"id"`
OrderID string `db:"order_id" json:"order_id"`
ProductID int `db:"product_id" json:"product_id"`
Quantity int `db:"quantity" json:"quantity"`
Price float64 `db:"price" json:"price"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
}

18
order/model/order.go Normal file
View File

@ -0,0 +1,18 @@
package order
import "time"
type OrderModel struct {
State string `db:"state" json:"state"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
}
type OrderItemModel struct {
OrderID string `db:"order_id" json:"order_id"`
ProductID int `db:"product_id" json:"product_id"`
Quantity int `db:"quantity" json:"quantity"`
Price float64 `db:"price" json:"price"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
}

View File

@ -1,7 +1,6 @@
package pricing
type ProductPriceModel struct {
// ID int `db:"id"`
PID string `db:"pid"`
Price int `db:"price"`
}