Compare commits
No commits in common. "7fa79d770a20293799485e76c55fb66f4ca73f6f" and "a0e21db5a09e7e13d026611c1f068ca27fbe9ed1" have entirely different histories.
7fa79d770a
...
a0e21db5a0
7 changed files with 71 additions and 172 deletions
31
docs/docs.go
31
docs/docs.go
|
|
@ -106,9 +106,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Обновить информацию про мерч по его uuid в json-е",
|
"description": "Обновить информацию про мерч по его uuid в json-е",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch"
|
"Merch"
|
||||||
],
|
],
|
||||||
|
|
@ -334,9 +331,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Создать новую метку для товара",
|
"description": "Создать новую метку для товара",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -379,9 +373,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Прикрепить метку к товару",
|
"description": "Прикрепить метку к товару",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -424,9 +415,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Удалить привязку метки к товару",
|
"description": "Удалить привязку метки к товару",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -510,9 +498,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Изменить метку",
|
"description": "Изменить метку",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -638,9 +623,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Пометить нулевые цены как удаленные",
|
"description": "Пометить нулевые цены как удаленные",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch zero prices"
|
"Merch zero prices"
|
||||||
],
|
],
|
||||||
|
|
@ -1178,11 +1160,11 @@ const docTemplate = `{
|
||||||
"merch.DeleteZeroPrices": {
|
"merch.DeleteZeroPrices": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"merch_uuids": {
|
||||||
"type": "integer"
|
"type": "array",
|
||||||
},
|
"items": {
|
||||||
"merch_uuid": {
|
"type": "string"
|
||||||
"type": "string"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -1360,9 +1342,6 @@ const docTemplate = `{
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"id": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"merch_uuid": {
|
"merch_uuid": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Обновить информацию про мерч по его uuid в json-е",
|
"description": "Обновить информацию про мерч по его uuid в json-е",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch"
|
"Merch"
|
||||||
],
|
],
|
||||||
|
|
@ -326,9 +323,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Создать новую метку для товара",
|
"description": "Создать новую метку для товара",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -371,9 +365,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Прикрепить метку к товару",
|
"description": "Прикрепить метку к товару",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -416,9 +407,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Удалить привязку метки к товару",
|
"description": "Удалить привязку метки к товару",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -502,9 +490,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Изменить метку",
|
"description": "Изменить метку",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch labels"
|
"Merch labels"
|
||||||
],
|
],
|
||||||
|
|
@ -630,9 +615,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Пометить нулевые цены как удаленные",
|
"description": "Пометить нулевые цены как удаленные",
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"Merch zero prices"
|
"Merch zero prices"
|
||||||
],
|
],
|
||||||
|
|
@ -1170,11 +1152,11 @@
|
||||||
"merch.DeleteZeroPrices": {
|
"merch.DeleteZeroPrices": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"merch_uuids": {
|
||||||
"type": "integer"
|
"type": "array",
|
||||||
},
|
"items": {
|
||||||
"merch_uuid": {
|
"type": "string"
|
||||||
"type": "string"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -1352,9 +1334,6 @@
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"id": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"merch_uuid": {
|
"merch_uuid": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
merch.DeleteZeroPrices:
|
merch.DeleteZeroPrices:
|
||||||
properties:
|
properties:
|
||||||
id:
|
merch_uuids:
|
||||||
type: integer
|
items:
|
||||||
merch_uuid:
|
type: string
|
||||||
type: string
|
type: array
|
||||||
type: object
|
type: object
|
||||||
merch.ImageLink:
|
merch.ImageLink:
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -126,8 +126,6 @@ definitions:
|
||||||
properties:
|
properties:
|
||||||
created_at:
|
created_at:
|
||||||
type: string
|
type: string
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
merch_uuid:
|
merch_uuid:
|
||||||
type: string
|
type: string
|
||||||
name:
|
name:
|
||||||
|
|
@ -256,8 +254,6 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- Merch
|
- Merch
|
||||||
put:
|
put:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Обновить информацию про мерч по его uuid в json-е
|
description: Обновить информацию про мерч по его uuid в json-е
|
||||||
parameters:
|
parameters:
|
||||||
- description: merch_uuid
|
- description: merch_uuid
|
||||||
|
|
@ -457,8 +453,6 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- Merch labels
|
- Merch labels
|
||||||
post:
|
post:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Создать новую метку для товара
|
description: Создать новую метку для товара
|
||||||
parameters:
|
parameters:
|
||||||
- description: payload
|
- description: payload
|
||||||
|
|
@ -535,8 +529,6 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- Merch labels
|
- Merch labels
|
||||||
put:
|
put:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Изменить метку
|
description: Изменить метку
|
||||||
parameters:
|
parameters:
|
||||||
- description: label uuid
|
- description: label uuid
|
||||||
|
|
@ -568,8 +560,6 @@ paths:
|
||||||
- Merch labels
|
- Merch labels
|
||||||
/merch/labels/attach:
|
/merch/labels/attach:
|
||||||
post:
|
post:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Прикрепить метку к товару
|
description: Прикрепить метку к товару
|
||||||
parameters:
|
parameters:
|
||||||
- description: payload
|
- description: payload
|
||||||
|
|
@ -596,8 +586,6 @@ paths:
|
||||||
- Merch labels
|
- Merch labels
|
||||||
/merch/labels/detach:
|
/merch/labels/detach:
|
||||||
post:
|
post:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Удалить привязку метки к товару
|
description: Удалить привязку метки к товару
|
||||||
parameters:
|
parameters:
|
||||||
- description: payload
|
- description: payload
|
||||||
|
|
@ -624,8 +612,6 @@ paths:
|
||||||
- Merch labels
|
- Merch labels
|
||||||
/merch/zeroprices:
|
/merch/zeroprices:
|
||||||
delete:
|
delete:
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Пометить нулевые цены как удаленные
|
description: Пометить нулевые цены как удаленные
|
||||||
parameters:
|
parameters:
|
||||||
- description: payload
|
- description: payload
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (co *controller) addMerch(c *gin.Context) {
|
||||||
// @Description Получить всю информацию про мерч по его uuid
|
// @Description Получить всю информацию про мерч по его uuid
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param uuid path string true "merch_uuid"
|
// @Param uuid path string true "merch_uuid"
|
||||||
// @Success 200 {object} MerchDTO
|
// @Success 200 {object} MerchDTO
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
|
|
@ -129,7 +129,7 @@ func (co *controller) getSingleMerch(c *gin.Context) {
|
||||||
// @Description Получить все записи мерча
|
// @Description Получить все записи мерча
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} ListResponse
|
// @Success 200 {array} ListResponse
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
|
|
@ -156,7 +156,7 @@ func (co *controller) getAllMerch(c *gin.Context) {
|
||||||
// @Description Обновить информацию про мерч по его uuid в json-е
|
// @Description Обновить информацию про мерч по его uuid в json-е
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param body body UpdateMerchDTO true "merch_uuid"
|
// @Param body body UpdateMerchDTO true "merch_uuid"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
|
|
@ -182,7 +182,6 @@ func (co *controller) updateMerch(c *gin.Context) {
|
||||||
log.WithError(err).Error("Merch | Failed to get single merch")
|
log.WithError(err).Error("Merch | Failed to get single merch")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Status(http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Пометить мерч как удаленный
|
// @Summary Пометить мерч как удаленный
|
||||||
|
|
@ -193,8 +192,7 @@ func (co *controller) updateMerch(c *gin.Context) {
|
||||||
// @Success 200 {object} MerchDTO
|
// @Success 200 {object} MerchDTO
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
//
|
// @Router /merch/{uuid} [delete]
|
||||||
// @Router /merch/{uuid} [delete]
|
|
||||||
func (co *controller) deleteMerch(c *gin.Context) {
|
func (co *controller) deleteMerch(c *gin.Context) {
|
||||||
merchUuid := c.Param("uuid")
|
merchUuid := c.Param("uuid")
|
||||||
if merchUuid == "" {
|
if merchUuid == "" {
|
||||||
|
|
@ -222,16 +220,12 @@ func (co *controller) deleteMerch(c *gin.Context) {
|
||||||
// @Description Получить цены мерча за период
|
// @Description Получить цены мерча за период
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param days query string false "period in days"
|
// @Param days query string false "period in days"
|
||||||
// @Success 200 {array} PricesResponse
|
// @Success 200 {array} PricesResponse
|
||||||
// @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", ""))
|
||||||
|
|
||||||
|
|
@ -256,7 +250,7 @@ func (co *controller) getChartsPrices(c *gin.Context) {
|
||||||
// @Description Получить перепады цен мерча за период по его merch_uuid
|
// @Description Получить перепады цен мерча за период по его merch_uuid
|
||||||
// @Tags Merch
|
// @Tags Merch
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param uuid path string true "merch_uuid"
|
// @Param uuid path string true "merch_uuid"
|
||||||
// @Param days query string false "period in days"
|
// @Param days query string false "period in days"
|
||||||
// @Success 200 {object} PricesResponse
|
// @Success 200 {object} PricesResponse
|
||||||
|
|
@ -344,6 +338,7 @@ func (co *controller) uploadMerchImage(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//c.Status(http.StatusOK)
|
||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +346,7 @@ func (co *controller) uploadMerchImage(c *gin.Context) {
|
||||||
// @Description Получить картинки по merch_uuid и query параметрам
|
// @Description Получить картинки по merch_uuid и query параметрам
|
||||||
// @Tags Merch images
|
// @Tags Merch images
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param uuid path string true "merch_uuid"
|
// @Param uuid path string true "merch_uuid"
|
||||||
// @Param type query string true "image type"
|
// @Param type query string true "image type"
|
||||||
// @Success 200 {object} ImageLink
|
// @Success 200 {object} ImageLink
|
||||||
|
|
@ -398,6 +393,7 @@ func (co *controller) getMerchImage(c *gin.Context) {
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//c.JSON(http.StatusOK, link)
|
//c.JSON(http.StatusOK, link)
|
||||||
|
c.JSON(http.StatusNotImplemented, gin.H{"msg": "Method deprecated. Request images from image storage."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Удалить (безвозвратно) картинки по merch_uuid
|
// @Summary Удалить (безвозвратно) картинки по merch_uuid
|
||||||
|
|
@ -442,7 +438,7 @@ func (co *controller) deleteMerchImage(c *gin.Context) {
|
||||||
// @Description Создать новую метку для товара
|
// @Description Создать новую метку для товара
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param payload body LabelDTO true "payload"
|
// @Param payload body LabelDTO true "payload"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
|
|
@ -478,7 +474,7 @@ func (co *controller) createLabel(c *gin.Context) {
|
||||||
// @Description Получить все метки товаров
|
// @Description Получить все метки товаров
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} LabelsList
|
// @Success 200 {array} LabelsList
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
|
|
@ -507,7 +503,7 @@ func (co *controller) getLabels(c *gin.Context) {
|
||||||
// @Description Изменить метку
|
// @Description Изменить метку
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param uuid path string true "label uuid"
|
// @Param uuid path string true "label uuid"
|
||||||
// @Param payload body LabelDTO true "payload"
|
// @Param payload body LabelDTO true "payload"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
|
|
@ -580,16 +576,16 @@ func (co *controller) deleteLabel(c *gin.Context) {
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Прикрепить метку к товару
|
// @Summary Прикрепить метку к товару
|
||||||
// @Description Прикрепить метку к товару
|
// @Description Прикрепить метку к товару
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param payload body LabelLink true "payload"
|
// @Param payload body LabelLink true "payload"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/labels/attach [post]
|
// @Router /merch/labels/attach [post]
|
||||||
func (co *controller) attachLabel(c *gin.Context) {
|
func (co *controller) attachLabel(c *gin.Context) {
|
||||||
const logMsg = "Merch | Attach label"
|
const logMsg = "Merch | Attach label"
|
||||||
|
|
||||||
|
|
@ -615,16 +611,16 @@ func (co *controller) attachLabel(c *gin.Context) {
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Удалить привязку метки к товару
|
// @Summary Удалить привязку метки к товару
|
||||||
// @Description Удалить привязку метки к товару
|
// @Description Удалить привязку метки к товару
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param payload body LabelLink true "payload"
|
// @Param payload body LabelLink true "payload"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/labels/detach [post]
|
// @Router /merch/labels/detach [post]
|
||||||
func (co *controller) detachLabel(c *gin.Context) {
|
func (co *controller) detachLabel(c *gin.Context) {
|
||||||
const logMsg = "Merch | Detach label"
|
const logMsg = "Merch | Detach label"
|
||||||
|
|
||||||
|
|
@ -654,7 +650,7 @@ func (co *controller) detachLabel(c *gin.Context) {
|
||||||
// @Description Получить метки товара по его uuid
|
// @Description Получить метки товара по его uuid
|
||||||
// @Tags Merch labels
|
// @Tags Merch labels
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param uuid path string true "label uuid"
|
// @Param uuid path string true "label uuid"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
|
|
@ -690,10 +686,10 @@ func (co *controller) getMerchLabels(c *gin.Context) {
|
||||||
// @Description Получить нулевые цены
|
// @Description Получить нулевые цены
|
||||||
// @Tags Merch zero prices
|
// @Tags Merch zero prices
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} ZeroPrice
|
// @Success 200 {array} ZeroPrice
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/zeroprices [get]
|
// @Router /merch/zeroprices [get]
|
||||||
func (co *controller) getZeroPrices(c *gin.Context) {
|
func (co *controller) getZeroPrices(c *gin.Context) {
|
||||||
const logMsg = "Merch | Get zero prices"
|
const logMsg = "Merch | Get zero prices"
|
||||||
|
|
@ -719,11 +715,11 @@ func (co *controller) getZeroPrices(c *gin.Context) {
|
||||||
// @Description Пометить нулевые цены как удаленные
|
// @Description Пометить нулевые цены как удаленные
|
||||||
// @Tags Merch zero prices
|
// @Tags Merch zero prices
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Accept json
|
// Accept json
|
||||||
// @Param payload body DeleteZeroPrices true "payload"
|
// @Param payload body DeleteZeroPrices true "payload"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
// @Failure 400 {object} responses.ErrorResponse400
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /merch/zeroprices [delete]
|
// @Router /merch/zeroprices [delete]
|
||||||
func (co *controller) deleteZeroPrices(c *gin.Context) {
|
func (co *controller) deleteZeroPrices(c *gin.Context) {
|
||||||
const logMsg = "Merch | Delete zero prices"
|
const logMsg = "Merch | Delete zero prices"
|
||||||
|
|
@ -735,7 +731,7 @@ func (co *controller) deleteZeroPrices(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload []DeleteZeroPrices
|
var payload DeleteZeroPrices
|
||||||
if err = c.ShouldBindJSON(&payload); err != nil {
|
if err = c.ShouldBindJSON(&payload); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()})
|
c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()})
|
||||||
log.WithError(err).Error(logMsg)
|
log.WithError(err).Error(logMsg)
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@ type LabelLink struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZeroPrice struct {
|
type ZeroPrice struct {
|
||||||
Id int `json:"id"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
MerchUuid string `json:"merch_uuid"`
|
MerchUuid string `json:"merch_uuid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
@ -90,6 +89,5 @@ type ZeroPrice struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteZeroPrices struct {
|
type DeleteZeroPrices struct {
|
||||||
Id uint `json:"id"`
|
MerchUuids []string `json:"merch_uuids"`
|
||||||
MerchUuid string `json:"merch_uuid"`
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package merch
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/clause"
|
"gorm.io/gorm/clause"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -23,7 +22,6 @@ type repository interface {
|
||||||
addMerch(bundle merchBundle) error
|
addMerch(bundle merchBundle) error
|
||||||
|
|
||||||
merchRecordExists(userUuid, merchUuid string) (bool, error)
|
merchRecordExists(userUuid, merchUuid string) (bool, error)
|
||||||
userOwnsMerchUuids(userUuid string, merchUuids []string) (bool, error)
|
|
||||||
getSingleMerch(userUuid, merchUuid string) (merchBundle, error)
|
getSingleMerch(userUuid, merchUuid string) (merchBundle, error)
|
||||||
getAllMerch(userUuid string) ([]ListResponse, error)
|
getAllMerch(userUuid string) ([]ListResponse, error)
|
||||||
|
|
||||||
|
|
@ -42,7 +40,7 @@ type prices interface {
|
||||||
getDistinctPrices(userUuid, merchUuid string, period time.Time) (prices []Price, err error)
|
getDistinctPrices(userUuid, merchUuid string, period time.Time) (prices []Price, err error)
|
||||||
|
|
||||||
getZeroPrices(userUuid string) ([]ZeroPrice, error)
|
getZeroPrices(userUuid string) ([]ZeroPrice, error)
|
||||||
deleteZeroPrices(list []DeleteZeroPrices) error
|
deleteZeroPrices(userUuid string, list []string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type labels interface {
|
type labels interface {
|
||||||
|
|
@ -86,22 +84,6 @@ func (r *Repo) merchRecordExists(userUuid, merchUuid string) (bool, error) {
|
||||||
return exists, err
|
return exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) userOwnsMerchUuids(userUuid string, merchUuids []string) (bool, error) {
|
|
||||||
var count int64
|
|
||||||
|
|
||||||
err := r.db.Model(&Merch{}).
|
|
||||||
Where("user_uuid = ?", userUuid).
|
|
||||||
Where("merch_uuid IN ?", merchUuids).
|
|
||||||
Where("deleted_at IS NULL").
|
|
||||||
Count(&count).Error
|
|
||||||
fmt.Println("!!!!!!", count)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
fmt.Println("!!!!!!", len(merchUuids))
|
|
||||||
return count == int64(len(merchUuids)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
||||||
var merch Merch
|
var merch Merch
|
||||||
if err := r.db.
|
if err := r.db.
|
||||||
|
|
@ -338,17 +320,16 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) {
|
||||||
if err := r.db.Raw(`
|
if err := r.db.Raw(`
|
||||||
WITH price_with_neighbors AS (
|
WITH price_with_neighbors AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.id, p.created_at, p.merch_uuid, p.price, p.origin, m.name,
|
p.created_at, p.merch_uuid, p.price, p.origin, m.name,
|
||||||
LAG(price) OVER (PARTITION BY p.merch_uuid ORDER BY p.created_at, p.id) AS prev_price,
|
LAG(price) OVER (PARTITION BY p.merch_uuid ORDER BY p.created_at, p.id) AS prev_price,
|
||||||
LEAD(price) OVER (PARTITION BY p.merch_uuid ORDER BY p.created_at, p.id) AS next_price
|
LEAD(price) OVER (PARTITION BY p.merch_uuid ORDER BY p.created_at, p.id) AS next_price
|
||||||
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 p.deleted_at IS NULL
|
WHERE p.deleted_at IS NULL
|
||||||
AND m.deleted_at IS NULL
|
|
||||||
AND m.user_uuid = ?)
|
AND m.user_uuid = ?)
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
id, created_at, merch_uuid, origin, name
|
created_at, merch_uuid, origin, name
|
||||||
FROM price_with_neighbors
|
FROM price_with_neighbors
|
||||||
WHERE
|
WHERE
|
||||||
price = 0
|
price = 0
|
||||||
|
|
@ -362,13 +343,14 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) {
|
||||||
return priceList, nil
|
return priceList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) deleteZeroPrices(list []DeleteZeroPrices) error {
|
func (r *Repo) deleteZeroPrices(userUuid string, list []string) error {
|
||||||
for _, item := range list {
|
subQuery := r.db.Table("merch").
|
||||||
if err := r.db.Model(&Price{}).
|
Select("merch_uuid").
|
||||||
Where("id = ? AND merch_uuid = ?", item.Id, item.MerchUuid).
|
Where("user_uuid = ?", userUuid)
|
||||||
Update("deleted_at", time.Now().UTC()).Error; err != nil {
|
|
||||||
return err
|
return r.db.Model(&Price{}).
|
||||||
}
|
Where("merch_uuid IN ?", list).
|
||||||
}
|
Where("merch_uuid IN (?)", subQuery).
|
||||||
return nil
|
Update("deleted_at", time.Now().UTC()).
|
||||||
|
Error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import (
|
||||||
is "merch-parser-api/proto/imageStorage"
|
is "merch-parser-api/proto/imageStorage"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -618,26 +617,6 @@ func (s *service) getZeroPrices(userUuid string) ([]ZeroPrice, error) {
|
||||||
return s.repo.getZeroPrices(userUuid)
|
return s.repo.getZeroPrices(userUuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) deleteZeroPrices(userUuid string, list []DeleteZeroPrices) error {
|
func (s *service) deleteZeroPrices(userUuid string, list DeleteZeroPrices) error {
|
||||||
if len(list) == 0 {
|
return s.repo.deleteZeroPrices(userUuid, list.MerchUuids)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ids := make([]string, 0, len(list))
|
|
||||||
for _, item := range list {
|
|
||||||
ids = append(ids, item.MerchUuid)
|
|
||||||
fmt.Println(item.MerchUuid, ids)
|
|
||||||
}
|
|
||||||
slices.Compact(ids)
|
|
||||||
|
|
||||||
owns, err := s.repo.userOwnsMerchUuids(userUuid, ids)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !owns {
|
|
||||||
return errors.New("wrong ids")
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.repo.deleteZeroPrices(list)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue