diff --git a/http/basket.go b/basket/dto/dto.go similarity index 71% rename from http/basket.go rename to basket/dto/dto.go index 9385ba9..b89314d 100644 --- a/http/basket.go +++ b/basket/dto/dto.go @@ -1,22 +1,22 @@ -package http +package basket import "time" -type GetBasketRequest struct { +type GetBasketRequestDTO struct { BasketID string `json:"basket_id"` } -type GetBasketResponse struct { +type GetBasketResponseDTO struct { ID string `json:"id"` State string `json:"state"` CreatedAt time.Duration `json:"created_at"` UpdatedAt time.Duration `json:"updated_at,omitempty"` } -type GetBasketItemsRequest struct { +type GetBasketItemsRequestDTO struct { } -type GetBasketItemsResponse struct { +type GetBasketItemsResponseDTO struct { ID string `json:"id"` BasketID string `json:"basket_id"` ProductID int `json:"product_id"` @@ -26,10 +26,10 @@ type GetBasketItemsResponse struct { UpdatedAt time.Duration `json:"updated_at,omitempty"` } -type BasketCheckoutRequest struct { +type BasketCheckoutRequestDTO struct { BasketID string `json:"basket_id"` } -type BasketCheckoutResponse struct { +type BasketCheckoutResponseDTO struct { ID string `json:"basket_id"` } diff --git a/model/basket.go b/basket/entity/entity.go similarity index 90% rename from model/basket.go rename to basket/entity/entity.go index 766b646..c37f36b 100644 --- a/model/basket.go +++ b/basket/entity/entity.go @@ -1,17 +1,17 @@ -package model +package basket import ( "github.com/jackc/pgtype" ) -type BasketModel struct { +type BasketEntity 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 { +type BasketItemEntity struct { ID string `db:"id" json:"id"` BasketID string `db:"basket_id" json:"basket_id"` ProductID int `db:"product_id" json:"product_id"` diff --git a/basket/model/model.go b/basket/model/model.go new file mode 100644 index 0000000..6acffac --- /dev/null +++ b/basket/model/model.go @@ -0,0 +1,22 @@ +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"` +} diff --git a/http/catalog.go b/catalog/dto/dto.go similarity index 98% rename from http/catalog.go rename to catalog/dto/dto.go index dfb445a..c360e8b 100644 --- a/http/catalog.go +++ b/catalog/dto/dto.go @@ -1,4 +1,4 @@ -package http +package catalog import ( "time" diff --git a/model/catalog.go b/catalog/entity/entity.go similarity index 87% rename from model/catalog.go rename to catalog/entity/entity.go index cc8f4b9..084cf53 100644 --- a/model/catalog.go +++ b/catalog/entity/entity.go @@ -1,8 +1,8 @@ -package model +package catalog import "github.com/jackc/pgtype" -type ProductModel struct { +type ProductEntity struct { ID int `db:"id"` PID string `db:"pid"` Name string `db:"name"` diff --git a/catalog/model/model.go b/catalog/model/model.go new file mode 100644 index 0000000..5e5ff31 --- /dev/null +++ b/catalog/model/model.go @@ -0,0 +1,12 @@ +package catalog + +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"` +} diff --git a/common/dto/error.go b/common/dto/error.go new file mode 100644 index 0000000..de697d7 --- /dev/null +++ b/common/dto/error.go @@ -0,0 +1,9 @@ +package common + +type ErrorResponseDTO struct { + Error string `json:"error"` +} + +func Error(err string) *ErrorResponseDTO { // FIXME Can DTOs have functions? + return &ErrorResponseDTO{err} +} diff --git a/common/dto/health.go b/common/dto/health.go new file mode 100644 index 0000000..3e8d506 --- /dev/null +++ b/common/dto/health.go @@ -0,0 +1,5 @@ +package common + +type HealthResponseDTO struct { + Status string `json:"status"` +} diff --git a/http/error.go b/http/error.go deleted file mode 100644 index 242e86a..0000000 --- a/http/error.go +++ /dev/null @@ -1,9 +0,0 @@ -package http - -type ErrorResponse struct { - Error string `json:"error"` -} - -func Error(err string) *ErrorResponse { - return &ErrorResponse{err} -} diff --git a/http/health.go b/http/health.go deleted file mode 100644 index ec996a1..0000000 --- a/http/health.go +++ /dev/null @@ -1,5 +0,0 @@ -package http - -type HealthResponse struct { - Status string `json:"status,omitempty"` -} diff --git a/http/order.go b/http/order.go deleted file mode 100644 index 498a3bf..0000000 --- a/http/order.go +++ /dev/null @@ -1,8 +0,0 @@ -package http - -type UpdateOrderStatusRequest struct { - Status string `json:"status"` -} - -type UpdateOrderStatusResponse struct { -} diff --git a/http/pricing.go b/http/pricing.go deleted file mode 100644 index b613e83..0000000 --- a/http/pricing.go +++ /dev/null @@ -1,9 +0,0 @@ -package http - -type ProductPriceRequest struct { - ProductId int `json:"product_id"` -} - -type ProductPriceResponse struct { - Price int `json:"price"` -} diff --git a/http/identity.go b/identity/dto/dto.go similarity index 55% rename from http/identity.go rename to identity/dto/dto.go index bb15239..2440a2e 100644 --- a/http/identity.go +++ b/identity/dto/dto.go @@ -1,10 +1,10 @@ -package http +package identity -type AuthLoginRequest struct { +type AuthLoginRequestDTO struct { Username string `json:"username"` Password string `json:"password"` } -type AuthLoginResponse struct { +type AuthLoginResponseDTO struct { Token string `json:"jwt_token"` } diff --git a/order/dto/dto.go b/order/dto/dto.go new file mode 100644 index 0000000..6e67e8b --- /dev/null +++ b/order/dto/dto.go @@ -0,0 +1,8 @@ +package order + +type UpdateOrderStatusRequestDTO struct { + Status string `json:"status"` +} + +type UpdateOrderStatusResponseDTO struct { +} diff --git a/model/order.go b/order/entity/entity.go similarity index 90% rename from model/order.go rename to order/entity/entity.go index 042ea97..dd3e862 100644 --- a/model/order.go +++ b/order/entity/entity.go @@ -1,15 +1,15 @@ -package model +package order import "github.com/jackc/pgtype" -type OrderModel struct { +type OrderEntity 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 { +type OrderItemEntity struct { ID string `db:"id" json:"id"` OrderID string `db:"order_id" json:"order_id"` ProductID int `db:"product_id" json:"product_id"` diff --git a/order/model/model.go b/order/model/model.go new file mode 100644 index 0000000..ce197e5 --- /dev/null +++ b/order/model/model.go @@ -0,0 +1,20 @@ +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"` +} diff --git a/pricing/dto/dto.go b/pricing/dto/dto.go new file mode 100644 index 0000000..cdb5fe6 --- /dev/null +++ b/pricing/dto/dto.go @@ -0,0 +1,9 @@ +package pricing + +type ProductPriceRequestDTO struct { + ProductId int `json:"product_id"` +} + +type ProductPriceResponseDTO struct { + Price int `json:"price"` +} diff --git a/pricing/entity/entity.go b/pricing/entity/entity.go new file mode 100644 index 0000000..b34aafa --- /dev/null +++ b/pricing/entity/entity.go @@ -0,0 +1,7 @@ +package pricing + +type ProductPriceEntity struct { + ID int `db:"id"` + PID string `db:"pid"` + Price int `db:"price"` +} diff --git a/model/pricing.go b/pricing/model/model.go similarity index 66% rename from model/pricing.go rename to pricing/model/model.go index 6ab3884..852ecae 100644 --- a/model/pricing.go +++ b/pricing/model/model.go @@ -1,7 +1,7 @@ -package model +package pricing type ProductPriceModel struct { - ID int `db:"id"` + // ID int `db:"id"` PID string `db:"pid"` Price int `db:"price"` }