Restructurization

This commit is contained in:
Piotr Biernat 2024-12-06 13:24:56 +01:00
parent f9acb885a8
commit d7d8ac5091
19 changed files with 113 additions and 52 deletions

View File

@ -1,22 +1,22 @@
package http package basket
import "time" import "time"
type GetBasketRequest struct { type GetBasketRequestDTO struct {
BasketID string `json:"basket_id"` BasketID string `json:"basket_id"`
} }
type GetBasketResponse struct { type GetBasketResponseDTO struct {
ID string `json:"id"` ID string `json:"id"`
State string `json:"state"` State string `json:"state"`
CreatedAt time.Duration `json:"created_at"` CreatedAt time.Duration `json:"created_at"`
UpdatedAt time.Duration `json:"updated_at,omitempty"` UpdatedAt time.Duration `json:"updated_at,omitempty"`
} }
type GetBasketItemsRequest struct { type GetBasketItemsRequestDTO struct {
} }
type GetBasketItemsResponse struct { type GetBasketItemsResponseDTO struct {
ID string `json:"id"` ID string `json:"id"`
BasketID string `json:"basket_id"` BasketID string `json:"basket_id"`
ProductID int `json:"product_id"` ProductID int `json:"product_id"`
@ -26,10 +26,10 @@ type GetBasketItemsResponse struct {
UpdatedAt time.Duration `json:"updated_at,omitempty"` UpdatedAt time.Duration `json:"updated_at,omitempty"`
} }
type BasketCheckoutRequest struct { type BasketCheckoutRequestDTO struct {
BasketID string `json:"basket_id"` BasketID string `json:"basket_id"`
} }
type BasketCheckoutResponse struct { type BasketCheckoutResponseDTO struct {
ID string `json:"basket_id"` ID string `json:"basket_id"`
} }

View File

@ -1,17 +1,17 @@
package model package basket
import ( import (
"github.com/jackc/pgtype" "github.com/jackc/pgtype"
) )
type BasketModel struct { type BasketEntity struct {
ID string `db:"id" json:"id"` ID string `db:"id" json:"id"`
State string `db:"state" json:"state"` State string `db:"state" json:"state"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"` CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"` UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
} }
type BasketItemModel struct { type BasketItemEntity struct {
ID string `db:"id" json:"id"` ID string `db:"id" json:"id"`
BasketID string `db:"basket_id" json:"basket_id"` BasketID string `db:"basket_id" json:"basket_id"`
ProductID int `db:"product_id" json:"product_id"` ProductID int `db:"product_id" json:"product_id"`

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

@ -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"`
}

View File

@ -1,4 +1,4 @@
package http package catalog
import ( import (
"time" "time"

View File

@ -1,8 +1,8 @@
package model package catalog
import "github.com/jackc/pgtype" import "github.com/jackc/pgtype"
type ProductModel struct { type ProductEntity struct {
ID int `db:"id"` ID int `db:"id"`
PID string `db:"pid"` PID string `db:"pid"`
Name string `db:"name"` Name string `db:"name"`

12
catalog/model/model.go Normal file
View File

@ -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"`
}

9
common/dto/error.go Normal file
View File

@ -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}
}

5
common/dto/health.go Normal file
View File

@ -0,0 +1,5 @@
package common
type HealthResponseDTO struct {
Status string `json:"status"`
}

View File

@ -1,9 +0,0 @@
package http
type ErrorResponse struct {
Error string `json:"error"`
}
func Error(err string) *ErrorResponse {
return &ErrorResponse{err}
}

View File

@ -1,5 +0,0 @@
package http
type HealthResponse struct {
Status string `json:"status,omitempty"`
}

View File

@ -1,8 +0,0 @@
package http
type UpdateOrderStatusRequest struct {
Status string `json:"status"`
}
type UpdateOrderStatusResponse struct {
}

View File

@ -1,9 +0,0 @@
package http
type ProductPriceRequest struct {
ProductId int `json:"product_id"`
}
type ProductPriceResponse struct {
Price int `json:"price"`
}

View File

@ -1,10 +1,10 @@
package http package identity
type AuthLoginRequest struct { type AuthLoginRequestDTO struct {
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
} }
type AuthLoginResponse struct { type AuthLoginResponseDTO struct {
Token string `json:"jwt_token"` Token string `json:"jwt_token"`
} }

8
order/dto/dto.go Normal file
View File

@ -0,0 +1,8 @@
package order
type UpdateOrderStatusRequestDTO struct {
Status string `json:"status"`
}
type UpdateOrderStatusResponseDTO struct {
}

View File

@ -1,15 +1,15 @@
package model package order
import "github.com/jackc/pgtype" import "github.com/jackc/pgtype"
type OrderModel struct { type OrderEntity struct {
ID string `db:"id" json:"id"` ID string `db:"id" json:"id"`
State string `db:"state" json:"state"` State string `db:"state" json:"state"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"` CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"` UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at,omitempty"`
} }
type OrderItemModel struct { type OrderItemEntity struct {
ID string `db:"id" json:"id"` ID string `db:"id" json:"id"`
OrderID string `db:"order_id" json:"order_id"` OrderID string `db:"order_id" json:"order_id"`
ProductID int `db:"product_id" json:"product_id"` ProductID int `db:"product_id" json:"product_id"`

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

@ -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"`
}

9
pricing/dto/dto.go Normal file
View File

@ -0,0 +1,9 @@
package pricing
type ProductPriceRequestDTO struct {
ProductId int `json:"product_id"`
}
type ProductPriceResponseDTO struct {
Price int `json:"price"`
}

7
pricing/entity/entity.go Normal file
View File

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

View File

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