fixes
This commit is contained in:
parent
895605e6b8
commit
1c5802dedf
5 changed files with 30 additions and 30 deletions
|
|
@ -231,10 +231,6 @@ func (co *controller) deleteMerch(c *gin.Context) {
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /prices [get]
|
// @Router /prices [get]
|
||||||
//
|
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
|
||||||
// @Router /prices [get]
|
|
||||||
func (co *controller) getChartsPrices(c *gin.Context) {
|
func (co *controller) getChartsPrices(c *gin.Context) {
|
||||||
daysQuery := strings.ToLower(c.DefaultQuery("days", ""))
|
daysQuery := strings.ToLower(c.DefaultQuery("days", ""))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ type MerchDTO struct {
|
||||||
|
|
||||||
type OriginDTO struct {
|
type OriginDTO struct {
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
|
Name origins.Origin `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SurugayaDTO struct {
|
type SurugayaDTO struct {
|
||||||
|
|
@ -39,7 +40,7 @@ type AmiamiDTO struct {
|
||||||
type SingleMerchResponse struct {
|
type SingleMerchResponse struct {
|
||||||
MerchUuid string `json:"merch_uuid"`
|
MerchUuid string `json:"merch_uuid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Origins []any `json:"origins"`
|
Origins []OriginDTO `json:"origins"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResponse struct {
|
type ListResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ type Price struct {
|
||||||
DeletedAt sql.NullTime `json:"deleted_at,omitempty" gorm:"column:deleted_at"`
|
DeletedAt sql.NullTime `json:"deleted_at,omitempty" gorm:"column:deleted_at"`
|
||||||
MerchUuid string `json:"merch_uuid" gorm:"column:merch_uuid"`
|
MerchUuid string `json:"merch_uuid" gorm:"column:merch_uuid"`
|
||||||
Price int `json:"price" gorm:"column:price"`
|
Price int `json:"price" gorm:"column:price"`
|
||||||
Origin origins.Origin `json:"origin" gorm:"column:origins;type:integer"`
|
Origin origins.Origin `json:"origin" gorm:"column:origin;type:integer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Label struct {
|
type Label struct {
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ func (r *Repo) getAllUserMerch(userUuid string) (merchList []Merch, err error) {
|
||||||
|
|
||||||
func (r *Repo) getPricesWithDays(userUuid string, period time.Time) (prices []Price, err error) {
|
func (r *Repo) getPricesWithDays(userUuid string, period time.Time) (prices []Price, err error) {
|
||||||
err = r.db.Raw(`
|
err = r.db.Raw(`
|
||||||
SELECT p.created_at, p.merch_uuid, p.price, p.origins
|
SELECT p.created_at, p.merch_uuid, p.price, p.origin
|
||||||
FROM prices AS p
|
FROM prices AS p
|
||||||
JOIN merch AS m ON m.merch_uuid = p.merch_uuid
|
JOIN merch AS m ON m.merch_uuid = p.merch_uuid
|
||||||
WHERE m.user_uuid = ?
|
WHERE m.user_uuid = ?
|
||||||
|
|
@ -248,9 +248,9 @@ func (r *Repo) getPricesWithDays(userUuid string, period time.Time) (prices []Pr
|
||||||
|
|
||||||
func (r *Repo) getDistinctPrices(userUuid, merchUuid string, period time.Time) (prices []Price, err error) {
|
func (r *Repo) getDistinctPrices(userUuid, merchUuid string, period time.Time) (prices []Price, err error) {
|
||||||
err = r.db.Raw(`
|
err = r.db.Raw(`
|
||||||
SELECT price, created_at, origins
|
SELECT price, created_at, origin
|
||||||
FROM (
|
FROM (
|
||||||
SELECT DISTINCT ON (price) price, created_at, origins
|
SELECT DISTINCT ON (price) price, created_at, origin
|
||||||
FROM prices
|
FROM prices
|
||||||
WHERE merch_uuid = ?
|
WHERE merch_uuid = ?
|
||||||
AND created_at > ?
|
AND created_at > ?
|
||||||
|
|
|
||||||
|
|
@ -75,30 +75,33 @@ func (s *service) addMerch(payload MerchDTO, userUuid string) error {
|
||||||
return s.repo.addMerch(bundle)
|
return s.repo.addMerch(bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) getSingleMerch(userUuid, merchUuid string) (MerchDTO, error) {
|
func (s *service) getSingleMerch(userUuid, merchUuid string) (SingleMerchResponse, error) {
|
||||||
bundle, err := s.repo.getSingleMerch(userUuid, merchUuid)
|
bundle, err := s.repo.getSingleMerch(userUuid, merchUuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MerchDTO{}, err
|
return SingleMerchResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return MerchDTO{
|
var originsSlice []OriginDTO
|
||||||
|
|
||||||
|
originsSlice = append(originsSlice, OriginDTO{
|
||||||
|
Link: bundle.Surugaya.Link,
|
||||||
|
Name: origins.Surugaya,
|
||||||
|
})
|
||||||
|
|
||||||
|
originsSlice = append(originsSlice, OriginDTO{
|
||||||
|
Link: bundle.Mandarake.Link,
|
||||||
|
Name: origins.Mandarake,
|
||||||
|
})
|
||||||
|
|
||||||
|
originsSlice = append(originsSlice, OriginDTO{
|
||||||
|
Link: bundle.Amiami.Link,
|
||||||
|
Name: origins.Amiami,
|
||||||
|
})
|
||||||
|
|
||||||
|
return SingleMerchResponse{
|
||||||
MerchUuid: bundle.Merch.MerchUuid,
|
MerchUuid: bundle.Merch.MerchUuid,
|
||||||
Name: bundle.Merch.Name,
|
Name: bundle.Merch.Name,
|
||||||
OriginSurugaya: SurugayaDTO{
|
Origins: originsSlice,
|
||||||
OriginDTO{
|
|
||||||
Link: bundle.Surugaya.Link,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
OriginMandarake: MandarakeDTO{
|
|
||||||
OriginDTO{
|
|
||||||
Link: bundle.Mandarake.Link,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
OriginAmiami: AmiamiDTO{
|
|
||||||
OriginDTO{
|
|
||||||
Link: bundle.Amiami.Link,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue