diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 2c51210..c257e09 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -18,584 +18,6 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/v1/companies": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Lista empresas", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Company" - } - } - } - } - }, - "post": { - "description": "Cadastra farmácia, distribuidora ou administrador com CNPJ e licença sanitária.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Registro de empresas", - "parameters": [ - { - "description": "Dados da empresa", - "name": "company", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.registerCompanyRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Company" - } - } - } - } - }, - "/api/v1/companies/{id}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Obter empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Company" - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "delete": { - "tags": [ - "Empresas" - ], - "summary": "Remover empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "" - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "patch": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Atualizar empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Campos para atualização", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.updateCompanyRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Company" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/api/v1/orders": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Listar pedidos", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Order" - } - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Criação de pedido com split", - "parameters": [ - { - "description": "Pedido", - "name": "order", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.createOrderRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Order" - } - } - } - } - }, - "/api/v1/orders/{id}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Consulta pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Order" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "tags": [ - "Pedidos" - ], - "summary": "Remover pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "" - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/api/v1/orders/{id}/payment": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pagamentos" - ], - "summary": "Cria preferência de pagamento Mercado Pago com split nativo", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.PaymentPreference" - } - } - } - } - }, - "/api/v1/orders/{id}/status": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Atualiza status do pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Novo status", - "name": "status", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.updateStatusRequest" - } - } - ], - "responses": { - "204": { - "description": "" - } - } - } - }, - "/api/v1/products": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Lista catálogo com lote e validade", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Product" - } - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Cadastro de produto com rastreabilidade de lote", - "parameters": [ - { - "description": "Produto", - "name": "product", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.registerProductRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Product" - } - } - } - } - }, - "/api/v1/products/{id}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Obter produto", - "parameters": [ - { - "type": "string", - "description": "Product ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Product" - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "delete": { - "tags": [ - "Produtos" - ], - "summary": "Remover produto", - "parameters": [ - { - "type": "string", - "description": "Product ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "" - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "patch": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Atualizar produto", - "parameters": [ - { - "type": "string", - "description": "Product ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Campos para atualização", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.updateProductRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Product" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, "/api/v1/auth/login": { "post": { "description": "Autentica usuário e retorna token JWT.", @@ -616,7 +38,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.loginRequest" + "$ref": "#/definitions/internal_http_handler.loginRequest" } } ], @@ -624,7 +46,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.authResponse" + "$ref": "#/definitions/internal_http_handler.authResponse" } }, "400": { @@ -668,7 +90,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerAuthRequest" + "$ref": "#/definitions/internal_http_handler.registerAuthRequest" } } ], @@ -676,7 +98,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/handler.authResponse" + "$ref": "#/definitions/internal_http_handler.authResponse" } }, "400": { @@ -718,7 +140,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } } } @@ -746,7 +168,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.addCartItemRequest" + "$ref": "#/definitions/internal_http_handler.addCartItemRequest" } } ], @@ -754,7 +176,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } }, "400": { @@ -793,7 +215,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } }, "400": { @@ -823,7 +245,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -848,7 +270,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerCompanyRequest" + "$ref": "#/definitions/internal_http_handler.registerCompanyRequest" } } ], @@ -856,7 +278,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -880,7 +302,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -908,7 +330,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } }, "404": { @@ -985,7 +407,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateCompanyRequest" + "$ref": "#/definitions/internal_http_handler.updateCompanyRequest" } } ], @@ -993,7 +415,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } }, "400": { @@ -1039,7 +461,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CompanyRating" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CompanyRating" } } } @@ -1069,7 +491,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -1093,7 +515,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.AdminDashboard" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.AdminDashboard" } } } @@ -1125,7 +547,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.SellerDashboard" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.SellerDashboard" } } } @@ -1159,7 +581,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.InventoryItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem" } } } @@ -1190,7 +612,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.inventoryAdjustRequest" + "$ref": "#/definitions/internal_http_handler.inventoryAdjustRequest" } } ], @@ -1198,7 +620,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.InventoryItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem" } }, "400": { @@ -1233,7 +655,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1257,7 +679,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createOrderRequest" + "$ref": "#/definitions/internal_http_handler.createOrderRequest" } } ], @@ -1265,7 +687,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1298,7 +720,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1374,7 +796,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.PaymentPreference" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentPreference" } } } @@ -1411,7 +833,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateStatusRequest" + "$ref": "#/definitions/internal_http_handler.updateStatusRequest" } } ], @@ -1441,7 +863,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.PaymentWebhookEvent" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent" } } ], @@ -1449,7 +871,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.PaymentSplitResult" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult" } } } @@ -1470,7 +892,7 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } } } @@ -1494,7 +916,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerProductRequest" + "$ref": "#/definitions/internal_http_handler.registerProductRequest" } } ], @@ -1502,7 +924,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } } } @@ -1530,7 +952,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "404": { @@ -1607,7 +1029,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateProductRequest" + "$ref": "#/definitions/internal_http_handler.updateProductRequest" } } ], @@ -1615,7 +1037,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "400": { @@ -1663,7 +1085,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createReviewRequest" + "$ref": "#/definitions/internal_http_handler.createReviewRequest" } } ], @@ -1671,7 +1093,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Review" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Review" } }, "400": { @@ -1710,7 +1132,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createShipmentRequest" + "$ref": "#/definitions/internal_http_handler.createShipmentRequest" } } ], @@ -1718,7 +1140,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Shipment" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment" } } } @@ -1751,7 +1173,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Shipment" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment" } } } @@ -1795,7 +1217,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.UserPage" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.UserPage" } }, "400": { @@ -1841,7 +1263,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createUserRequest" + "$ref": "#/definitions/internal_http_handler.createUserRequest" } } ], @@ -1849,7 +1271,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -1909,7 +1331,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -1971,7 +1393,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateUserRequest" + "$ref": "#/definitions/internal_http_handler.updateUserRequest" } } ], @@ -1979,7 +1401,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -2087,7 +1509,7 @@ const docTemplate = `{ } }, "definitions": { - "domain.AdminDashboard": { + "github_com_saveinmed_backend-go_internal_domain.AdminDashboard": { "type": "object", "properties": { "gmv_cents": { @@ -2101,7 +1523,7 @@ const docTemplate = `{ } } }, - "domain.CartItem": { + "github_com_saveinmed_backend-go_internal_domain.CartItem": { "type": "object", "properties": { "batch": { @@ -2136,7 +1558,7 @@ const docTemplate = `{ } } }, - "domain.CartSummary": { + "github_com_saveinmed_backend-go_internal_domain.CartSummary": { "type": "object", "properties": { "discount_cents": { @@ -2148,7 +1570,7 @@ const docTemplate = `{ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.CartItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartItem" } }, "subtotal_cents": { @@ -2159,7 +1581,7 @@ const docTemplate = `{ } } }, - "domain.Company": { + "github_com_saveinmed_backend-go_internal_domain.Company": { "type": "object", "properties": { "cnpj": { @@ -2189,7 +1611,7 @@ const docTemplate = `{ } } }, - "domain.CompanyRating": { + "github_com_saveinmed_backend-go_internal_domain.CompanyRating": { "type": "object", "properties": { "average_score": { @@ -2203,7 +1625,7 @@ const docTemplate = `{ } } }, - "domain.InventoryItem": { + "github_com_saveinmed_backend-go_internal_domain.InventoryItem": { "type": "object", "properties": { "batch": { @@ -2232,7 +1654,7 @@ const docTemplate = `{ } } }, - "domain.Order": { + "github_com_saveinmed_backend-go_internal_domain.Order": { "type": "object", "properties": { "buyer_id": { @@ -2247,17 +1669,17 @@ const docTemplate = `{ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.OrderItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem" } }, "seller_id": { "type": "string" }, "shipping": { - "$ref": "#/definitions/domain.ShippingAddress" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress" }, "status": { - "$ref": "#/definitions/domain.OrderStatus" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderStatus" }, "total_cents": { "type": "integer" @@ -2267,7 +1689,7 @@ const docTemplate = `{ } } }, - "domain.OrderItem": { + "github_com_saveinmed_backend-go_internal_domain.OrderItem": { "type": "object", "properties": { "batch": { @@ -2293,7 +1715,7 @@ const docTemplate = `{ } } }, - "domain.OrderStatus": { + "github_com_saveinmed_backend-go_internal_domain.OrderStatus": { "type": "string", "enum": [ "Pendente", @@ -2308,7 +1730,7 @@ const docTemplate = `{ "OrderStatusDelivered" ] }, - "domain.PaymentPreference": { + "github_com_saveinmed_backend-go_internal_domain.PaymentPreference": { "type": "object", "properties": { "commission_pct": { @@ -2331,7 +1753,7 @@ const docTemplate = `{ } } }, - "domain.PaymentSplitResult": { + "github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult": { "type": "object", "properties": { "marketplace_fee": { @@ -2354,7 +1776,7 @@ const docTemplate = `{ } } }, - "domain.PaymentWebhookEvent": { + "github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent": { "type": "object", "properties": { "marketplace_fee": { @@ -2377,7 +1799,7 @@ const docTemplate = `{ } } }, - "domain.Product": { + "github_com_saveinmed_backend-go_internal_domain.Product": { "type": "object", "properties": { "batch": { @@ -2412,7 +1834,7 @@ const docTemplate = `{ } } }, - "domain.Review": { + "github_com_saveinmed_backend-go_internal_domain.Review": { "type": "object", "properties": { "buyer_id": { @@ -2438,13 +1860,13 @@ const docTemplate = `{ } } }, - "domain.SellerDashboard": { + "github_com_saveinmed_backend-go_internal_domain.SellerDashboard": { "type": "object", "properties": { "low_stock_alerts": { "type": "array", "items": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "orders_count": { @@ -2456,7 +1878,7 @@ const docTemplate = `{ "top_products": { "type": "array", "items": { - "$ref": "#/definitions/domain.TopProduct" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.TopProduct" } }, "total_sales_cents": { @@ -2464,7 +1886,7 @@ const docTemplate = `{ } } }, - "domain.Shipment": { + "github_com_saveinmed_backend-go_internal_domain.Shipment": { "type": "object", "properties": { "carrier": { @@ -2493,7 +1915,7 @@ const docTemplate = `{ } } }, - "domain.ShippingAddress": { + "github_com_saveinmed_backend-go_internal_domain.ShippingAddress": { "type": "object", "properties": { "city": { @@ -2525,7 +1947,7 @@ const docTemplate = `{ } } }, - "domain.TopProduct": { + "github_com_saveinmed_backend-go_internal_domain.TopProduct": { "type": "object", "properties": { "name": { @@ -2542,7 +1964,7 @@ const docTemplate = `{ } } }, - "domain.User": { + "github_com_saveinmed_backend-go_internal_domain.User": { "type": "object", "properties": { "company_id": { @@ -2568,7 +1990,7 @@ const docTemplate = `{ } } }, - "domain.UserPage": { + "github_com_saveinmed_backend-go_internal_domain.UserPage": { "type": "object", "properties": { "page": { @@ -2583,12 +2005,12 @@ const docTemplate = `{ "users": { "type": "array", "items": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } } } }, - "handler.addCartItemRequest": { + "internal_http_handler.addCartItemRequest": { "type": "object", "properties": { "product_id": { @@ -2599,7 +2021,7 @@ const docTemplate = `{ } } }, - "handler.authResponse": { + "internal_http_handler.authResponse": { "type": "object", "properties": { "expires_at": { @@ -2610,7 +2032,7 @@ const docTemplate = `{ } } }, - "handler.createOrderRequest": { + "internal_http_handler.createOrderRequest": { "type": "object", "properties": { "buyer_id": { @@ -2619,18 +2041,18 @@ const docTemplate = `{ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.OrderItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem" } }, "seller_id": { "type": "string" }, "shipping": { - "$ref": "#/definitions/domain.ShippingAddress" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress" } } }, - "handler.createReviewRequest": { + "internal_http_handler.createReviewRequest": { "type": "object", "properties": { "comment": { @@ -2644,7 +2066,7 @@ const docTemplate = `{ } } }, - "handler.createShipmentRequest": { + "internal_http_handler.createShipmentRequest": { "type": "object", "properties": { "carrier": { @@ -2661,7 +2083,7 @@ const docTemplate = `{ } } }, - "handler.createUserRequest": { + "internal_http_handler.createUserRequest": { "type": "object", "properties": { "company_id": { @@ -2681,7 +2103,7 @@ const docTemplate = `{ } } }, - "handler.inventoryAdjustRequest": { + "internal_http_handler.inventoryAdjustRequest": { "type": "object", "properties": { "delta": { @@ -2695,7 +2117,7 @@ const docTemplate = `{ } } }, - "handler.loginRequest": { + "internal_http_handler.loginRequest": { "type": "object", "properties": { "email": { @@ -2706,11 +2128,11 @@ const docTemplate = `{ } } }, - "handler.registerAuthRequest": { + "internal_http_handler.registerAuthRequest": { "type": "object", "properties": { "company": { - "$ref": "#/definitions/handler.registerCompanyTarget" + "$ref": "#/definitions/internal_http_handler.registerCompanyTarget" }, "company_id": { "type": "string" @@ -2729,7 +2151,7 @@ const docTemplate = `{ } } }, - "handler.registerCompanyRequest": { + "internal_http_handler.registerCompanyRequest": { "type": "object", "properties": { "cnpj": { @@ -2746,7 +2168,7 @@ const docTemplate = `{ } } }, - "handler.registerCompanyTarget": { + "internal_http_handler.registerCompanyTarget": { "type": "object", "properties": { "cnpj": { @@ -2766,7 +2188,7 @@ const docTemplate = `{ } } }, - "handler.registerProductRequest": { + "internal_http_handler.registerProductRequest": { "type": "object", "properties": { "batch": { @@ -2792,7 +2214,7 @@ const docTemplate = `{ } } }, - "handler.updateCompanyRequest": { + "internal_http_handler.updateCompanyRequest": { "type": "object", "properties": { "cnpj": { @@ -2812,7 +2234,7 @@ const docTemplate = `{ } } }, - "handler.updateProductRequest": { + "internal_http_handler.updateProductRequest": { "type": "object", "properties": { "batch": { @@ -2838,7 +2260,7 @@ const docTemplate = `{ } } }, - "handler.updateStatusRequest": { + "internal_http_handler.updateStatusRequest": { "type": "object", "properties": { "status": { @@ -2846,7 +2268,7 @@ const docTemplate = `{ } } }, - "handler.updateUserRequest": { + "internal_http_handler.updateUserRequest": { "type": "object", "properties": { "company_id": { diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index 8a83991..a6a4a43 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -14,453 +14,6 @@ }, "basePath": "/", "paths": { - "/api/v1/companies": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Lista empresas", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Company" - } - } - } - } - }, - "post": { - "description": "Cadastra farmácia, distribuidora ou administrador com CNPJ e licença sanitária.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Registro de empresas", - "parameters": [ - { - "description": "Dados da empresa", - "name": "company", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.registerCompanyRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Company" - } - } - } - } - }, - "/api/v1/companies/{id}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Obter empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Company" - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "delete": { - "tags": [ - "Empresas" - ], - "summary": "Remover empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "" - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "patch": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Empresas" - ], - "summary": "Atualizar empresa", - "parameters": [ - { - "type": "string", - "description": "Company ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Campos para atualização", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.updateCompanyRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Company" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/api/v1/orders": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Listar pedidos", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Order" - } - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Criação de pedido com split", - "parameters": [ - { - "description": "Pedido", - "name": "order", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.createOrderRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Order" - } - } - } - } - }, - "/api/v1/orders/{id}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Consulta pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.Order" - } - } - } - }, - "delete": { - "security": [ - { - "BearerAuth": [] - } - ], - "tags": [ - "Pedidos" - ], - "summary": "Remover pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "" - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/api/v1/orders/{id}/payment": { - "post": { - "security": [ - { - "BearerAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pagamentos" - ], - "summary": "Cria preferência de pagamento Mercado Pago com split nativo", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.PaymentPreference" - } - } - } - } - }, - "/api/v1/orders/{id}/status": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Pedidos" - ], - "summary": "Atualiza status do pedido", - "parameters": [ - { - "type": "string", - "description": "Order ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Novo status", - "name": "status", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.updateStatusRequest" - } - } - ], - "responses": { - "204": { - "description": "" - } - } - } - }, - "/api/v1/products": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Lista catálogo com lote e validade", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.Product" - } - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Produtos" - ], - "summary": "Cadastro de produto com rastreabilidade de lote", - "parameters": [ - { - "description": "Produto", - "name": "product", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/handler.registerProductRequest" - } - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "$ref": "#/definitions/domain.Product" - } - } - } - } - }, "/api/v1/auth/login": { "post": { "description": "Autentica usuário e retorna token JWT.", @@ -481,7 +34,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.loginRequest" + "$ref": "#/definitions/internal_http_handler.loginRequest" } } ], @@ -489,7 +42,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.authResponse" + "$ref": "#/definitions/internal_http_handler.authResponse" } }, "400": { @@ -533,7 +86,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerAuthRequest" + "$ref": "#/definitions/internal_http_handler.registerAuthRequest" } } ], @@ -541,7 +94,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/handler.authResponse" + "$ref": "#/definitions/internal_http_handler.authResponse" } }, "400": { @@ -583,7 +136,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } } } @@ -611,7 +164,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.addCartItemRequest" + "$ref": "#/definitions/internal_http_handler.addCartItemRequest" } } ], @@ -619,7 +172,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } }, "400": { @@ -658,7 +211,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CartSummary" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary" } }, "400": { @@ -688,7 +241,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -713,7 +266,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerCompanyRequest" + "$ref": "#/definitions/internal_http_handler.registerCompanyRequest" } } ], @@ -721,7 +274,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -745,7 +298,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -773,7 +326,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } }, "404": { @@ -850,7 +403,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateCompanyRequest" + "$ref": "#/definitions/internal_http_handler.updateCompanyRequest" } } ], @@ -858,7 +411,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } }, "400": { @@ -904,7 +457,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CompanyRating" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CompanyRating" } } } @@ -934,7 +487,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Company" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Company" } } } @@ -958,7 +511,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.AdminDashboard" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.AdminDashboard" } } } @@ -990,7 +543,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.SellerDashboard" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.SellerDashboard" } } } @@ -1024,7 +577,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.InventoryItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem" } } } @@ -1055,7 +608,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.inventoryAdjustRequest" + "$ref": "#/definitions/internal_http_handler.inventoryAdjustRequest" } } ], @@ -1063,7 +616,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.InventoryItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem" } }, "400": { @@ -1098,7 +651,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1122,7 +675,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createOrderRequest" + "$ref": "#/definitions/internal_http_handler.createOrderRequest" } } ], @@ -1130,7 +683,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1163,7 +716,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Order" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Order" } } } @@ -1239,7 +792,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.PaymentPreference" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentPreference" } } } @@ -1276,7 +829,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateStatusRequest" + "$ref": "#/definitions/internal_http_handler.updateStatusRequest" } } ], @@ -1306,7 +859,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.PaymentWebhookEvent" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent" } } ], @@ -1314,7 +867,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.PaymentSplitResult" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult" } } } @@ -1335,7 +888,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } } } @@ -1359,7 +912,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.registerProductRequest" + "$ref": "#/definitions/internal_http_handler.registerProductRequest" } } ], @@ -1367,7 +920,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } } } @@ -1395,7 +948,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "404": { @@ -1472,7 +1025,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateProductRequest" + "$ref": "#/definitions/internal_http_handler.updateProductRequest" } } ], @@ -1480,7 +1033,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "400": { @@ -1528,7 +1081,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createReviewRequest" + "$ref": "#/definitions/internal_http_handler.createReviewRequest" } } ], @@ -1536,7 +1089,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Review" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Review" } }, "400": { @@ -1575,7 +1128,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createShipmentRequest" + "$ref": "#/definitions/internal_http_handler.createShipmentRequest" } } ], @@ -1583,7 +1136,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.Shipment" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment" } } } @@ -1616,7 +1169,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Shipment" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment" } } } @@ -1660,7 +1213,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.UserPage" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.UserPage" } }, "400": { @@ -1706,7 +1259,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.createUserRequest" + "$ref": "#/definitions/internal_http_handler.createUserRequest" } } ], @@ -1714,7 +1267,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -1774,7 +1327,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -1836,7 +1389,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/handler.updateUserRequest" + "$ref": "#/definitions/internal_http_handler.updateUserRequest" } } ], @@ -1844,7 +1397,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } }, "400": { @@ -1952,7 +1505,7 @@ } }, "definitions": { - "domain.AdminDashboard": { + "github_com_saveinmed_backend-go_internal_domain.AdminDashboard": { "type": "object", "properties": { "gmv_cents": { @@ -1966,7 +1519,7 @@ } } }, - "domain.CartItem": { + "github_com_saveinmed_backend-go_internal_domain.CartItem": { "type": "object", "properties": { "batch": { @@ -2001,7 +1554,7 @@ } } }, - "domain.CartSummary": { + "github_com_saveinmed_backend-go_internal_domain.CartSummary": { "type": "object", "properties": { "discount_cents": { @@ -2013,7 +1566,7 @@ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.CartItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.CartItem" } }, "subtotal_cents": { @@ -2024,7 +1577,7 @@ } } }, - "domain.Company": { + "github_com_saveinmed_backend-go_internal_domain.Company": { "type": "object", "properties": { "cnpj": { @@ -2054,7 +1607,7 @@ } } }, - "domain.CompanyRating": { + "github_com_saveinmed_backend-go_internal_domain.CompanyRating": { "type": "object", "properties": { "average_score": { @@ -2068,7 +1621,7 @@ } } }, - "domain.InventoryItem": { + "github_com_saveinmed_backend-go_internal_domain.InventoryItem": { "type": "object", "properties": { "batch": { @@ -2097,7 +1650,7 @@ } } }, - "domain.Order": { + "github_com_saveinmed_backend-go_internal_domain.Order": { "type": "object", "properties": { "buyer_id": { @@ -2112,17 +1665,17 @@ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.OrderItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem" } }, "seller_id": { "type": "string" }, "shipping": { - "$ref": "#/definitions/domain.ShippingAddress" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress" }, "status": { - "$ref": "#/definitions/domain.OrderStatus" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderStatus" }, "total_cents": { "type": "integer" @@ -2132,7 +1685,7 @@ } } }, - "domain.OrderItem": { + "github_com_saveinmed_backend-go_internal_domain.OrderItem": { "type": "object", "properties": { "batch": { @@ -2158,7 +1711,7 @@ } } }, - "domain.OrderStatus": { + "github_com_saveinmed_backend-go_internal_domain.OrderStatus": { "type": "string", "enum": [ "Pendente", @@ -2173,7 +1726,7 @@ "OrderStatusDelivered" ] }, - "domain.PaymentPreference": { + "github_com_saveinmed_backend-go_internal_domain.PaymentPreference": { "type": "object", "properties": { "commission_pct": { @@ -2196,7 +1749,7 @@ } } }, - "domain.PaymentSplitResult": { + "github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult": { "type": "object", "properties": { "marketplace_fee": { @@ -2219,7 +1772,7 @@ } } }, - "domain.PaymentWebhookEvent": { + "github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent": { "type": "object", "properties": { "marketplace_fee": { @@ -2242,7 +1795,7 @@ } } }, - "domain.Product": { + "github_com_saveinmed_backend-go_internal_domain.Product": { "type": "object", "properties": { "batch": { @@ -2277,7 +1830,7 @@ } } }, - "domain.Review": { + "github_com_saveinmed_backend-go_internal_domain.Review": { "type": "object", "properties": { "buyer_id": { @@ -2303,13 +1856,13 @@ } } }, - "domain.SellerDashboard": { + "github_com_saveinmed_backend-go_internal_domain.SellerDashboard": { "type": "object", "properties": { "low_stock_alerts": { "type": "array", "items": { - "$ref": "#/definitions/domain.Product" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.Product" } }, "orders_count": { @@ -2321,7 +1874,7 @@ "top_products": { "type": "array", "items": { - "$ref": "#/definitions/domain.TopProduct" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.TopProduct" } }, "total_sales_cents": { @@ -2329,7 +1882,7 @@ } } }, - "domain.Shipment": { + "github_com_saveinmed_backend-go_internal_domain.Shipment": { "type": "object", "properties": { "carrier": { @@ -2358,7 +1911,7 @@ } } }, - "domain.ShippingAddress": { + "github_com_saveinmed_backend-go_internal_domain.ShippingAddress": { "type": "object", "properties": { "city": { @@ -2390,7 +1943,7 @@ } } }, - "domain.TopProduct": { + "github_com_saveinmed_backend-go_internal_domain.TopProduct": { "type": "object", "properties": { "name": { @@ -2407,7 +1960,7 @@ } } }, - "domain.User": { + "github_com_saveinmed_backend-go_internal_domain.User": { "type": "object", "properties": { "company_id": { @@ -2433,7 +1986,7 @@ } } }, - "domain.UserPage": { + "github_com_saveinmed_backend-go_internal_domain.UserPage": { "type": "object", "properties": { "page": { @@ -2448,12 +2001,12 @@ "users": { "type": "array", "items": { - "$ref": "#/definitions/domain.User" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.User" } } } }, - "handler.addCartItemRequest": { + "internal_http_handler.addCartItemRequest": { "type": "object", "properties": { "product_id": { @@ -2464,7 +2017,7 @@ } } }, - "handler.authResponse": { + "internal_http_handler.authResponse": { "type": "object", "properties": { "expires_at": { @@ -2475,7 +2028,7 @@ } } }, - "handler.createOrderRequest": { + "internal_http_handler.createOrderRequest": { "type": "object", "properties": { "buyer_id": { @@ -2484,18 +2037,18 @@ "items": { "type": "array", "items": { - "$ref": "#/definitions/domain.OrderItem" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem" } }, "seller_id": { "type": "string" }, "shipping": { - "$ref": "#/definitions/domain.ShippingAddress" + "$ref": "#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress" } } }, - "handler.createReviewRequest": { + "internal_http_handler.createReviewRequest": { "type": "object", "properties": { "comment": { @@ -2509,7 +2062,7 @@ } } }, - "handler.createShipmentRequest": { + "internal_http_handler.createShipmentRequest": { "type": "object", "properties": { "carrier": { @@ -2526,7 +2079,7 @@ } } }, - "handler.createUserRequest": { + "internal_http_handler.createUserRequest": { "type": "object", "properties": { "company_id": { @@ -2546,7 +2099,7 @@ } } }, - "handler.inventoryAdjustRequest": { + "internal_http_handler.inventoryAdjustRequest": { "type": "object", "properties": { "delta": { @@ -2560,7 +2113,7 @@ } } }, - "handler.loginRequest": { + "internal_http_handler.loginRequest": { "type": "object", "properties": { "email": { @@ -2571,11 +2124,11 @@ } } }, - "handler.registerAuthRequest": { + "internal_http_handler.registerAuthRequest": { "type": "object", "properties": { "company": { - "$ref": "#/definitions/handler.registerCompanyTarget" + "$ref": "#/definitions/internal_http_handler.registerCompanyTarget" }, "company_id": { "type": "string" @@ -2594,7 +2147,7 @@ } } }, - "handler.registerCompanyRequest": { + "internal_http_handler.registerCompanyRequest": { "type": "object", "properties": { "cnpj": { @@ -2611,7 +2164,7 @@ } } }, - "handler.registerCompanyTarget": { + "internal_http_handler.registerCompanyTarget": { "type": "object", "properties": { "cnpj": { @@ -2631,7 +2184,7 @@ } } }, - "handler.registerProductRequest": { + "internal_http_handler.registerProductRequest": { "type": "object", "properties": { "batch": { @@ -2657,7 +2210,7 @@ } } }, - "handler.updateCompanyRequest": { + "internal_http_handler.updateCompanyRequest": { "type": "object", "properties": { "cnpj": { @@ -2677,7 +2230,7 @@ } } }, - "handler.updateProductRequest": { + "internal_http_handler.updateProductRequest": { "type": "object", "properties": { "batch": { @@ -2703,7 +2256,7 @@ } } }, - "handler.updateStatusRequest": { + "internal_http_handler.updateStatusRequest": { "type": "object", "properties": { "status": { @@ -2711,7 +2264,7 @@ } } }, - "handler.updateUserRequest": { + "internal_http_handler.updateUserRequest": { "type": "object", "properties": { "company_id": { @@ -2739,4 +2292,4 @@ "in": "header" } } -} +} \ No newline at end of file diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index e2d7747..3dcc215 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -1,6 +1,6 @@ basePath: / definitions: - domain.AdminDashboard: + github_com_saveinmed_backend-go_internal_domain.AdminDashboard: properties: gmv_cents: type: integer @@ -9,7 +9,7 @@ definitions: window_start_at: type: string type: object - domain.CartItem: + github_com_saveinmed_backend-go_internal_domain.CartItem: properties: batch: type: string @@ -32,7 +32,7 @@ definitions: updated_at: type: string type: object - domain.CartSummary: + github_com_saveinmed_backend-go_internal_domain.CartSummary: properties: discount_cents: type: integer @@ -40,14 +40,14 @@ definitions: type: string items: items: - $ref: '#/definitions/domain.CartItem' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.CartItem' type: array subtotal_cents: type: integer total_cents: type: integer type: object - domain.Company: + github_com_saveinmed_backend-go_internal_domain.Company: properties: cnpj: type: string @@ -67,7 +67,7 @@ definitions: updated_at: type: string type: object - domain.CompanyRating: + github_com_saveinmed_backend-go_internal_domain.CompanyRating: properties: average_score: type: number @@ -76,7 +76,7 @@ definitions: total_reviews: type: integer type: object - domain.InventoryItem: + github_com_saveinmed_backend-go_internal_domain.InventoryItem: properties: batch: type: string @@ -95,7 +95,7 @@ definitions: updated_at: type: string type: object - domain.Order: + github_com_saveinmed_backend-go_internal_domain.Order: properties: buyer_id: type: string @@ -105,20 +105,20 @@ definitions: type: string items: items: - $ref: '#/definitions/domain.OrderItem' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem' type: array seller_id: type: string shipping: - $ref: '#/definitions/domain.ShippingAddress' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress' status: - $ref: '#/definitions/domain.OrderStatus' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderStatus' total_cents: type: integer updated_at: type: string type: object - domain.OrderItem: + github_com_saveinmed_backend-go_internal_domain.OrderItem: properties: batch: type: string @@ -135,7 +135,7 @@ definitions: unit_cents: type: integer type: object - domain.OrderStatus: + github_com_saveinmed_backend-go_internal_domain.OrderStatus: enum: - Pendente - Pago @@ -147,7 +147,7 @@ definitions: - OrderStatusPaid - OrderStatusInvoiced - OrderStatusDelivered - domain.PaymentPreference: + github_com_saveinmed_backend-go_internal_domain.PaymentPreference: properties: commission_pct: type: number @@ -162,7 +162,7 @@ definitions: seller_receivable: type: integer type: object - domain.PaymentSplitResult: + github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult: properties: marketplace_fee: type: integer @@ -177,7 +177,7 @@ definitions: total_paid_amount: type: integer type: object - domain.PaymentWebhookEvent: + github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent: properties: marketplace_fee: type: integer @@ -192,7 +192,7 @@ definitions: total_paid_amount: type: integer type: object - domain.Product: + github_com_saveinmed_backend-go_internal_domain.Product: properties: batch: type: string @@ -215,7 +215,7 @@ definitions: updated_at: type: string type: object - domain.Review: + github_com_saveinmed_backend-go_internal_domain.Review: properties: buyer_id: type: string @@ -232,11 +232,11 @@ definitions: seller_id: type: string type: object - domain.SellerDashboard: + github_com_saveinmed_backend-go_internal_domain.SellerDashboard: properties: low_stock_alerts: items: - $ref: '#/definitions/domain.Product' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Product' type: array orders_count: type: integer @@ -244,12 +244,12 @@ definitions: type: string top_products: items: - $ref: '#/definitions/domain.TopProduct' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.TopProduct' type: array total_sales_cents: type: integer type: object - domain.Shipment: + github_com_saveinmed_backend-go_internal_domain.Shipment: properties: carrier: type: string @@ -268,7 +268,7 @@ definitions: updated_at: type: string type: object - domain.ShippingAddress: + github_com_saveinmed_backend-go_internal_domain.ShippingAddress: properties: city: type: string @@ -289,7 +289,7 @@ definitions: zip_code: type: string type: object - domain.TopProduct: + github_com_saveinmed_backend-go_internal_domain.TopProduct: properties: name: type: string @@ -300,7 +300,7 @@ definitions: total_quantity: type: integer type: object - domain.User: + github_com_saveinmed_backend-go_internal_domain.User: properties: company_id: type: string @@ -317,7 +317,7 @@ definitions: updated_at: type: string type: object - domain.UserPage: + github_com_saveinmed_backend-go_internal_domain.UserPage: properties: page: type: integer @@ -327,37 +327,37 @@ definitions: type: integer users: items: - $ref: '#/definitions/domain.User' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.User' type: array type: object - handler.addCartItemRequest: + internal_http_handler.addCartItemRequest: properties: product_id: type: string quantity: type: integer type: object - handler.authResponse: + internal_http_handler.authResponse: properties: expires_at: type: string token: type: string type: object - handler.createOrderRequest: + internal_http_handler.createOrderRequest: properties: buyer_id: type: string items: items: - $ref: '#/definitions/domain.OrderItem' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.OrderItem' type: array seller_id: type: string shipping: - $ref: '#/definitions/domain.ShippingAddress' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.ShippingAddress' type: object - handler.createReviewRequest: + internal_http_handler.createReviewRequest: properties: comment: type: string @@ -366,7 +366,7 @@ definitions: rating: type: integer type: object - handler.createShipmentRequest: + internal_http_handler.createShipmentRequest: properties: carrier: type: string @@ -377,7 +377,7 @@ definitions: tracking_code: type: string type: object - handler.createUserRequest: + internal_http_handler.createUserRequest: properties: company_id: type: string @@ -390,7 +390,7 @@ definitions: role: type: string type: object - handler.inventoryAdjustRequest: + internal_http_handler.inventoryAdjustRequest: properties: delta: type: integer @@ -399,17 +399,17 @@ definitions: reason: type: string type: object - handler.loginRequest: + internal_http_handler.loginRequest: properties: email: type: string password: type: string type: object - handler.registerAuthRequest: + internal_http_handler.registerAuthRequest: properties: company: - $ref: '#/definitions/handler.registerCompanyTarget' + $ref: '#/definitions/internal_http_handler.registerCompanyTarget' company_id: type: string email: @@ -421,7 +421,7 @@ definitions: role: type: string type: object - handler.registerCompanyRequest: + internal_http_handler.registerCompanyRequest: properties: cnpj: type: string @@ -432,7 +432,7 @@ definitions: role: type: string type: object - handler.registerCompanyTarget: + internal_http_handler.registerCompanyTarget: properties: cnpj: type: string @@ -445,7 +445,7 @@ definitions: role: type: string type: object - handler.registerProductRequest: + internal_http_handler.registerProductRequest: properties: batch: type: string @@ -462,7 +462,7 @@ definitions: stock: type: integer type: object - handler.updateCompanyRequest: + internal_http_handler.updateCompanyRequest: properties: cnpj: type: string @@ -475,7 +475,7 @@ definitions: role: type: string type: object - handler.updateProductRequest: + internal_http_handler.updateProductRequest: properties: batch: type: string @@ -492,12 +492,12 @@ definitions: stock: type: integer type: object - handler.updateStatusRequest: + internal_http_handler.updateStatusRequest: properties: status: type: string type: object - handler.updateUserRequest: + internal_http_handler.updateUserRequest: properties: company_id: type: string @@ -519,291 +519,6 @@ info: title: SaveInMed Performance Core API version: "1.0" paths: - /api/v1/companies: - get: - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/domain.Company' - type: array - summary: Lista empresas - tags: - - Empresas - post: - consumes: - - application/json - description: Cadastra farmácia, distribuidora ou administrador com CNPJ e licença - sanitária. - parameters: - - description: Dados da empresa - in: body - name: company - required: true - schema: - $ref: '#/definitions/handler.registerCompanyRequest' - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/domain.Company' - summary: Registro de empresas - tags: - - Empresas - /api/v1/companies/{id}: - delete: - parameters: - - description: Company ID - in: path - name: id - required: true - type: string - responses: - "204": - description: "" - "400": - description: Bad Request - schema: - additionalProperties: - type: string - type: object - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - summary: Remover empresa - tags: - - Empresas - get: - parameters: - - description: Company ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/domain.Company' - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - summary: Obter empresa - tags: - - Empresas - patch: - consumes: - - application/json - parameters: - - description: Company ID - in: path - name: id - required: true - type: string - - description: Campos para atualização - in: body - name: payload - required: true - schema: - $ref: '#/definitions/handler.updateCompanyRequest' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/domain.Company' - "400": - description: Bad Request - schema: - additionalProperties: - type: string - type: object - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - summary: Atualizar empresa - tags: - - Empresas - /api/v1/orders: - get: - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/domain.Order' - type: array - security: - - BearerAuth: [] - summary: Listar pedidos - tags: - - Pedidos - post: - consumes: - - application/json - parameters: - - description: Pedido - in: body - name: order - required: true - schema: - $ref: '#/definitions/handler.createOrderRequest' - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/domain.Order' - summary: Criação de pedido com split - tags: - - Pedidos - /api/v1/orders/{id}: - delete: - parameters: - - description: Order ID - in: path - name: id - required: true - type: string - responses: - "204": - description: "" - "400": - description: Bad Request - schema: - additionalProperties: - type: string - type: object - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - security: - - BearerAuth: [] - summary: Remover pedido - tags: - - Pedidos - get: - parameters: - - description: Order ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/domain.Order' - security: - - BearerAuth: [] - summary: Consulta pedido - tags: - - Pedidos - /api/v1/orders/{id}/payment: - post: - parameters: - - description: Order ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/domain.PaymentPreference' - security: - - BearerAuth: [] - summary: Cria preferência de pagamento Mercado Pago com split nativo - tags: - - Pagamentos - /api/v1/orders/{id}/status: - patch: - consumes: - - application/json - parameters: - - description: Order ID - in: path - name: id - required: true - type: string - - description: Novo status - in: body - name: status - required: true - schema: - $ref: '#/definitions/handler.updateStatusRequest' - produces: - - application/json - responses: - "204": - description: "" - security: - - BearerAuth: [] - summary: Atualiza status do pedido - tags: - - Pedidos - /api/v1/products: - get: - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/domain.Product' - type: array - summary: Lista catálogo com lote e validade - tags: - - Produtos - post: - consumes: - - application/json - parameters: - - description: Produto - in: body - name: product - required: true - schema: - $ref: '#/definitions/handler.registerProductRequest' - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/domain.Product' - summary: Cadastro de produto com rastreabilidade de lote - tags: - - Produtos /api/v1/auth/login: post: consumes: @@ -815,14 +530,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.loginRequest' + $ref: '#/definitions/internal_http_handler.loginRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/handler.authResponse' + $ref: '#/definitions/internal_http_handler.authResponse' "400": description: Bad Request schema: @@ -849,14 +564,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.registerAuthRequest' + $ref: '#/definitions/internal_http_handler.registerAuthRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/handler.authResponse' + $ref: '#/definitions/internal_http_handler.authResponse' "400": description: Bad Request schema: @@ -880,7 +595,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.CartSummary' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary' security: - BearerAuth: [] summary: Obter carrinho @@ -895,14 +610,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.addCartItemRequest' + $ref: '#/definitions/internal_http_handler.addCartItemRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.CartSummary' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary' "400": description: Bad Request schema: @@ -926,7 +641,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.CartSummary' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.CartSummary' "400": description: Bad Request schema: @@ -947,7 +662,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' type: array summary: Lista empresas tags: @@ -963,14 +678,14 @@ paths: name: company required: true schema: - $ref: '#/definitions/handler.registerCompanyRequest' + $ref: '#/definitions/internal_http_handler.registerCompanyRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' summary: Registro de empresas tags: - Empresas @@ -1013,7 +728,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' "404": description: Not Found schema: @@ -1037,14 +752,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.updateCompanyRequest' + $ref: '#/definitions/internal_http_handler.updateCompanyRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' "400": description: Bad Request schema: @@ -1074,7 +789,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.CompanyRating' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.CompanyRating' summary: Obter avaliação da empresa tags: - Empresas @@ -1090,7 +805,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' security: - BearerAuth: [] summary: Verificar empresa @@ -1104,7 +819,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Company' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Company' security: - BearerAuth: [] summary: Obter minha empresa @@ -1118,7 +833,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.AdminDashboard' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.AdminDashboard' security: - BearerAuth: [] summary: Dashboard do administrador @@ -1137,7 +852,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.SellerDashboard' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.SellerDashboard' security: - BearerAuth: [] summary: Dashboard do vendedor @@ -1157,7 +872,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/domain.InventoryItem' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem' type: array security: - BearerAuth: [] @@ -1174,14 +889,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.inventoryAdjustRequest' + $ref: '#/definitions/internal_http_handler.inventoryAdjustRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.InventoryItem' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.InventoryItem' "400": description: Bad Request schema: @@ -1202,7 +917,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/domain.Order' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Order' type: array security: - BearerAuth: [] @@ -1218,14 +933,14 @@ paths: name: order required: true schema: - $ref: '#/definitions/handler.createOrderRequest' + $ref: '#/definitions/internal_http_handler.createOrderRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.Order' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Order' summary: Criação de pedido com split tags: - Pedidos @@ -1270,7 +985,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Order' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Order' security: - BearerAuth: [] summary: Consulta pedido @@ -1290,7 +1005,7 @@ paths: "201": description: Created schema: - $ref: '#/definitions/domain.PaymentPreference' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentPreference' security: - BearerAuth: [] summary: Cria preferência de pagamento Mercado Pago com split nativo @@ -1311,7 +1026,7 @@ paths: name: status required: true schema: - $ref: '#/definitions/handler.updateStatusRequest' + $ref: '#/definitions/internal_http_handler.updateStatusRequest' produces: - application/json responses: @@ -1332,14 +1047,14 @@ paths: name: notification required: true schema: - $ref: '#/definitions/domain.PaymentWebhookEvent' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentWebhookEvent' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.PaymentSplitResult' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.PaymentSplitResult' summary: Recebe notificações do Mercado Pago tags: - Pagamentos @@ -1352,7 +1067,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/domain.Product' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Product' type: array summary: Lista catálogo com lote e validade tags: @@ -1366,14 +1081,14 @@ paths: name: product required: true schema: - $ref: '#/definitions/handler.registerProductRequest' + $ref: '#/definitions/internal_http_handler.registerProductRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.Product' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Product' summary: Cadastro de produto com rastreabilidade de lote tags: - Produtos @@ -1416,7 +1131,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Product' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Product' "404": description: Not Found schema: @@ -1440,14 +1155,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.updateProductRequest' + $ref: '#/definitions/internal_http_handler.updateProductRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.Product' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Product' "400": description: Bad Request schema: @@ -1473,14 +1188,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.createReviewRequest' + $ref: '#/definitions/internal_http_handler.createReviewRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.Review' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Review' "400": description: Bad Request schema: @@ -1502,14 +1217,14 @@ paths: name: shipment required: true schema: - $ref: '#/definitions/handler.createShipmentRequest' + $ref: '#/definitions/internal_http_handler.createShipmentRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.Shipment' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment' security: - BearerAuth: [] summary: Gera guia de postagem/transporte @@ -1529,7 +1244,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.Shipment' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.Shipment' security: - BearerAuth: [] summary: Rastreia entrega @@ -1556,7 +1271,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.UserPage' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.UserPage' "400": description: Bad Request schema: @@ -1583,14 +1298,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.createUserRequest' + $ref: '#/definitions/internal_http_handler.createUserRequest' produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/domain.User' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.User' "400": description: Bad Request schema: @@ -1669,7 +1384,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.User' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.User' "400": description: Bad Request schema: @@ -1707,14 +1422,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/handler.updateUserRequest' + $ref: '#/definitions/internal_http_handler.updateUserRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.User' + $ref: '#/definitions/github_com_saveinmed_backend-go_internal_domain.User' "400": description: Bad Request schema: diff --git a/backend/internal/http/handler/handler.go b/backend/internal/http/handler/handler.go index 27ec190..079c6ba 100644 --- a/backend/internal/http/handler/handler.go +++ b/backend/internal/http/handler/handler.go @@ -123,7 +123,6 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) { // @Param company body registerCompanyRequest true "Dados da empresa" // @Success 201 {object} domain.Company // @Router /api/v1/companies [post] -// @Router /api/v1/companies [post] func (h *Handler) CreateCompany(w http.ResponseWriter, r *http.Request) { var req registerCompanyRequest if err := decodeJSON(r.Context(), r, &req); err != nil { @@ -152,7 +151,6 @@ func (h *Handler) CreateCompany(w http.ResponseWriter, r *http.Request) { // @Produce json // @Success 200 {array} domain.Company // @Router /api/v1/companies [get] -// @Router /api/v1/companies [get] func (h *Handler) ListCompanies(w http.ResponseWriter, r *http.Request) { companies, err := h.svc.ListCompanies(r.Context()) if err != nil { @@ -170,7 +168,6 @@ func (h *Handler) ListCompanies(w http.ResponseWriter, r *http.Request) { // @Success 200 {object} domain.Company // @Failure 404 {object} map[string]string // @Router /api/v1/companies/{id} [get] -// @Router /api/v1/companies/{id} [get] func (h *Handler) GetCompany(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -198,7 +195,6 @@ func (h *Handler) GetCompany(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string // @Router /api/v1/companies/{id} [patch] -// @Router /api/v1/companies/{id} [patch] func (h *Handler) UpdateCompany(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -250,7 +246,6 @@ func (h *Handler) UpdateCompany(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string // @Router /api/v1/companies/{id} [delete] -// @Router /api/v1/companies/{id} [delete] func (h *Handler) DeleteCompany(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -356,7 +351,6 @@ func (h *Handler) GetCompanyRating(w http.ResponseWriter, r *http.Request) { // @Param product body registerProductRequest true "Produto" // @Success 201 {object} domain.Product // @Router /api/v1/products [post] -// @Router /api/v1/products [post] func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request) { var req registerProductRequest if err := decodeJSON(r.Context(), r, &req); err != nil { @@ -388,7 +382,6 @@ func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request) { // @Produce json // @Success 200 {array} domain.Product // @Router /api/v1/products [get] -// @Router /api/v1/products [get] func (h *Handler) ListProducts(w http.ResponseWriter, r *http.Request) { products, err := h.svc.ListProducts(r.Context()) if err != nil { @@ -406,7 +399,6 @@ func (h *Handler) ListProducts(w http.ResponseWriter, r *http.Request) { // @Success 200 {object} domain.Product // @Failure 404 {object} map[string]string // @Router /api/v1/products/{id} [get] -// @Router /api/v1/products/{id} [get] func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -434,7 +426,6 @@ func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string // @Router /api/v1/products/{id} [patch] -// @Router /api/v1/products/{id} [patch] func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -492,7 +483,6 @@ func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string // @Router /api/v1/products/{id} [delete] -// @Router /api/v1/products/{id} [delete] func (h *Handler) DeleteProduct(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -578,7 +568,6 @@ func (h *Handler) AdjustInventory(w http.ResponseWriter, r *http.Request) { // @Param order body createOrderRequest true "Pedido" // @Success 201 {object} domain.Order // @Router /api/v1/orders [post] -// @Router /api/v1/orders [post] func (h *Handler) CreateOrder(w http.ResponseWriter, r *http.Request) { var req createOrderRequest if err := decodeJSON(r.Context(), r, &req); err != nil { @@ -614,7 +603,6 @@ func (h *Handler) CreateOrder(w http.ResponseWriter, r *http.Request) { // @Produce json // @Success 200 {array} domain.Order // @Router /api/v1/orders [get] -// @Router /api/v1/orders [get] func (h *Handler) ListOrders(w http.ResponseWriter, r *http.Request) { orders, err := h.svc.ListOrders(r.Context()) if err != nil { @@ -633,7 +621,6 @@ func (h *Handler) ListOrders(w http.ResponseWriter, r *http.Request) { // @Param id path string true "Order ID" // @Success 200 {object} domain.Order // @Router /api/v1/orders/{id} [get] -// @Router /api/v1/orders/{id} [get] func (h *Handler) GetOrder(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -660,7 +647,6 @@ func (h *Handler) GetOrder(w http.ResponseWriter, r *http.Request) { // @Param status body updateStatusRequest true "Novo status" // @Success 204 "" // @Router /api/v1/orders/{id}/status [patch] -// @Router /api/v1/orders/{id}/status [patch] func (h *Handler) UpdateOrderStatus(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -696,7 +682,6 @@ func (h *Handler) UpdateOrderStatus(w http.ResponseWriter, r *http.Request) { // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string // @Router /api/v1/orders/{id} [delete] -// @Router /api/v1/orders/{id} [delete] func (h *Handler) DeleteOrder(w http.ResponseWriter, r *http.Request) { id, err := parseUUIDFromPath(r.URL.Path) if err != nil { @@ -840,7 +825,6 @@ func (h *Handler) DeleteCartItem(w http.ResponseWriter, r *http.Request) { // @Param id path string true "Order ID" // @Success 201 {object} domain.PaymentPreference // @Router /api/v1/orders/{id}/payment [post] -// @Router /api/v1/orders/{id}/payment [post] func (h *Handler) CreatePaymentPreference(w http.ResponseWriter, r *http.Request) { if !strings.HasSuffix(r.URL.Path, "/payment") { http.NotFound(w, r) diff --git a/backend/internal/http/handler/handler_test.go b/backend/internal/http/handler/handler_test.go new file mode 100644 index 0000000..be42db7 --- /dev/null +++ b/backend/internal/http/handler/handler_test.go @@ -0,0 +1,340 @@ +package handler + +import ( + "bytes" + "context" + "errors" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/gofrs/uuid/v5" + "github.com/saveinmed/backend-go/internal/domain" + "github.com/saveinmed/backend-go/internal/usecase" +) + +// MockRepository implements the Repository interface for testing without database +type MockRepository struct { + companies []domain.Company + products []domain.Product + users []domain.User + orders []domain.Order +} + +func NewMockRepository() *MockRepository { + return &MockRepository{ + companies: make([]domain.Company, 0), + products: make([]domain.Product, 0), + users: make([]domain.User, 0), + orders: make([]domain.Order, 0), + } +} + +// Company methods +func (m *MockRepository) CreateCompany(ctx context.Context, company *domain.Company) error { + id, _ := uuid.NewV4() + company.ID = id + company.CreatedAt = time.Now() + company.UpdatedAt = time.Now() + m.companies = append(m.companies, *company) + return nil +} + +func (m *MockRepository) ListCompanies(ctx context.Context) ([]domain.Company, error) { + return m.companies, nil +} + +func (m *MockRepository) GetCompany(ctx context.Context, id uuid.UUID) (*domain.Company, error) { + for _, c := range m.companies { + if c.ID == id { + return &c, nil + } + } + return nil, nil +} + +func (m *MockRepository) UpdateCompany(ctx context.Context, company *domain.Company) error { + for i, c := range m.companies { + if c.ID == company.ID { + m.companies[i] = *company + return nil + } + } + return nil +} + +func (m *MockRepository) DeleteCompany(ctx context.Context, id uuid.UUID) error { + for i, c := range m.companies { + if c.ID == id { + m.companies = append(m.companies[:i], m.companies[i+1:]...) + return nil + } + } + return nil +} + +// Product methods +func (m *MockRepository) CreateProduct(ctx context.Context, product *domain.Product) error { + id, _ := uuid.NewV4() + product.ID = id + product.CreatedAt = time.Now() + product.UpdatedAt = time.Now() + m.products = append(m.products, *product) + return nil +} + +func (m *MockRepository) ListProducts(ctx context.Context) ([]domain.Product, error) { + return m.products, nil +} + +func (m *MockRepository) GetProduct(ctx context.Context, id uuid.UUID) (*domain.Product, error) { + for _, p := range m.products { + if p.ID == id { + return &p, nil + } + } + return nil, nil +} + +func (m *MockRepository) UpdateProduct(ctx context.Context, product *domain.Product) error { + for i, p := range m.products { + if p.ID == product.ID { + m.products[i] = *product + return nil + } + } + return nil +} + +func (m *MockRepository) DeleteProduct(ctx context.Context, id uuid.UUID) error { + for i, p := range m.products { + if p.ID == id { + m.products = append(m.products[:i], m.products[i+1:]...) + return nil + } + } + return nil +} + +// Stub methods for other interfaces +func (m *MockRepository) AdjustInventory(ctx context.Context, productID uuid.UUID, delta int64, reason string) (*domain.InventoryItem, error) { + return &domain.InventoryItem{}, nil +} + +func (m *MockRepository) ListInventory(ctx context.Context, filter domain.InventoryFilter) ([]domain.InventoryItem, error) { + return []domain.InventoryItem{}, nil +} + +func (m *MockRepository) CreateOrder(ctx context.Context, order *domain.Order) error { + id, _ := uuid.NewV4() + order.ID = id + m.orders = append(m.orders, *order) + return nil +} + +func (m *MockRepository) ListOrders(ctx context.Context) ([]domain.Order, error) { + return m.orders, nil +} + +func (m *MockRepository) GetOrder(ctx context.Context, id uuid.UUID) (*domain.Order, error) { + for _, o := range m.orders { + if o.ID == id { + return &o, nil + } + } + return nil, nil +} + +func (m *MockRepository) UpdateOrderStatus(ctx context.Context, id uuid.UUID, status domain.OrderStatus) error { + return nil +} + +func (m *MockRepository) DeleteOrder(ctx context.Context, id uuid.UUID) error { + return nil +} + +func (m *MockRepository) CreateShipment(ctx context.Context, shipment *domain.Shipment) error { + return nil +} + +func (m *MockRepository) GetShipmentByOrderID(ctx context.Context, orderID uuid.UUID) (*domain.Shipment, error) { + return nil, nil +} + +func (m *MockRepository) CreateUser(ctx context.Context, user *domain.User) error { + id, _ := uuid.NewV4() + user.ID = id + m.users = append(m.users, *user) + return nil +} + +func (m *MockRepository) ListUsers(ctx context.Context, filter domain.UserFilter) ([]domain.User, int64, error) { + return m.users, int64(len(m.users)), nil +} + +func (m *MockRepository) GetUser(ctx context.Context, id uuid.UUID) (*domain.User, error) { + for _, u := range m.users { + if u.ID == id { + return &u, nil + } + } + return nil, nil +} + +func (m *MockRepository) GetUserByEmail(ctx context.Context, email string) (*domain.User, error) { + for _, u := range m.users { + if u.Email == email { + return &u, nil + } + } + return nil, errors.New("user not found") // Simulate repository behavior +} + +func (m *MockRepository) UpdateUser(ctx context.Context, user *domain.User) error { + return nil +} + +func (m *MockRepository) DeleteUser(ctx context.Context, id uuid.UUID) error { + return nil +} + +func (m *MockRepository) AddCartItem(ctx context.Context, item *domain.CartItem) (*domain.CartItem, error) { + return item, nil +} + +func (m *MockRepository) ListCartItems(ctx context.Context, buyerID uuid.UUID) ([]domain.CartItem, error) { + return []domain.CartItem{}, nil +} + +func (m *MockRepository) DeleteCartItem(ctx context.Context, id uuid.UUID, buyerID uuid.UUID) error { + return nil +} + +func (m *MockRepository) CreateReview(ctx context.Context, review *domain.Review) error { + return nil +} + +func (m *MockRepository) GetCompanyRating(ctx context.Context, companyID uuid.UUID) (*domain.CompanyRating, error) { + return &domain.CompanyRating{}, nil +} + +func (m *MockRepository) SellerDashboard(ctx context.Context, sellerID uuid.UUID) (*domain.SellerDashboard, error) { + return &domain.SellerDashboard{}, nil +} + +func (m *MockRepository) AdminDashboard(ctx context.Context, since time.Time) (*domain.AdminDashboard, error) { + return &domain.AdminDashboard{}, nil +} + +// MockPaymentGateway implements the PaymentGateway interface for testing +type MockPaymentGateway struct{} + +func (m *MockPaymentGateway) CreatePreference(ctx context.Context, order *domain.Order) (*domain.PaymentPreference, error) { + return &domain.PaymentPreference{}, nil +} + +func (m *MockPaymentGateway) ParseWebhook(ctx context.Context, payload []byte) (*domain.PaymentSplitResult, error) { + return &domain.PaymentSplitResult{}, nil +} + +// Create a test handler for testing +func newTestHandler() *Handler { + repo := NewMockRepository() + gateway := &MockPaymentGateway{} + svc := usecase.NewService(repo, gateway, 0.05, "test-secret", time.Hour, "test-pepper") + return New(svc) +} + +func TestListProducts(t *testing.T) { + h := newTestHandler() + + req := httptest.NewRequest(http.MethodGet, "/api/v1/products", nil) + rec := httptest.NewRecorder() + + h.ListProducts(rec, req) + + if rec.Code != http.StatusOK { + t.Errorf("expected status %d, got %d", http.StatusOK, rec.Code) + } + + // Should return empty array + body := strings.TrimSpace(rec.Body.String()) + if body != "[]" { + t.Errorf("expected empty array, got %s", body) + } +} + +func TestListCompanies(t *testing.T) { + h := newTestHandler() + + req := httptest.NewRequest(http.MethodGet, "/api/v1/companies", nil) + rec := httptest.NewRecorder() + + h.ListCompanies(rec, req) + + if rec.Code != http.StatusOK { + t.Errorf("expected status %d, got %d", http.StatusOK, rec.Code) + } +} + +func TestCreateCompany(t *testing.T) { + h := newTestHandler() + + payload := `{"role":"pharmacy","cnpj":"12345678901234","corporate_name":"Test Pharmacy","license_number":"LIC-001"}` + req := httptest.NewRequest(http.MethodPost, "/api/v1/companies", bytes.NewReader([]byte(payload))) + req.Header.Set("Content-Type", "application/json") + rec := httptest.NewRecorder() + + h.CreateCompany(rec, req) + + if rec.Code != http.StatusCreated { + t.Errorf("expected status %d, got %d: %s", http.StatusCreated, rec.Code, rec.Body.String()) + } +} + +func TestCreateProduct(t *testing.T) { + h := newTestHandler() + + sellerID, _ := uuid.NewV4() + payload := `{"seller_id":"` + sellerID.String() + `","name":"Aspirin","description":"Pain relief","batch":"BATCH-001","expires_at":"2025-12-31T00:00:00Z","price_cents":1000,"stock":100}` + req := httptest.NewRequest(http.MethodPost, "/api/v1/products", bytes.NewReader([]byte(payload))) + req.Header.Set("Content-Type", "application/json") + rec := httptest.NewRecorder() + + h.CreateProduct(rec, req) + + if rec.Code != http.StatusCreated { + t.Errorf("expected status %d, got %d: %s", http.StatusCreated, rec.Code, rec.Body.String()) + } +} + +func TestLoginInvalidCredentials(t *testing.T) { + h := newTestHandler() + + payload := `{"email":"nonexistent@test.com","password":"wrongpassword"}` + req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/login", bytes.NewReader([]byte(payload))) + req.Header.Set("Content-Type", "application/json") + rec := httptest.NewRecorder() + + h.Login(rec, req) + + // Should fail because user doesn't exist + if rec.Code != http.StatusUnauthorized { + t.Errorf("expected status %d, got %d", http.StatusUnauthorized, rec.Code) + } +} + +func TestListOrders(t *testing.T) { + h := newTestHandler() + + req := httptest.NewRequest(http.MethodGet, "/api/v1/orders", nil) + rec := httptest.NewRecorder() + + h.ListOrders(rec, req) + + if rec.Code != http.StatusOK { + t.Errorf("expected status %d, got %d", http.StatusOK, rec.Code) + } +} diff --git a/backend/internal/server/server_test.go b/backend/internal/server/server_test.go new file mode 100644 index 0000000..09ca024 --- /dev/null +++ b/backend/internal/server/server_test.go @@ -0,0 +1,143 @@ +package server + +import ( + "context" + "net/http" + "net/http/httptest" + "os" + "strings" + "testing" + "time" + + _ "github.com/jackc/pgx/v5/stdlib" + "github.com/jmoiron/sqlx" + "github.com/saveinmed/backend-go/internal/config" +) + +// TestServerHealthCheck tests the /health endpoint without a database +func TestServerHealthCheck(t *testing.T) { + // Create a simple handler to test health endpoint + mux := http.NewServeMux() + mux.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ok")) + }) + + req := httptest.NewRequest(http.MethodGet, "/health", nil) + rec := httptest.NewRecorder() + + mux.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Errorf("expected status %d, got %d", http.StatusOK, rec.Code) + } + + if rec.Body.String() != "ok" { + t.Errorf("expected body 'ok', got '%s'", rec.Body.String()) + } +} + +// TestServerRootEndpoint tests the root / endpoint +func TestServerRootEndpoint(t *testing.T) { + mux := http.NewServeMux() + mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + response := `{"message":"💊 SaveInMed API is running!","docs":"/docs/index.html","health":"/health","version":"1.0.0"}` + _, _ = w.Write([]byte(response)) + }) + + req := httptest.NewRequest(http.MethodGet, "/", nil) + rec := httptest.NewRecorder() + + mux.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Errorf("expected status %d, got %d", http.StatusOK, rec.Code) + } + + body := rec.Body.String() + if !strings.Contains(body, "SaveInMed API is running") { + t.Errorf("expected body to contain 'SaveInMed API is running', got '%s'", body) + } +} + +// TestServerCreationWithDatabase tests server creation with a real database +// Skip this test if SKIP_DB_TEST environment variable is set +func TestServerCreationWithDatabase(t *testing.T) { + if os.Getenv("SKIP_DB_TEST") != "" { + t.Skip("Skipping database tests") + } + + // Simple .env loader for testing purposes + if content, err := os.ReadFile("../../.env"); err == nil { + for _, line := range strings.Split(string(content), "\n") { + parts := strings.SplitN(line, "=", 2) + if len(parts) == 2 { + os.Setenv(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])) + } + } + } + + cfg := config.Load() + + srv, err := New(cfg) + if err != nil { + t.Fatalf("Failed to create server: %v", err) + } + + if srv == nil { + t.Fatal("Server should not be nil") + } + + // Clean up + if srv.db != nil { + srv.db.Close() + } +} + +// TestDatabaseConnectionAndPing tests the database connection and ping +func TestDatabaseConnectionAndPing(t *testing.T) { + if os.Getenv("SKIP_DB_TEST") != "" { + t.Skip("Skipping database tests") + } + + // Simple .env loader for testing purposes + if content, err := os.ReadFile("../../.env"); err == nil { + for _, line := range strings.Split(string(content), "\n") { + parts := strings.SplitN(line, "=", 2) + if len(parts) == 2 { + os.Setenv(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])) + } + } + } + + cfg := config.Load() + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + db, err := sqlx.ConnectContext(ctx, "pgx", cfg.DatabaseURL) + if err != nil { + t.Fatalf("Failed to connect to database: %v", err) + } + defer db.Close() + + if err := db.PingContext(ctx); err != nil { + t.Fatalf("Failed to ping database: %v", err) + } + + // Test a simple query + var result int + if err := db.QueryRowContext(ctx, "SELECT 1").Scan(&result); err != nil { + t.Fatalf("Failed to execute query: %v", err) + } + + if result != 1 { + t.Errorf("Expected 1, got %d", result) + } +}