diff --git a/cmd/main.go b/cmd/main.go index ce397b1..8c0cb26 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -94,9 +94,9 @@ func main() { }) merchModule := merch.NewHandler(merch.Deps{ - DB: database, - Utils: utilsProvider, - //Media: mediaProvider, + DB: database, + Utils: utilsProvider, + Media: mediaProvider, ImageStorage: imageProvider, }) diff --git a/docs/docs.go b/docs/docs.go index a232b91..8e556d2 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -68,9 +68,6 @@ const docTemplate = `{ } ], "description": "Получить все записи мерча", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -106,9 +103,6 @@ const docTemplate = `{ } ], "description": "Обновить информацию про мерч по его uuid в json-е", - "consumes": [ - "application/json" - ], "tags": [ "Merch" ], @@ -151,9 +145,6 @@ const docTemplate = `{ } ], "description": "Получить картинки по merch_uuid и query параметрам", - "produces": [ - "application/json" - ], "tags": [ "Merch images" ], @@ -288,440 +279,6 @@ const docTemplate = `{ } } }, - "/merch/labels": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить все метки товаров", - "produces": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Получить все метки товаров", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/merch.LabelsList" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Создать новую метку для товара", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Создать новую метку для товара", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelDTO" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/attach": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Прикрепить метку к товару", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Прикрепить метку к товару", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelLink" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/detach": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Удалить привязку метки к товару", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Удалить привязку метки к товару", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelLink" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/{uuid}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить метки товара по его uuid", - "produces": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Получить метки товара по его uuid", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "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" - } - } - } - }, - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Изменить метку", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Изменить метку", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "required": true - }, - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelDTO" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Пометить метку как удаленную", - "tags": [ - "Merch labels" - ], - "summary": "Пометить метку как удаленную", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "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/zeroprices": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить нулевые цены", - "produces": [ - "application/json" - ], - "tags": [ - "Merch zero prices" - ], - "summary": "Получить нулевые цены", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/merch.ZeroPrice" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Пометить нулевые цены как удаленные", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch zero prices" - ], - "summary": "Пометить нулевые цены как удаленные", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.DeleteZeroPrices" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/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}": { "get": { "security": [ @@ -730,9 +287,6 @@ const docTemplate = `{ } ], "description": "Получить всю информацию про мерч по его uuid", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -817,9 +371,6 @@ const docTemplate = `{ } ], "description": "Получить цены мерча за период", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -865,9 +416,6 @@ const docTemplate = `{ } ], "description": "Получить перепады цен мерча за период по его merch_uuid", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -1222,17 +770,6 @@ const docTemplate = `{ } } }, - "merch.DeleteZeroPrices": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "merch_uuid": { - "type": "string" - } - } - }, "merch.ImageLink": { "type": "object", "properties": { @@ -1244,57 +781,9 @@ const docTemplate = `{ } } }, - "merch.LabelDTO": { - "type": "object", - "properties": { - "bg_color": { - "type": "string" - }, - "color": { - "type": "string" - }, - "name": { - "type": "string" - } - } - }, - "merch.LabelLink": { - "type": "object", - "properties": { - "label_uuid": { - "type": "string" - }, - "merch_uuid": { - "type": "string" - } - } - }, - "merch.LabelsList": { - "type": "object", - "properties": { - "bg_color": { - "type": "string" - }, - "color": { - "type": "string" - }, - "label_uuid": { - "type": "string" - }, - "name": { - "type": "string" - } - } - }, "merch.ListResponse": { "type": "object", "properties": { - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, "merch_uuid": { "type": "string" }, @@ -1314,12 +803,6 @@ const docTemplate = `{ "merch.MerchDTO": { "type": "object", "properties": { - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, "merch_uuid": { "type": "string" }, @@ -1401,26 +884,6 @@ const docTemplate = `{ } } }, - "merch.ZeroPrice": { - "type": "object", - "properties": { - "created_at": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "merch_uuid": { - "type": "string" - }, - "name": { - "type": "string" - }, - "origin": { - "type": "string" - } - } - }, "responses.ErrorResponse400": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 74a0031..ea5dbf2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -60,9 +60,6 @@ } ], "description": "Получить все записи мерча", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -98,9 +95,6 @@ } ], "description": "Обновить информацию про мерч по его uuid в json-е", - "consumes": [ - "application/json" - ], "tags": [ "Merch" ], @@ -143,9 +137,6 @@ } ], "description": "Получить картинки по merch_uuid и query параметрам", - "produces": [ - "application/json" - ], "tags": [ "Merch images" ], @@ -280,440 +271,6 @@ } } }, - "/merch/labels": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить все метки товаров", - "produces": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Получить все метки товаров", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/merch.LabelsList" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Создать новую метку для товара", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Создать новую метку для товара", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelDTO" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/attach": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Прикрепить метку к товару", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Прикрепить метку к товару", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelLink" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/detach": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Удалить привязку метки к товару", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Удалить привязку метки к товару", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelLink" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/merch/labels/{uuid}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить метки товара по его uuid", - "produces": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Получить метки товара по его uuid", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "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" - } - } - } - }, - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Изменить метку", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch labels" - ], - "summary": "Изменить метку", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "required": true - }, - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.LabelDTO" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Пометить метку как удаленную", - "tags": [ - "Merch labels" - ], - "summary": "Пометить метку как удаленную", - "parameters": [ - { - "type": "string", - "description": "label uuid", - "name": "uuid", - "in": "path", - "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/zeroprices": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Получить нулевые цены", - "produces": [ - "application/json" - ], - "tags": [ - "Merch zero prices" - ], - "summary": "Получить нулевые цены", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/merch.ZeroPrice" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Пометить нулевые цены как удаленные", - "consumes": [ - "application/json" - ], - "tags": [ - "Merch zero prices" - ], - "summary": "Пометить нулевые цены как удаленные", - "parameters": [ - { - "description": "payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/merch.DeleteZeroPrices" - } - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse400" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/responses.ErrorResponse500" - } - } - } - } - }, - "/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}": { "get": { "security": [ @@ -722,9 +279,6 @@ } ], "description": "Получить всю информацию про мерч по его uuid", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -809,9 +363,6 @@ } ], "description": "Получить цены мерча за период", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -857,9 +408,6 @@ } ], "description": "Получить перепады цен мерча за период по его merch_uuid", - "produces": [ - "application/json" - ], "tags": [ "Merch" ], @@ -1214,17 +762,6 @@ } } }, - "merch.DeleteZeroPrices": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "merch_uuid": { - "type": "string" - } - } - }, "merch.ImageLink": { "type": "object", "properties": { @@ -1236,57 +773,9 @@ } } }, - "merch.LabelDTO": { - "type": "object", - "properties": { - "bg_color": { - "type": "string" - }, - "color": { - "type": "string" - }, - "name": { - "type": "string" - } - } - }, - "merch.LabelLink": { - "type": "object", - "properties": { - "label_uuid": { - "type": "string" - }, - "merch_uuid": { - "type": "string" - } - } - }, - "merch.LabelsList": { - "type": "object", - "properties": { - "bg_color": { - "type": "string" - }, - "color": { - "type": "string" - }, - "label_uuid": { - "type": "string" - }, - "name": { - "type": "string" - } - } - }, "merch.ListResponse": { "type": "object", "properties": { - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, "merch_uuid": { "type": "string" }, @@ -1306,12 +795,6 @@ "merch.MerchDTO": { "type": "object", "properties": { - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, "merch_uuid": { "type": "string" }, @@ -1393,26 +876,6 @@ } } }, - "merch.ZeroPrice": { - "type": "object", - "properties": { - "created_at": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "merch_uuid": { - "type": "string" - }, - "name": { - "type": "string" - }, - "origin": { - "type": "string" - } - } - }, "responses.ErrorResponse400": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 31eaa0d..1afef07 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -7,13 +7,6 @@ definitions: thumbnail: type: string type: object - merch.DeleteZeroPrices: - properties: - id: - type: integer - merch_uuid: - type: string - type: object merch.ImageLink: properties: etag: @@ -21,39 +14,8 @@ definitions: link: type: string type: object - merch.LabelDTO: - properties: - bg_color: - type: string - color: - type: string - name: - type: string - type: object - merch.LabelLink: - properties: - label_uuid: - type: string - merch_uuid: - type: string - type: object - merch.LabelsList: - properties: - bg_color: - type: string - color: - type: string - label_uuid: - type: string - name: - type: string - type: object merch.ListResponse: properties: - labels: - items: - type: string - type: array merch_uuid: type: string name: @@ -66,10 +28,6 @@ definitions: type: object merch.MerchDTO: properties: - labels: - items: - type: string - type: array merch_uuid: type: string name: @@ -122,19 +80,6 @@ definitions: origin: type: string type: object - merch.ZeroPrice: - properties: - created_at: - type: string - id: - type: integer - merch_uuid: - type: string - name: - type: string - origin: - type: string - type: object responses.ErrorResponse400: properties: error: @@ -233,8 +178,6 @@ paths: /merch/: get: description: Получить все записи мерча - produces: - - application/json responses: "200": description: OK @@ -256,8 +199,6 @@ paths: tags: - Merch put: - consumes: - - application/json description: Обновить информацию про мерч по его uuid в json-е parameters: - description: merch_uuid @@ -317,8 +258,6 @@ paths: name: uuid required: true type: string - produces: - - application/json responses: "200": description: OK @@ -375,8 +314,6 @@ paths: name: type required: true type: string - produces: - - application/json responses: "200": description: OK @@ -431,279 +368,6 @@ paths: summary: Загрузить картинку по merch_uuid tags: - Merch images - /merch/labels: - get: - description: Получить все метки товаров - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/merch.LabelsList' - type: array - "400": - description: Bad Request - schema: - $ref: '#/definitions/responses.ErrorResponse400' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/responses.ErrorResponse500' - security: - - BearerAuth: [] - summary: Получить все метки товаров - tags: - - Merch labels - post: - consumes: - - application/json - description: Создать новую метку для товара - parameters: - - description: payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/merch.LabelDTO' - 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 labels - /merch/labels/{uuid}: - delete: - description: Пометить метку как удаленную - parameters: - - description: label uuid - in: path - name: uuid - 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 labels - get: - description: Получить метки товара по его uuid - parameters: - - description: label uuid - in: path - name: uuid - required: true - type: string - produces: - - application/json - 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: Получить метки товара по его uuid - tags: - - Merch labels - put: - consumes: - - application/json - description: Изменить метку - parameters: - - description: label uuid - in: path - name: uuid - required: true - type: string - - description: payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/merch.LabelDTO' - 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 labels - /merch/labels/attach: - post: - consumes: - - application/json - description: Прикрепить метку к товару - parameters: - - description: payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/merch.LabelLink' - 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 labels - /merch/labels/detach: - post: - consumes: - - application/json - description: Удалить привязку метки к товару - parameters: - - description: payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/merch.LabelLink' - 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 labels - /merch/zeroprices: - delete: - consumes: - - application/json - description: Пометить нулевые цены как удаленные - parameters: - - description: payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/merch.DeleteZeroPrices' - 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 - get: - description: Получить нулевые цены - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/merch.ZeroPrice' - type: array - "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 - /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: get: description: Получить цены мерча за период @@ -712,8 +376,6 @@ paths: in: query name: days type: string - produces: - - application/json responses: "200": description: OK @@ -747,8 +409,6 @@ paths: in: query name: days type: string - produces: - - application/json responses: "200": description: OK diff --git a/internal/api/merch/controller.go b/internal/api/merch/controller.go index a9f922a..06fd408 100644 --- a/internal/api/merch/controller.go +++ b/internal/api/merch/controller.go @@ -27,6 +27,7 @@ func newController(service *service, utils interfaces.Utils, expires time.Durati func (h *Handler) RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, refreshMW gin.HandlerFunc) { merchGroup := r.Group("/merch", authMW) + merchGroup.POST("/", h.controller.addMerch) merchGroup.GET("/:uuid", h.controller.getSingleMerch) merchGroup.GET("/", h.controller.getAllMerch) @@ -41,22 +42,6 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, ref imagesGroup.POST("/:uuid", h.controller.uploadMerchImage) imagesGroup.GET("/:uuid", h.controller.getMerchImage) imagesGroup.DELETE("/:uuid", h.controller.deleteMerchImage) - - labelsGroup := merchGroup.Group("/labels", authMW) - labelsGroup.POST("", h.controller.createLabel) - labelsGroup.GET("", h.controller.getLabels) - labelsGroup.PUT("/:uuid", h.controller.updateLabel) - labelsGroup.DELETE("/:uuid", h.controller.deleteLabel) - labelsGroup.POST("/attach", h.controller.attachLabel) - labelsGroup.POST("/detach", h.controller.detachLabel) - labelsGroup.GET("/:uuid", h.controller.getMerchLabels) - - zeroPricesGroup := merchGroup.Group("/zeroprices", authMW) - zeroPricesGroup.GET("", h.controller.getZeroPrices) - zeroPricesGroup.DELETE("", h.controller.deleteZeroPrices) - - zeroPricesGroup.DELETE("/period", h.controller.deleteZeroPricesPeriod) - } // @Summary Добавить новый мерч @@ -98,7 +83,6 @@ func (co *controller) addMerch(c *gin.Context) { // @Description Получить всю информацию про мерч по его uuid // @Tags Merch // @Security BearerAuth -// @Produce json // @Param uuid path string true "merch_uuid" // @Success 200 {object} MerchDTO // @Failure 400 {object} responses.ErrorResponse400 @@ -132,7 +116,6 @@ func (co *controller) getSingleMerch(c *gin.Context) { // @Description Получить все записи мерча // @Tags Merch // @Security BearerAuth -// @Produce json // @Success 200 {array} ListResponse // @Failure 400 {object} responses.ErrorResponse400 // @Failure 500 {object} responses.ErrorResponse500 @@ -159,7 +142,6 @@ func (co *controller) getAllMerch(c *gin.Context) { // @Description Обновить информацию про мерч по его uuid в json-е // @Tags Merch // @Security BearerAuth -// @Accept json // @Param body body UpdateMerchDTO true "merch_uuid" // @Success 200 // @Failure 400 {object} responses.ErrorResponse400 @@ -185,7 +167,6 @@ func (co *controller) updateMerch(c *gin.Context) { log.WithError(err).Error("Merch | Failed to get single merch") return } - c.Status(http.StatusOK) } // @Summary Пометить мерч как удаленный @@ -196,7 +177,6 @@ func (co *controller) updateMerch(c *gin.Context) { // @Success 200 {object} MerchDTO // @Failure 400 {object} responses.ErrorResponse400 // @Failure 500 {object} responses.ErrorResponse500 -// // @Router /merch/{uuid} [delete] func (co *controller) deleteMerch(c *gin.Context) { merchUuid := c.Param("uuid") @@ -225,16 +205,11 @@ func (co *controller) deleteMerch(c *gin.Context) { // @Description Получить цены мерча за период // @Tags Merch // @Security BearerAuth -// @Produce json // @Param days query string false "period in days" // @Success 200 {array} PricesResponse // @Failure 400 {object} responses.ErrorResponse400 // @Failure 500 {object} responses.ErrorResponse500 // @Router /prices [get] -// -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /prices [get] func (co *controller) getChartsPrices(c *gin.Context) { daysQuery := strings.ToLower(c.DefaultQuery("days", "")) @@ -259,7 +234,6 @@ func (co *controller) getChartsPrices(c *gin.Context) { // @Description Получить перепады цен мерча за период по его merch_uuid // @Tags Merch // @Security BearerAuth -// @Produce json // @Param uuid path string true "merch_uuid" // @Param days query string false "period in days" // @Success 200 {object} PricesResponse @@ -347,6 +321,7 @@ func (co *controller) uploadMerchImage(c *gin.Context) { return } + //c.Status(http.StatusOK) c.JSON(http.StatusOK, response) } @@ -354,7 +329,6 @@ func (co *controller) uploadMerchImage(c *gin.Context) { // @Description Получить картинки по merch_uuid и query параметрам // @Tags Merch images // @Security BearerAuth -// @Produce json // @Param uuid path string true "merch_uuid" // @Param type query string true "image type" // @Success 200 {object} ImageLink @@ -401,6 +375,7 @@ func (co *controller) getMerchImage(c *gin.Context) { //} // //c.JSON(http.StatusOK, link) + c.JSON(http.StatusNotImplemented, gin.H{"msg": "Method deprecated. Request images from image storage."}) } // @Summary Удалить (безвозвратно) картинки по merch_uuid @@ -440,357 +415,3 @@ func (co *controller) deleteMerchImage(c *gin.Context) { } c.Status(http.StatusOK) } - -// @Summary Создать новую метку для товара -// @Description Создать новую метку для товара -// @Tags Merch labels -// @Security BearerAuth -// @Accept json -// @Param payload body LabelDTO true "payload" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels [post] -func (co *controller) createLabel(c *gin.Context) { - const logMsg = "Merch | Create label" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - var payload LabelDTO - if err = c.ShouldBindJSON(&payload); err != nil { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.createLabel(payload, userUuid); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - c.Status(http.StatusOK) -} - -// @Summary Получить все метки товаров -// @Description Получить все метки товаров -// @Tags Merch labels -// @Security BearerAuth -// @Produce json -// @Success 200 {array} LabelsList -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels [get] -func (co *controller) getLabels(c *gin.Context) { - const logMsg = "Merch | Get labels" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - response, err := co.service.getLabels(userUuid) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - c.JSON(http.StatusOK, response) -} - -// @Summary Изменить метку -// @Description Изменить метку -// @Tags Merch labels -// @Security BearerAuth -// @Accept json -// @Param uuid path string true "label uuid" -// @Param payload body LabelDTO true "payload" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/{uuid} [put] -func (co *controller) updateLabel(c *gin.Context) { - const logMsg = "Merch | Update label" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - labelUuid := c.Param("uuid") - if labelUuid == "" { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: "label uuid is empty"}) - log.WithError(err).Error(logMsg) - return - } - - var payload LabelDTO - if err = c.ShouldBindJSON(&payload); err != nil { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.updateLabel(userUuid, labelUuid, payload); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.Status(http.StatusOK) -} - -// @Summary Пометить метку как удаленную -// @Description Пометить метку как удаленную -// @Tags Merch labels -// @Security BearerAuth -// @Param uuid path string true "label uuid" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/{uuid} [delete] -func (co *controller) deleteLabel(c *gin.Context) { - const logMsg = "Merch | Delete label" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - labelUuid := c.Param("uuid") - if labelUuid == "" { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: "label uuid is empty"}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.deleteLabel(userUuid, labelUuid); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.Status(http.StatusOK) -} - -// @Summary Прикрепить метку к товару -// @Description Прикрепить метку к товару -// @Tags Merch labels -// @Security BearerAuth -// @Accept json -// @Param payload body LabelLink true "payload" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/attach [post] -func (co *controller) attachLabel(c *gin.Context) { - const logMsg = "Merch | Attach label" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - var payload LabelLink - if err = c.ShouldBindJSON(&payload); err != nil { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.attachLabel(userUuid, payload); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.Status(http.StatusOK) -} - -// @Summary Удалить привязку метки к товару -// @Description Удалить привязку метки к товару -// @Tags Merch labels -// @Security BearerAuth -// @Accept json -// @Param payload body LabelLink true "payload" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/detach [post] -func (co *controller) detachLabel(c *gin.Context) { - const logMsg = "Merch | Detach label" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - var payload LabelLink - if err = c.ShouldBindJSON(&payload); err != nil { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.detachLabel(userUuid, payload); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.Status(http.StatusOK) -} - -// @Summary Получить метки товара по его uuid -// @Description Получить метки товара по его uuid -// @Tags Merch labels -// @Security BearerAuth -// @Produce json -// @Param uuid path string true "label uuid" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/{uuid} [get] -func (co *controller) getMerchLabels(c *gin.Context) { - const logMsg = "Merch | Get merch labels" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - merchUuid := c.Param("uuid") - if merchUuid == "" { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: "label uuid is empty"}) - log.WithError(err).Error(logMsg) - return - } - - response, err := co.service.getMerchLabels(userUuid, merchUuid) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.JSON(http.StatusOK, response) -} - -// @Summary Получить нулевые цены -// @Description Получить нулевые цены -// @Tags Merch zero prices -// @Security BearerAuth -// @Produce json -// @Success 200 {array} ZeroPrice -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/zeroprices [get] -func (co *controller) getZeroPrices(c *gin.Context) { - const logMsg = "Merch | Get zero prices" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - response, err := co.service.getZeroPrices(userUuid) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - c.JSON(http.StatusOK, response) -} - -// @Summary Пометить нулевые цены как удаленные -// @Description Пометить нулевые цены как удаленные -// @Tags Merch zero prices -// @Security BearerAuth -// @Accept json -// @Param payload body DeleteZeroPrices true "payload" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/zeroprices [delete] -func (co *controller) deleteZeroPrices(c *gin.Context) { - const logMsg = "Merch | Delete zero prices" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - var payload []DeleteZeroPrices - if err = c.ShouldBindJSON(&payload); err != nil { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - if err = co.service.deleteZeroPrices(userUuid, payload); err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - 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) -} diff --git a/internal/api/merch/dto.go b/internal/api/merch/dto.go index 5b9180c..bc1646e 100644 --- a/internal/api/merch/dto.go +++ b/internal/api/merch/dto.go @@ -1,7 +1,5 @@ package merch -import "time" - type merchBundle struct { Merch *Merch Surugaya *Surugaya @@ -12,7 +10,6 @@ type MerchDTO struct { Name string `json:"name"` OriginSurugaya SurugayaDTO `json:"origin_surugaya"` OriginMandarake MandarakeDTO `json:"origin_mandarake"` - Labels []string `json:"labels,omitempty" gorm:"-"` } type SurugayaDTO struct { @@ -30,9 +27,8 @@ type SingleMerchResponse struct { } type ListResponse struct { - MerchUuid string `json:"merch_uuid"` - Name string `json:"name"` - Labels []string `json:"labels,omitempty" gorm:"-"` + MerchUuid string `json:"merch_uuid"` + Name string `json:"name"` } type PriceEntry struct { @@ -62,34 +58,3 @@ type ImageLink struct { Link string `json:"link"` ETag string `json:"etag"` } - -type LabelDTO struct { - Name string `json:"name"` - Color string `json:"color,omitempty"` - BgColor string `json:"bg_color,omitempty"` -} - -type LabelsList struct { - LabelUuid string `json:"label_uuid"` - Name string `json:"name"` - Color string `json:"color,omitempty"` - BgColor string `json:"bg_color,omitempty"` -} - -type LabelLink struct { - MerchUuid string `json:"merch_uuid"` - LabelUuid string `json:"label_uuid"` -} - -type ZeroPrice struct { - Id int `json:"id"` - CreatedAt time.Time `json:"created_at"` - MerchUuid string `json:"merch_uuid"` - Name string `json:"name"` - Origin Origin `json:"origin"` -} - -type DeleteZeroPrices struct { - Id uint `json:"id"` - MerchUuid string `json:"merch_uuid"` -} diff --git a/internal/api/merch/handler.go b/internal/api/merch/handler.go index 0239179..6918be0 100644 --- a/internal/api/merch/handler.go +++ b/internal/api/merch/handler.go @@ -1,6 +1,7 @@ package merch import ( + log "github.com/sirupsen/logrus" "gorm.io/gorm" "merch-parser-api/internal/interfaces" is "merch-parser-api/proto/imageStorage" @@ -14,9 +15,9 @@ type Handler struct { } type Deps struct { - DB *gorm.DB - Utils interfaces.Utils - //Media interfaces.MediaStorage + DB *gorm.DB + Utils interfaces.Utils + Media interfaces.MediaStorage ImageStorage is.ImageStorageClient } @@ -26,23 +27,23 @@ func NewHandler(deps Deps) *Handler { r := NewRepo(deps.DB) s := newService(serviceDeps{ - repo: r, - //media: deps.Media, + repo: r, + media: deps.Media, bucketName: packageBucketName, expires: expires, imageStorage: deps.ImageStorage, }) c := newController(s, deps.Utils, expires) - //media := deps.Media - //log.WithFields(log.Fields{ - // "addr": media, - //}).Debug("Merch handler constructor | Media provider") - // - //exists, err := media.CheckBucketExists(packageBucketName) - //if err != nil || !exists { - // log.WithError(err).Fatal("Merch handler constructor | Failed to ensure bucket exists") - //} + media := deps.Media + log.WithFields(log.Fields{ + "addr": media, + }).Debug("Merch handler constructor | Media provider") + + exists, err := media.CheckBucketExists(packageBucketName) + if err != nil || !exists { + log.WithError(err).Fatal("Merch handler constructor | Failed to ensure bucket exists") + } return &Handler{ repo: r, diff --git a/internal/api/merch/model.go b/internal/api/merch/model.go index 2dd6e0e..9322547 100644 --- a/internal/api/merch/model.go +++ b/internal/api/merch/model.go @@ -44,35 +44,9 @@ func (Mandarake) TableName() string { type Price struct { Id uint `json:"id" gorm:"primary_key"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` - UpdatedAt sql.NullTime `json:"updated_at,omitempty" gorm:"column:updated_at"` - DeletedAt sql.NullTime `json:"deleted_at,omitempty" gorm:"column:deleted_at"` + UpdatedAt sql.NullTime `json:"updated_at" gorm:"column:updated_at"` + DeletedAt sql.NullTime `json:"deleted_at" gorm:"column:deleted_at"` MerchUuid string `json:"merch_uuid" gorm:"column:merch_uuid"` Price int `json:"price" gorm:"column:price"` Origin Origin `json:"origin" gorm:"column:origin;type:integer"` } - -type Label struct { - Id uint `json:"-" gorm:"primary_key"` - CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` - UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` - DeletedAt sql.NullTime `json:"deleted_at" gorm:"column:deleted_at"` - LabelUuid string `json:"label_uuid" gorm:"column:label_uuid"` - UserUuid string `json:"user_uuid" gorm:"column:user_uuid"` - Name string `json:"name" gorm:"column:name"` - Color string `json:"color" gorm:"column:color"` - BgColor string `json:"bg_color" gorm:"column:bg_color"` -} - -func (Label) TableName() string { - return "labels" -} - -type CardLabel struct { - LabelUuid string `json:"label_uuid"` - UserUuid string `json:"user_uuid"` - MerchUuid string `json:"merch_uuid"` -} - -func (CardLabel) TableName() string { - return "card_labels" -} diff --git a/internal/api/merch/repository.go b/internal/api/merch/repository.go index fe5dd7d..98d2695 100644 --- a/internal/api/merch/repository.go +++ b/internal/api/merch/repository.go @@ -22,7 +22,6 @@ type repository interface { addMerch(bundle merchBundle) error merchRecordExists(userUuid, merchUuid string) (bool, error) - userOwnsMerchUuids(userUuid string, merchUuids []string) ([]Merch, error) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) getAllMerch(userUuid string) ([]ListResponse, error) @@ -33,27 +32,11 @@ type repository interface { getAllUserMerch(userUuid string) ([]Merch, error) prices - labels } type prices interface { getPricesWithDays(userUuid string, period time.Time) ([]Price, error) getDistinctPrices(userUuid, merchUuid string, period time.Time) (prices []Price, err error) - - getZeroPrices(userUuid string) ([]ZeroPrice, error) - deleteZeroPrices(list []DeleteZeroPrices) error - deleteZeroPricesPeriod(userUuid string, start, end time.Time) error -} - -type labels interface { - createLabel(label Label) error - getLabels(userUuid string) ([]Label, error) - updateLabel(userUuid, labelUuid string, label map[string]any) error - deleteLabel(userUuid, labelUuid string) error - attachLabel(label CardLabel) error - detachLabel(label CardLabel) error - getAttachedLabelsByList(list []string) ([]CardLabel, error) - getAttachedLabelsByUuid(userUuid, merchUuid string) ([]CardLabel, error) } func (r *Repo) addMerch(bundle merchBundle) error { @@ -86,22 +69,6 @@ func (r *Repo) merchRecordExists(userUuid, merchUuid string) (bool, error) { return exists, err } -func (r *Repo) userOwnsMerchUuids(userUuid string, merchUuids []string) ([]Merch, error) { - var ownsUuids []Merch - err := r.db.Model(&Merch{}). - Select("merch_uuid"). - Where("user_uuid = ?", userUuid). - Where("merch_uuid IN (?)", merchUuids). - Where("deleted_at IS NULL"). - Find(&ownsUuids).Error - - if err != nil { - return nil, err - } - - return ownsUuids, nil -} - func (r *Repo) getSingleMerch(userUuid, merchUuid string) (merchBundle, error) { var merch Merch if err := r.db. @@ -272,119 +239,3 @@ func (r *Repo) upsertOrigin(model any) error { DoUpdates: clause.AssignmentColumns([]string{"link"}), }).Create(model).Error } - -func (r *Repo) createLabel(label Label) error { - return r.db.Model(&Label{}).Create(&label).Error -} - -func (r *Repo) getLabels(userUuid string) ([]Label, error) { - var labelsList []Label - - if err := r.db. - Model(&Label{}). - Where("user_uuid = ?", userUuid). - Where("deleted_at IS NULL"). - Find(&labelsList).Error; err != nil { - return nil, err - } - - return labelsList, nil -} - -func (r *Repo) updateLabel(userUuid, labelUuid string, label map[string]any) error { - return r.db.Model(&Label{}). - Where("user_uuid =? AND label_uuid = ?", userUuid, labelUuid). - Updates(label).Error -} - -func (r *Repo) deleteLabel(userUuid, labelUuid string) error { - return r.db.Model(&Label{}). - Where("user_uuid =? AND label_uuid = ?", userUuid, labelUuid). - Update("deleted_at", time.Now().UTC()).Error -} - -func (r *Repo) attachLabel(label CardLabel) error { - return r.db.Model(&CardLabel{}).Create(&label).Error -} - -func (r *Repo) detachLabel(label CardLabel) error { - return r.db. - Where("user_uuid = ? AND label_uuid = ? AND merch_uuid = ?", label.UserUuid, label.LabelUuid, label.MerchUuid). - Delete(&CardLabel{}).Error -} - -func (r *Repo) getAttachedLabelsByList(list []string) ([]CardLabel, error) { - var labelsList []CardLabel - - if err := r.db.Model(&CardLabel{}).Where("merch_uuid IN ?", list).Find(&labelsList).Error; err != nil { - return nil, err - } - - return labelsList, nil -} - -func (r *Repo) getAttachedLabelsByUuid(userUuid, merchUuid string) ([]CardLabel, error) { - var labelsList []CardLabel - - if err := r.db.Model(&CardLabel{}).Where("user_uuid = ? AND merch_uuid = ?", userUuid, merchUuid).Find(&labelsList).Error; err != nil { - return nil, err - } - - return labelsList, nil -} - -func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) { - var priceList []ZeroPrice - if err := r.db.Raw(` - WITH price_with_neighbors AS ( - SELECT - 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, - LEAD(price) OVER (PARTITION BY p.merch_uuid, p.origin ORDER BY p.created_at, p.id) AS next_price - FROM prices AS p - JOIN merch as m ON m.merch_uuid = p.merch_uuid - WHERE p.deleted_at IS NULL - AND m.deleted_at IS NULL - AND m.user_uuid = ?) - - SELECT - id, created_at, merch_uuid, origin, name - FROM price_with_neighbors - WHERE - price = 0 - AND prev_price IS NOT NULL - AND prev_price > 0 - AND next_price IS NOT NULL - AND next_price > 0; - `, userUuid).Scan(&priceList).Error; err != nil { - return nil, err - } - return priceList, nil -} - -func (r *Repo) deleteZeroPrices(list []DeleteZeroPrices) error { - for _, item := range list { - if err := r.db.Model(&Price{}). - Where("id = ? AND merch_uuid = ?", item.Id, item.MerchUuid). - Update("deleted_at", time.Now().UTC()).Error; err != nil { - return err - } - } - 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 -} diff --git a/internal/api/merch/service.go b/internal/api/merch/service.go index ae6c2f5..e749d88 100644 --- a/internal/api/merch/service.go +++ b/internal/api/merch/service.go @@ -101,34 +101,7 @@ func (s *service) getSingleMerch(userUuid, merchUuid string) (MerchDTO, error) { } func (s *service) getAllMerch(userUuid string) ([]ListResponse, error) { - const logMsg = "Merch service | Get all merch" - - allMerch, err := s.repo.getAllMerch(userUuid) - if err != nil { - return nil, err - } - - ids := make([]string, 0, len(allMerch)) - for _, m := range allMerch { - ids = append(ids, m.MerchUuid) - } - - cardLabels, err := s.repo.getAttachedLabelsByList(ids) - if err != nil { - return nil, err - } - log.WithField("content", cardLabels).Debug(logMsg) - - clMap := make(map[string][]string) - for _, cl := range cardLabels { - clMap[cl.MerchUuid] = append(clMap[cl.MerchUuid], cl.LabelUuid) - } - - for item := range allMerch { - allMerch[item].Labels = clMap[allMerch[item].MerchUuid] - } - - return allMerch, nil + return s.repo.getAllMerch(userUuid) } func (s *service) updateMerch(payload UpdateMerchDTO, userUuid string) error { @@ -411,14 +384,13 @@ func (s *service) deleteMerchImage(ctx context.Context, userUuid, merchUuid stri return fmt.Errorf("no merch found for user %s with uuid %s", userUuid, merchUuid) } - //uncomment for MinIO - //if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/thumbnail.jpg", userUuid, merchUuid)); err != nil { - // return err - //} - // - //if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/full.jpg", userUuid, merchUuid)); err != nil { - // return err - //} + if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/thumbnail.jpg", userUuid, merchUuid)); err != nil { + return err + } + + if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/full.jpg", userUuid, merchUuid)); err != nil { + return err + } return nil } @@ -511,158 +483,3 @@ func (s *service) mtDeleteMerchImage(ctx context.Context, userUuid, merchUuid st }) return nil } - -func (s *service) createLabel(label LabelDTO, userUuid string) error { - now := time.Now().UTC() - - if label.Name == "" { - return fmt.Errorf("label name is required") - } - - newLabel := Label{ - CreatedAt: now, - UpdatedAt: now, - DeletedAt: sql.NullTime{Time: time.Time{}, Valid: false}, - LabelUuid: uuid.NewString(), - UserUuid: userUuid, - Name: label.Name, - Color: label.Color, - BgColor: label.BgColor, - } - - return s.repo.createLabel(newLabel) -} -func (s *service) getLabels(userUuid string) ([]LabelsList, error) { - stored, err := s.repo.getLabels(userUuid) - if err != nil { - return nil, err - } - - response := make([]LabelsList, 0, len(stored)) - for _, label := range stored { - response = append(response, LabelsList{ - LabelUuid: label.LabelUuid, - Name: label.Name, - Color: label.Color, - BgColor: label.BgColor, - }) - } - - return response, nil -} -func (s *service) updateLabel(userUuid, labelUuid string, label LabelDTO) error { - updateMap := make(map[string]any, 3) - - if label.Name != "" { - updateMap["name"] = label.Name - } - - if label.Color != "" { - updateMap["color"] = label.Color - } - - if label.BgColor != "" { - updateMap["bg_color"] = label.BgColor - } - - return s.repo.updateLabel(userUuid, labelUuid, updateMap) -} - -func (s *service) deleteLabel(userUuid, labelUuid string) error { - return s.repo.deleteLabel(userUuid, labelUuid) -} - -func (s *service) attachLabel(userUuid string, label LabelLink) error { - if label.LabelUuid == "" || label.MerchUuid == "" { - return fmt.Errorf("both label and merch uuid-s are required") - } - - attach := CardLabel{ - LabelUuid: label.LabelUuid, - UserUuid: userUuid, - MerchUuid: label.MerchUuid, - } - - return s.repo.attachLabel(attach) -} - -func (s *service) detachLabel(userUuid string, label LabelLink) error { - if label.LabelUuid == "" || label.MerchUuid == "" { - return fmt.Errorf("both label and merch uuid-s are required") - } - - detach := CardLabel{ - LabelUuid: label.LabelUuid, - UserUuid: userUuid, - MerchUuid: label.MerchUuid, - } - return s.repo.detachLabel(detach) -} - -func (s *service) getMerchLabels(userUuid, merchUuid string) ([]string, error) { - getLabels, err := s.repo.getAttachedLabelsByUuid(userUuid, merchUuid) - if err != nil { - return nil, err - } - - response := make([]string, 0, len(getLabels)) - for _, label := range getLabels { - response = append(response, label.LabelUuid) - } - - return response, nil -} - -func (s *service) getZeroPrices(userUuid string) ([]ZeroPrice, error) { - return s.repo.getZeroPrices(userUuid) -} - -func (s *service) deleteZeroPrices(userUuid string, list []DeleteZeroPrices) error { - const delMsg = "Merch - service | Delete zero prices" - if len(list) == 0 { - return nil - } - - ids := make([]string, 0, len(list)) - for _, item := range list { - ids = append(ids, item.MerchUuid) - } - - uniqueMap := make(map[string]struct{}, len(list)) - 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 { - return err - } - - if len(owns) < 1 { - return errors.New("wrong ids") - } - - ownsMap := make(map[string]struct{}, len(owns)) - 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) -} diff --git a/internal/api/user/controller.go b/internal/api/user/controller.go index 48128f6..212865a 100644 --- a/internal/api/user/controller.go +++ b/internal/api/user/controller.go @@ -26,10 +26,10 @@ func newController(service *service, utils interfaces.Utils) *controller { func (h *Handler) RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, refreshMW gin.HandlerFunc) { userGroup := r.Group("/user") - userGroup.POST("", h.controller.register) - userGroup.GET("", authMW, h.controller.get) - userGroup.PUT("", authMW, h.controller.update) - userGroup.DELETE("", authMW, h.controller.delete) + userGroup.POST("/", h.controller.register) + userGroup.GET("/", authMW, h.controller.get) + userGroup.PUT("/", authMW, h.controller.update) + userGroup.DELETE("/", authMW, h.controller.delete) //auth h.controller.authPath = fmt.Sprintf("%s/user/auth", h.apiPrefix) diff --git a/internal/api/user/repository.go b/internal/api/user/repository.go index 4b0b754..87d2b2d 100644 --- a/internal/api/user/repository.go +++ b/internal/api/user/repository.go @@ -40,7 +40,7 @@ func (r *repo) getByUuid(userUuid string) (user User, err error) { } func (r *repo) update(user map[string]any) error { - return r.db.Model(&User{}).Where("uuid = ?", user["uuid"]).Updates(&user).Error + return r.db.Where("uuid = ?", user["uuid"]).Updates(&user).Error } func (r *repo) delete(userUuid string) error { diff --git a/internal/interfaces/utils.go b/internal/interfaces/utils.go index 31cd891..dd6b773 100644 --- a/internal/interfaces/utils.go +++ b/internal/interfaces/utils.go @@ -1,9 +1,6 @@ package interfaces -import ( - "github.com/gin-gonic/gin" - "time" -) +import "github.com/gin-gonic/gin" type Utils interface { IsEmail(email string) bool @@ -11,5 +8,4 @@ type Utils interface { GetRefreshUuidFromContext(c *gin.Context) (string, error) HashPassword(password string) (string, error) ComparePasswords(hashedPassword string, plainPassword string) error - ParseTime(t string) (time.Time, error) } diff --git a/migrations.sql b/migrations.sql index 1ffe7e5..c4df99c 100644 --- a/migrations.sql +++ b/migrations.sql @@ -55,27 +55,4 @@ CREATE TABLE prices( merch_uuid VARCHAR(36) NOT NULL, price INT NULL, origin INT -); - -CREATE TABLE labels( - id BIGSERIAL PRIMARY KEY, - created_at TIMESTAMP WITH TIME ZONE NOT NULL, - updated_at TIMESTAMP WITH TIME ZONE NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, - user_uuid VARCHAR(36) NOT NULL, - label_uuid VARCHAR(36) NOT NULL, - name VARCHAR(255), - color VARCHAR(32), - bg_color VARCHAR(32) -); - -CREATE TABLE card_labels ( - id BIGSERIAL PRIMARY KEY, - user_uuid VARCHAR(36) NOT NULL, - label_uuid VARCHAR(36) NOT NULL, - merch_uuid VARCHAR(36) NOT NULL -); - -ALTER TABLE card_labels - ADD CONSTRAINT card_labels_unique_user_label_merch - UNIQUE (user_uuid, label_uuid, merch_uuid); \ No newline at end of file +); \ No newline at end of file diff --git a/pkg/utils/time.go b/pkg/utils/time.go deleted file mode 100644 index 01bfaf6..0000000 --- a/pkg/utils/time.go +++ /dev/null @@ -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 -}