170 lines
7.8 KiB
Go
170 lines
7.8 KiB
Go
|
|
package cardmaster
|
||
|
|
|
||
|
|
import (
|
||
|
|
"cardverse/internal/pkg/utils"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListCardMasterQuery struct {
|
||
|
|
Page int `form:"page,default=1" binding:"omitempty,min=1"`
|
||
|
|
Limit int `form:"limit,default=20" binding:"omitempty,min=1,max=100"`
|
||
|
|
Search string `form:"search"`
|
||
|
|
IDSet uint `form:"id_set" binding:"omitempty"`
|
||
|
|
Element string `form:"element"`
|
||
|
|
Rarity string `form:"rarity"`
|
||
|
|
Stage string `form:"stage"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type CreateCardMasterRequest struct {
|
||
|
|
IDSet uint `json:"id_set" binding:"required"`
|
||
|
|
Name string `json:"name" binding:"required,min=1,max=150"`
|
||
|
|
Number string `json:"number" binding:"omitempty,max=50"`
|
||
|
|
Image string `json:"image" binding:"omitempty,max=255"`
|
||
|
|
Stage string `json:"stage" binding:"omitempty,max=50"`
|
||
|
|
Element string `json:"element" binding:"omitempty,max=50"`
|
||
|
|
ElementImage string `json:"element_image" binding:"omitempty,max=255"`
|
||
|
|
EvolvesFrom string `json:"evolves_from" binding:"omitempty,max=150"`
|
||
|
|
Illustrator string `json:"illustrator" binding:"omitempty,max=150"`
|
||
|
|
Regulation string `json:"regulation" binding:"omitempty,max=10"`
|
||
|
|
Rarity string `json:"rarity" binding:"omitempty,max=50"`
|
||
|
|
IDPriceChartingEng string `json:"id_price_charting_eng" binding:"omitempty,max=50"`
|
||
|
|
LinkPriceChartingEng string `json:"link_price_charting_eng" binding:"omitempty"`
|
||
|
|
IDPriceChartingJpn string `json:"id_price_charting_jpn" binding:"omitempty,max=50"`
|
||
|
|
LinkPriceChartingJpn string `json:"link_price_charting_jpn" binding:"omitempty"`
|
||
|
|
HP *HP `json:"hp" binding:"omitempty"`
|
||
|
|
Attacks []Attack `json:"attacks" binding:"omitempty"`
|
||
|
|
Abilities []Ability `json:"abilities" binding:"omitempty"`
|
||
|
|
Battle *Battle `json:"battle" binding:"omitempty"`
|
||
|
|
EvolutionLine []EvolutionStage `json:"evolution_line" binding:"omitempty"`
|
||
|
|
PokedexInfo *PokedexInfo `json:"pokedex_info" binding:"omitempty"`
|
||
|
|
Effects []Effect `json:"effects" binding:"omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type UpdateCardMasterRequest struct {
|
||
|
|
IDSet uint `json:"id_set" binding:"omitempty"`
|
||
|
|
Name string `json:"name" binding:"omitempty,min=1,max=150"`
|
||
|
|
Number string `json:"number" binding:"omitempty,max=50"`
|
||
|
|
Image string `json:"image" binding:"omitempty,max=255"`
|
||
|
|
Stage string `json:"stage" binding:"omitempty,max=50"`
|
||
|
|
Element string `json:"element" binding:"omitempty,max=50"`
|
||
|
|
EvolvesFrom string `json:"evolves_from" binding:"omitempty,max=150"`
|
||
|
|
Illustrator string `json:"illustrator" binding:"omitempty,max=150"`
|
||
|
|
Regulation string `json:"regulation" binding:"omitempty,max=10"`
|
||
|
|
Rarity string `json:"rarity" binding:"omitempty,max=50"`
|
||
|
|
IDPriceChartingEng string `json:"id_price_charting_eng" binding:"omitempty,max=50"`
|
||
|
|
LinkPriceChartingEng string `json:"link_price_charting_eng" binding:"omitempty"`
|
||
|
|
IDPriceChartingJpn string `json:"id_price_charting_jpn" binding:"omitempty,max=50"`
|
||
|
|
LinkPriceChartingJpn string `json:"link_price_charting_jpn" binding:"omitempty"`
|
||
|
|
HP *HP `json:"hp" binding:"omitempty"`
|
||
|
|
Attacks []Attack `json:"attacks" binding:"omitempty"`
|
||
|
|
Abilities []Ability `json:"abilities" binding:"omitempty"`
|
||
|
|
Battle *Battle `json:"battle" binding:"omitempty"`
|
||
|
|
EvolutionLine []EvolutionStage `json:"evolution_line" binding:"omitempty"`
|
||
|
|
PokedexInfo *PokedexInfo `json:"pokedex_info" binding:"omitempty"`
|
||
|
|
Effects []Effect `json:"effects" binding:"omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type ElementResponse struct {
|
||
|
|
Name string `json:"name"`
|
||
|
|
Image string `json:"image"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetElementsResponse() []ElementResponse {
|
||
|
|
elements := []string{"Daun", "Api", "Air", "Listrik", "Psikis", "Petarung", "Kegelapan", "Logam", "Naga", "Peri", "Bening"}
|
||
|
|
result := make([]ElementResponse, 0, len(elements))
|
||
|
|
for _, name := range elements {
|
||
|
|
if path, exists := ElementImageMap[name]; exists {
|
||
|
|
result = append(result, ElementResponse{
|
||
|
|
Name: name,
|
||
|
|
Image: utils.FormatMediaURL(path),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return result
|
||
|
|
}
|
||
|
|
|
||
|
|
type CardMasterResponse struct {
|
||
|
|
ID uint `json:"id"`
|
||
|
|
IDSet uint `json:"id_set"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
Number *string `json:"number"`
|
||
|
|
Image *string `json:"image"`
|
||
|
|
Stage *string `json:"stage"`
|
||
|
|
Element *string `json:"element"`
|
||
|
|
ElementImage *string `json:"element_image"`
|
||
|
|
EvolvesFrom *string `json:"evolves_from"`
|
||
|
|
Illustrator *string `json:"illustrator"`
|
||
|
|
Regulation *string `json:"regulation"`
|
||
|
|
Rarity *string `json:"rarity"`
|
||
|
|
IDPriceChartingEng *string `json:"id_price_charting_eng"`
|
||
|
|
LinkPriceChartingEng *string `json:"link_price_charting_eng"`
|
||
|
|
IDPriceChartingJpn *string `json:"id_price_charting_jpn"`
|
||
|
|
LinkPriceChartingJpn *string `json:"link_price_charting_jpn"`
|
||
|
|
HP JSONB `json:"hp"`
|
||
|
|
Attacks JSONB `json:"attacks"`
|
||
|
|
Abilities JSONB `json:"abilities"`
|
||
|
|
Battle JSONB `json:"battle"`
|
||
|
|
EvolutionLine JSONB `json:"evolution_line"`
|
||
|
|
PokedexInfo JSONB `json:"pokedex_info"`
|
||
|
|
Effects JSONB `json:"effects"`
|
||
|
|
CreatedAt time.Time `json:"created_at"`
|
||
|
|
UpdatedAt time.Time `json:"updated_at"`
|
||
|
|
CreatedBy *uint `json:"created_by,omitempty"`
|
||
|
|
UpdatedBy *uint `json:"updated_by,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func ToCardMasterResponse(c CardMaster) CardMasterResponse {
|
||
|
|
return CardMasterResponse{
|
||
|
|
ID: c.ID,
|
||
|
|
IDSet: c.IDSet,
|
||
|
|
Name: c.Name,
|
||
|
|
Number: strPtr(c.Number),
|
||
|
|
Image: strPtrMedia(c.Image),
|
||
|
|
Stage: strPtr(c.Stage),
|
||
|
|
Element: strPtr(c.Element),
|
||
|
|
ElementImage: strPtrMedia(c.ElementImage),
|
||
|
|
EvolvesFrom: strPtr(c.EvolvesFrom),
|
||
|
|
Illustrator: strPtr(c.Illustrator),
|
||
|
|
Regulation: strPtr(c.Regulation),
|
||
|
|
Rarity: strPtr(c.Rarity),
|
||
|
|
IDPriceChartingEng: strPtr(c.IDPriceChartingEng),
|
||
|
|
LinkPriceChartingEng: strPtr(c.LinkPriceChartingEng),
|
||
|
|
IDPriceChartingJpn: strPtr(c.IDPriceChartingJpn),
|
||
|
|
LinkPriceChartingJpn: strPtr(c.LinkPriceChartingJpn),
|
||
|
|
HP: JSONB(utils.FormatJSONBMediaURLs(c.HP)),
|
||
|
|
Attacks: JSONB(utils.FormatJSONBMediaURLs(c.Attacks)),
|
||
|
|
Abilities: JSONB(utils.FormatJSONBMediaURLs(c.Abilities)),
|
||
|
|
Battle: JSONB(utils.FormatJSONBMediaURLs(c.Battle)),
|
||
|
|
EvolutionLine: JSONB(utils.FormatJSONBMediaURLs(c.EvolutionLine)),
|
||
|
|
PokedexInfo: JSONB(utils.FormatJSONBMediaURLs(c.PokedexInfo)),
|
||
|
|
Effects: JSONB(utils.FormatJSONBMediaURLs(c.Effects)),
|
||
|
|
CreatedAt: c.CreatedAt,
|
||
|
|
UpdatedAt: c.UpdatedAt,
|
||
|
|
CreatedBy: c.CreatedBy,
|
||
|
|
UpdatedBy: c.UpdatedBy,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func ToCardMasterResponseList(list []CardMaster) []CardMasterResponse {
|
||
|
|
result := make([]CardMasterResponse, 0, len(list))
|
||
|
|
for _, item := range list {
|
||
|
|
result = append(result, ToCardMasterResponse(item))
|
||
|
|
}
|
||
|
|
return result
|
||
|
|
}
|
||
|
|
|
||
|
|
func strPtr(s string) *string {
|
||
|
|
if s == "" {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return &s
|
||
|
|
}
|
||
|
|
|
||
|
|
func strPtrMedia(s string) *string {
|
||
|
|
if s == "" {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
formatted := utils.FormatMediaURL(s)
|
||
|
|
return &formatted
|
||
|
|
}
|