Compare commits
No commits in common. "main" and "v0.1.22" have entirely different histories.
9 changed files with 49 additions and 274 deletions
47
docs/docs.go
47
docs/docs.go
|
|
@ -675,53 +675,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/merch/zeroprices/period": {
|
|
||||||
"delete": {
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"BearerAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Пометить нулевые цены как удаленные за указанный период",
|
|
||||||
"tags": [
|
|
||||||
"Merch zero prices"
|
|
||||||
],
|
|
||||||
"summary": "Пометить нулевые цены как удаленные за указанный период",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "start",
|
|
||||||
"name": "start",
|
|
||||||
"in": "query",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "end",
|
|
||||||
"name": "end",
|
|
||||||
"in": "query",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK"
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/responses.ErrorResponse400"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/responses.ErrorResponse500"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/merch/{uuid}": {
|
"/merch/{uuid}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -667,53 +667,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/merch/zeroprices/period": {
|
|
||||||
"delete": {
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"BearerAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Пометить нулевые цены как удаленные за указанный период",
|
|
||||||
"tags": [
|
|
||||||
"Merch zero prices"
|
|
||||||
],
|
|
||||||
"summary": "Пометить нулевые цены как удаленные за указанный период",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "start",
|
|
||||||
"name": "start",
|
|
||||||
"in": "query",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "end",
|
|
||||||
"name": "end",
|
|
||||||
"in": "query",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK"
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/responses.ErrorResponse400"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/responses.ErrorResponse500"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/merch/{uuid}": {
|
"/merch/{uuid}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -674,36 +674,6 @@ paths:
|
||||||
summary: Получить нулевые цены
|
summary: Получить нулевые цены
|
||||||
tags:
|
tags:
|
||||||
- Merch zero prices
|
- Merch zero prices
|
||||||
/merch/zeroprices/period:
|
|
||||||
delete:
|
|
||||||
description: Пометить нулевые цены как удаленные за указанный период
|
|
||||||
parameters:
|
|
||||||
- description: start
|
|
||||||
in: query
|
|
||||||
name: start
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: end
|
|
||||||
in: query
|
|
||||||
name: end
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/responses.ErrorResponse400'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/responses.ErrorResponse500'
|
|
||||||
security:
|
|
||||||
- BearerAuth: []
|
|
||||||
summary: Пометить нулевые цены как удаленные за указанный период
|
|
||||||
tags:
|
|
||||||
- Merch zero prices
|
|
||||||
/prices:
|
/prices:
|
||||||
get:
|
get:
|
||||||
description: Получить цены мерча за период
|
description: Получить цены мерча за период
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,6 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, ref
|
||||||
zeroPricesGroup := merchGroup.Group("/zeroprices", authMW)
|
zeroPricesGroup := merchGroup.Group("/zeroprices", authMW)
|
||||||
zeroPricesGroup.GET("", h.controller.getZeroPrices)
|
zeroPricesGroup.GET("", h.controller.getZeroPrices)
|
||||||
zeroPricesGroup.DELETE("", h.controller.deleteZeroPrices)
|
zeroPricesGroup.DELETE("", h.controller.deleteZeroPrices)
|
||||||
|
|
||||||
zeroPricesGroup.DELETE("/period", h.controller.deleteZeroPricesPeriod)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Добавить новый мерч
|
// @Summary Добавить новый мерч
|
||||||
|
|
@ -159,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
|
||||||
|
|
@ -197,7 +194,7 @@ func (co *controller) updateMerch(c *gin.Context) {
|
||||||
// @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 == "" {
|
||||||
|
|
@ -232,9 +229,9 @@ func (co *controller) deleteMerch(c *gin.Context) {
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
// @Failure 500 {object} responses.ErrorResponse500
|
||||||
// @Router /prices [get]
|
// @Router /prices [get]
|
||||||
//
|
//
|
||||||
// @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]
|
||||||
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", ""))
|
||||||
|
|
||||||
|
|
@ -445,7 +442,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
|
||||||
|
|
@ -510,7 +507,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
|
||||||
|
|
@ -583,16 +580,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"
|
||||||
|
|
||||||
|
|
@ -618,16 +615,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"
|
||||||
|
|
||||||
|
|
@ -722,7 +719,7 @@ 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
|
||||||
|
|
@ -752,45 +749,3 @@ func (co *controller) deleteZeroPrices(c *gin.Context) {
|
||||||
}
|
}
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Пометить нулевые цены как удаленные за указанный период
|
|
||||||
// @Description Пометить нулевые цены как удаленные за указанный период
|
|
||||||
// @Tags Merch zero prices
|
|
||||||
// @Security BearerAuth
|
|
||||||
// @Param start query string true "start"
|
|
||||||
// @Param end query string true "end"
|
|
||||||
// @Success 200
|
|
||||||
// @Failure 400 {object} responses.ErrorResponse400
|
|
||||||
// @Failure 500 {object} responses.ErrorResponse500
|
|
||||||
// @Router /merch/zeroprices/period [delete]
|
|
||||||
func (co *controller) deleteZeroPricesPeriod(c *gin.Context) {
|
|
||||||
const logMsg = "Merch | Delete zero prices period"
|
|
||||||
|
|
||||||
userUuid, err := co.utils.GetUserUuidFromContext(c)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()})
|
|
||||||
log.WithError(err).Error(logMsg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
start, err := co.utils.ParseTime(c.Query("start"))
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()})
|
|
||||||
log.WithError(err).Error(logMsg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
end, err := co.utils.ParseTime(c.Query("end"))
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()})
|
|
||||||
log.WithError(err).Error(logMsg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = co.service.deleteZeroPricesPeriod(userUuid, start, end); err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()})
|
|
||||||
log.WithError(err).Error(logMsg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Status(http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ type ZeroPrice struct {
|
||||||
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"`
|
||||||
Origin Origin `json:"origin"`
|
Origin string `json:"origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteZeroPrices struct {
|
type DeleteZeroPrices struct {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ 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"
|
||||||
|
|
@ -22,7 +23,7 @@ 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) ([]Merch, 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 +43,6 @@ type prices interface {
|
||||||
|
|
||||||
getZeroPrices(userUuid string) ([]ZeroPrice, error)
|
getZeroPrices(userUuid string) ([]ZeroPrice, error)
|
||||||
deleteZeroPrices(list []DeleteZeroPrices) error
|
deleteZeroPrices(list []DeleteZeroPrices) error
|
||||||
deleteZeroPricesPeriod(userUuid string, start, end time.Time) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type labels interface {
|
type labels interface {
|
||||||
|
|
@ -86,20 +86,20 @@ func (r *Repo) merchRecordExists(userUuid, merchUuid string) (bool, error) {
|
||||||
return exists, err
|
return exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) userOwnsMerchUuids(userUuid string, merchUuids []string) ([]Merch, error) {
|
func (r *Repo) userOwnsMerchUuids(userUuid string, merchUuids []string) (bool, error) {
|
||||||
var ownsUuids []Merch
|
var count int64
|
||||||
|
|
||||||
err := r.db.Model(&Merch{}).
|
err := r.db.Model(&Merch{}).
|
||||||
Select("merch_uuid").
|
|
||||||
Where("user_uuid = ?", userUuid).
|
Where("user_uuid = ?", userUuid).
|
||||||
Where("merch_uuid IN (?)", merchUuids).
|
Where("merch_uuid IN ?", merchUuids).
|
||||||
Where("deleted_at IS NULL").
|
Where("deleted_at IS NULL").
|
||||||
Find(&ownsUuids).Error
|
Count(&count).Error
|
||||||
|
fmt.Println("!!!!!!", count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
fmt.Println("!!!!!!", len(merchUuids))
|
||||||
return ownsUuids, nil
|
return count == int64(len(merchUuids)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) {
|
||||||
|
|
@ -339,8 +339,8 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) {
|
||||||
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.id, p.created_at, p.merch_uuid, p.price, p.origin, m.name,
|
||||||
LAG(price) OVER (PARTITION BY p.merch_uuid, p.origin 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, p.origin 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
|
||||||
|
|
@ -372,19 +372,3 @@ func (r *Repo) deleteZeroPrices(list []DeleteZeroPrices) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) deleteZeroPricesPeriod(userUuid string, start, end time.Time) error {
|
|
||||||
if err := r.db.Exec(`
|
|
||||||
UPDATE prices
|
|
||||||
SET deleted_at = ?
|
|
||||||
FROM merch
|
|
||||||
WHERE prices.merch_uuid = merch.merch_uuid
|
|
||||||
AND merch.user_uuid = ?
|
|
||||||
AND prices.price = 0
|
|
||||||
AND prices.deleted_at IS NULL
|
|
||||||
AND prices.created_at BETWEEN ? AND ?;
|
|
||||||
`, time.Now().UTC(), userUuid, start, end).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ 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,7 +619,6 @@ func (s *service) getZeroPrices(userUuid string) ([]ZeroPrice, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) deleteZeroPrices(userUuid string, list []DeleteZeroPrices) error {
|
func (s *service) deleteZeroPrices(userUuid string, list []DeleteZeroPrices) error {
|
||||||
const delMsg = "Merch - service | Delete zero prices"
|
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -626,43 +626,18 @@ func (s *service) deleteZeroPrices(userUuid string, list []DeleteZeroPrices) err
|
||||||
ids := make([]string, 0, len(list))
|
ids := make([]string, 0, len(list))
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
ids = append(ids, item.MerchUuid)
|
ids = append(ids, item.MerchUuid)
|
||||||
|
fmt.Println(item.MerchUuid, ids)
|
||||||
}
|
}
|
||||||
|
slices.Compact(ids)
|
||||||
|
|
||||||
uniqueMap := make(map[string]struct{}, len(list))
|
owns, err := s.repo.userOwnsMerchUuids(userUuid, ids)
|
||||||
uniqueIds := make([]string, 0, len(list))
|
|
||||||
for _, id := range ids {
|
|
||||||
if _, ok := uniqueMap[id]; !ok {
|
|
||||||
uniqueMap[id] = struct{}{}
|
|
||||||
uniqueIds = append(uniqueIds, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithField("uuid count", len(uniqueIds)).Debug(delMsg)
|
|
||||||
|
|
||||||
owns, err := s.repo.userOwnsMerchUuids(userUuid, uniqueIds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(owns) < 1 {
|
if !owns {
|
||||||
return errors.New("wrong ids")
|
return errors.New("wrong ids")
|
||||||
}
|
}
|
||||||
|
|
||||||
ownsMap := make(map[string]struct{}, len(owns))
|
return s.repo.deleteZeroPrices(list)
|
||||||
for _, own := range owns {
|
|
||||||
ownsMap[own.MerchUuid] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
toDelete := make([]DeleteZeroPrices, 0, len(owns))
|
|
||||||
for _, item := range list {
|
|
||||||
if _, ok := ownsMap[item.MerchUuid]; ok {
|
|
||||||
toDelete = append(toDelete, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.repo.deleteZeroPrices(toDelete)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) deleteZeroPricesPeriod(userUuid string, start, end time.Time) error {
|
|
||||||
return s.repo.deleteZeroPricesPeriod(userUuid, start, end)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package interfaces
|
package interfaces
|
||||||
|
|
||||||
import (
|
import "github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Utils interface {
|
type Utils interface {
|
||||||
IsEmail(email string) bool
|
IsEmail(email string) bool
|
||||||
|
|
@ -11,5 +8,4 @@ type Utils interface {
|
||||||
GetRefreshUuidFromContext(c *gin.Context) (string, error)
|
GetRefreshUuidFromContext(c *gin.Context) (string, error)
|
||||||
HashPassword(password string) (string, error)
|
HashPassword(password string) (string, error)
|
||||||
ComparePasswords(hashedPassword string, plainPassword string) error
|
ComparePasswords(hashedPassword string, plainPassword string) error
|
||||||
ParseTime(t string) (time.Time, error)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package utils
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
func (u *Utils) ParseTime(t string) (time.Time, error) {
|
|
||||||
timeStr, err := time.Parse(time.RFC3339, t)
|
|
||||||
if err != nil {
|
|
||||||
return time.Time{}, err
|
|
||||||
}
|
|
||||||
return timeStr, nil
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue