-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
87 lines (77 loc) · 2.78 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package product
import (
bankaccount "github.com/citadel-corp/shopifyx-marketplace/internal/bank_account"
"github.com/citadel-corp/shopifyx-marketplace/internal/common/response"
"github.com/citadel-corp/shopifyx-marketplace/internal/user"
"github.com/google/uuid"
)
type Response struct {
Code int
Message string
Data any
Meta *response.Pagination
Error error
}
var (
SuccessCreateResponse = Response{Code: 200, Message: "Product created successfully"}
SuccessListResponse = Response{Code: 200, Message: "ok"}
SuccessPatchResponse = Response{Code: 200, Message: "Product patched successfully"}
SuccessGetResponse = Response{Code: 200, Message: "ok"}
SuccessPurchaseResponse = Response{Code: 200, Message: "Product purchased successfully"}
SuccessUpdateStockResponse = Response{Code: 200, Message: "Stock updated successfully"}
SuccessDeleteResponse = Response{Code: 200, Message: "Product deleted successfully"}
)
type ProductResponse struct {
UUID uuid.UUID `json:"productId"`
Name string `json:"name"`
ImageURL string `json:"imageUrl"`
Stock int `json:"stock"`
Condition Condition `json:"condition"`
Tags []string `json:"tags"`
IsPurchasable bool `json:"isPurchasable"`
Price int `json:"price"`
PurchaseCount int `json:"purchaseCount"`
}
func CreateProductResponse(product Product) ProductResponse {
return ProductResponse{
UUID: product.UUID,
Name: product.Name,
ImageURL: product.ImageURL,
Stock: product.Stock,
Condition: product.Condition,
Tags: product.Tags,
IsPurchasable: product.IsPurchasable,
Price: product.Price,
PurchaseCount: product.PurchaseCount,
}
}
type SellerResponse struct {
Name string `json:"name"`
ProductSoldTotal int `json:"productSoldTotal"`
BankAccounts []bankaccount.BankAccountResponse `json:"bankAccounts"`
}
func CreateSellerResponse(user *user.User, bankAccounts []*bankaccount.BankAccount) SellerResponse {
if user == nil {
return SellerResponse{}
}
accts := make([]bankaccount.BankAccountResponse, len(bankAccounts))
for i, bankAccount := range bankAccounts {
if bankAccount != nil {
accts[i] = bankaccount.BankAccountResponse{
BankAccountID: bankAccount.UUID.String(),
BankName: bankAccount.BankName,
BankAccountName: bankAccount.BankAccountName,
BankAccountNumber: bankAccount.BankAccountNumber,
}
}
}
return SellerResponse{
Name: user.Name,
ProductSoldTotal: user.ProductSoldTotal,
BankAccounts: accts,
}
}
type ProductDetailResponse struct {
Product ProductResponse `json:"product"`
Seller SellerResponse `json:"seller"`
}