From 69af774d3085129eeeaeca3d06921a21b49c53a7 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Fri, 19 Dec 2025 18:42:38 -0300 Subject: [PATCH] Add v1 prefix to API routes --- backend/docs/docs.go | 16 ++++++------ backend/docs/swagger.json | 16 ++++++------ backend/docs/swagger.yaml | 16 ++++++------ backend/internal/http/handler/handler.go | 32 ++++++++++++------------ backend/internal/server/server.go | 32 ++++++++++++------------ 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index e0707a5..2c51210 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -18,7 +18,7 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/companies": { + "/api/v1/companies": { "get": { "produces": [ "application/json" @@ -72,7 +72,7 @@ const docTemplate = `{ } } }, - "/api/companies/{id}": { + "/api/v1/companies/{id}": { "get": { "produces": [ "application/json" @@ -203,7 +203,7 @@ const docTemplate = `{ } } }, - "/api/orders": { + "/api/v1/orders": { "get": { "security": [ { @@ -261,7 +261,7 @@ const docTemplate = `{ } } }, - "/api/orders/{id}": { + "/api/v1/orders/{id}": { "get": { "security": [ { @@ -337,7 +337,7 @@ const docTemplate = `{ } } }, - "/api/orders/{id}/payment": { + "/api/v1/orders/{id}/payment": { "post": { "security": [ { @@ -370,7 +370,7 @@ const docTemplate = `{ } } }, - "/api/orders/{id}/status": { + "/api/v1/orders/{id}/status": { "patch": { "security": [ { @@ -412,7 +412,7 @@ const docTemplate = `{ } } }, - "/api/products": { + "/api/v1/products": { "get": { "produces": [ "application/json" @@ -465,7 +465,7 @@ const docTemplate = `{ } } }, - "/api/products/{id}": { + "/api/v1/products/{id}": { "get": { "produces": [ "application/json" diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index ca0145e..b72117e 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -14,7 +14,7 @@ }, "basePath": "/", "paths": { - "/api/companies": { + "/api/v1/companies": { "get": { "produces": [ "application/json" @@ -68,7 +68,7 @@ } } }, - "/api/companies/{id}": { + "/api/v1/companies/{id}": { "get": { "produces": [ "application/json" @@ -199,7 +199,7 @@ } } }, - "/api/orders": { + "/api/v1/orders": { "get": { "security": [ { @@ -257,7 +257,7 @@ } } }, - "/api/orders/{id}": { + "/api/v1/orders/{id}": { "get": { "security": [ { @@ -333,7 +333,7 @@ } } }, - "/api/orders/{id}/payment": { + "/api/v1/orders/{id}/payment": { "post": { "security": [ { @@ -366,7 +366,7 @@ } } }, - "/api/orders/{id}/status": { + "/api/v1/orders/{id}/status": { "patch": { "security": [ { @@ -408,7 +408,7 @@ } } }, - "/api/products": { + "/api/v1/products": { "get": { "produces": [ "application/json" @@ -461,7 +461,7 @@ } } }, - "/api/products/{id}": { + "/api/v1/products/{id}": { "get": { "produces": [ "application/json" diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 8cc7888..06bb07c 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -519,7 +519,7 @@ info: title: SaveInMed Performance Core API version: "1.0" paths: - /api/companies: + /api/v1/companies: get: produces: - application/json @@ -555,7 +555,7 @@ paths: summary: Registro de empresas tags: - Empresas - /api/companies/{id}: + /api/v1/companies/{id}: delete: parameters: - description: Company ID @@ -641,7 +641,7 @@ paths: summary: Atualizar empresa tags: - Empresas - /api/orders: + /api/v1/orders: get: produces: - application/json @@ -677,7 +677,7 @@ paths: summary: Criação de pedido com split tags: - Pedidos - /api/orders/{id}: + /api/v1/orders/{id}: delete: parameters: - description: Order ID @@ -724,7 +724,7 @@ paths: summary: Consulta pedido tags: - Pedidos - /api/orders/{id}/payment: + /api/v1/orders/{id}/payment: post: parameters: - description: Order ID @@ -744,7 +744,7 @@ paths: summary: Cria preferência de pagamento Mercado Pago com split nativo tags: - Pagamentos - /api/orders/{id}/status: + /api/v1/orders/{id}/status: patch: consumes: - application/json @@ -770,7 +770,7 @@ paths: summary: Atualiza status do pedido tags: - Pedidos - /api/products: + /api/v1/products: get: produces: - application/json @@ -804,7 +804,7 @@ paths: summary: Cadastro de produto com rastreabilidade de lote tags: - Produtos - /api/products/{id}: + /api/v1/products/{id}: delete: parameters: - description: Product ID diff --git a/backend/internal/http/handler/handler.go b/backend/internal/http/handler/handler.go index 1436eb9..27ec190 100644 --- a/backend/internal/http/handler/handler.go +++ b/backend/internal/http/handler/handler.go @@ -122,7 +122,7 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param company body registerCompanyRequest true "Dados da empresa" // @Success 201 {object} domain.Company -// @Router /api/companies [post] +// @Router /api/v1/companies [post] // @Router /api/v1/companies [post] func (h *Handler) CreateCompany(w http.ResponseWriter, r *http.Request) { var req registerCompanyRequest @@ -151,7 +151,7 @@ func (h *Handler) CreateCompany(w http.ResponseWriter, r *http.Request) { // @Tags Empresas // @Produce json // @Success 200 {array} domain.Company -// @Router /api/companies [get] +// @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()) @@ -169,7 +169,7 @@ func (h *Handler) ListCompanies(w http.ResponseWriter, r *http.Request) { // @Param id path string true "Company ID" // @Success 200 {object} domain.Company // @Failure 404 {object} map[string]string -// @Router /api/companies/{id} [get] +// @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) @@ -197,7 +197,7 @@ func (h *Handler) GetCompany(w http.ResponseWriter, r *http.Request) { // @Success 200 {object} domain.Company // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string -// @Router /api/companies/{id} [patch] +// @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) @@ -249,7 +249,7 @@ func (h *Handler) UpdateCompany(w http.ResponseWriter, r *http.Request) { // @Success 204 "" // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string -// @Router /api/companies/{id} [delete] +// @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) @@ -355,7 +355,7 @@ func (h *Handler) GetCompanyRating(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param product body registerProductRequest true "Produto" // @Success 201 {object} domain.Product -// @Router /api/products [post] +// @Router /api/v1/products [post] // @Router /api/v1/products [post] func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request) { var req registerProductRequest @@ -387,7 +387,7 @@ func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request) { // @Tags Produtos // @Produce json // @Success 200 {array} domain.Product -// @Router /api/products [get] +// @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()) @@ -405,7 +405,7 @@ func (h *Handler) ListProducts(w http.ResponseWriter, r *http.Request) { // @Param id path string true "Product ID" // @Success 200 {object} domain.Product // @Failure 404 {object} map[string]string -// @Router /api/products/{id} [get] +// @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) @@ -433,7 +433,7 @@ func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request) { // @Success 200 {object} domain.Product // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string -// @Router /api/products/{id} [patch] +// @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) @@ -491,7 +491,7 @@ func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request) { // @Success 204 "" // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string -// @Router /api/products/{id} [delete] +// @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) @@ -577,7 +577,7 @@ func (h *Handler) AdjustInventory(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param order body createOrderRequest true "Pedido" // @Success 201 {object} domain.Order -// @Router /api/orders [post] +// @Router /api/v1/orders [post] // @Router /api/v1/orders [post] func (h *Handler) CreateOrder(w http.ResponseWriter, r *http.Request) { var req createOrderRequest @@ -613,7 +613,7 @@ func (h *Handler) CreateOrder(w http.ResponseWriter, r *http.Request) { // @Security BearerAuth // @Produce json // @Success 200 {array} domain.Order -// @Router /api/orders [get] +// @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()) @@ -632,7 +632,7 @@ func (h *Handler) ListOrders(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param id path string true "Order ID" // @Success 200 {object} domain.Order -// @Router /api/orders/{id} [get] +// @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) @@ -659,7 +659,7 @@ func (h *Handler) GetOrder(w http.ResponseWriter, r *http.Request) { // @Param id path string true "Order ID" // @Param status body updateStatusRequest true "Novo status" // @Success 204 "" -// @Router /api/orders/{id}/status [patch] +// @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) @@ -695,7 +695,7 @@ func (h *Handler) UpdateOrderStatus(w http.ResponseWriter, r *http.Request) { // @Success 204 "" // @Failure 400 {object} map[string]string // @Failure 404 {object} map[string]string -// @Router /api/orders/{id} [delete] +// @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) @@ -839,7 +839,7 @@ func (h *Handler) DeleteCartItem(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param id path string true "Order ID" // @Success 201 {object} domain.PaymentPreference -// @Router /api/orders/{id}/payment [post] +// @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") { diff --git a/backend/internal/server/server.go b/backend/internal/server/server.go index 665abb6..3064efd 100644 --- a/backend/internal/server/server.go +++ b/backend/internal/server/server.go @@ -62,11 +62,11 @@ func New(cfg config.Config) (*Server, error) { auth := middleware.RequireAuth([]byte(cfg.JWTSecret)) adminOnly := middleware.RequireAuth([]byte(cfg.JWTSecret), "Admin") - mux.Handle("POST /api/companies", chain(http.HandlerFunc(h.CreateCompany), middleware.Logger, middleware.Gzip)) - mux.Handle("GET /api/companies", chain(http.HandlerFunc(h.ListCompanies), middleware.Logger, middleware.Gzip)) - mux.Handle("GET /api/companies/", chain(http.HandlerFunc(h.GetCompany), middleware.Logger, middleware.Gzip)) - mux.Handle("PATCH /api/companies/", chain(http.HandlerFunc(h.UpdateCompany), middleware.Logger, middleware.Gzip)) - mux.Handle("DELETE /api/companies/", chain(http.HandlerFunc(h.DeleteCompany), middleware.Logger, middleware.Gzip)) + mux.Handle("POST /api/v1/companies", chain(http.HandlerFunc(h.CreateCompany), middleware.Logger, middleware.Gzip)) + mux.Handle("GET /api/v1/companies", chain(http.HandlerFunc(h.ListCompanies), middleware.Logger, middleware.Gzip)) + mux.Handle("GET /api/v1/companies/", chain(http.HandlerFunc(h.GetCompany), middleware.Logger, middleware.Gzip)) + mux.Handle("PATCH /api/v1/companies/", chain(http.HandlerFunc(h.UpdateCompany), middleware.Logger, middleware.Gzip)) + mux.Handle("DELETE /api/v1/companies/", chain(http.HandlerFunc(h.DeleteCompany), middleware.Logger, middleware.Gzip)) mux.Handle("POST /api/v1/companies", chain(http.HandlerFunc(h.CreateCompany), middleware.Logger, middleware.Gzip)) mux.Handle("GET /api/v1/companies", chain(http.HandlerFunc(h.ListCompanies), middleware.Logger, middleware.Gzip)) mux.Handle("GET /api/v1/companies/", chain(http.HandlerFunc(h.GetCompany), middleware.Logger, middleware.Gzip)) @@ -76,11 +76,11 @@ func New(cfg config.Config) (*Server, error) { mux.Handle("GET /api/v1/companies/me", chain(http.HandlerFunc(h.GetMyCompany), middleware.Logger, middleware.Gzip, auth)) mux.Handle("GET /api/v1/companies/", chain(http.HandlerFunc(h.GetCompanyRating), middleware.Logger, middleware.Gzip)) - mux.Handle("POST /api/products", chain(http.HandlerFunc(h.CreateProduct), middleware.Logger, middleware.Gzip)) - mux.Handle("GET /api/products", chain(http.HandlerFunc(h.ListProducts), middleware.Logger, middleware.Gzip)) - mux.Handle("GET /api/products/", chain(http.HandlerFunc(h.GetProduct), middleware.Logger, middleware.Gzip)) - mux.Handle("PATCH /api/products/", chain(http.HandlerFunc(h.UpdateProduct), middleware.Logger, middleware.Gzip)) - mux.Handle("DELETE /api/products/", chain(http.HandlerFunc(h.DeleteProduct), middleware.Logger, middleware.Gzip)) + mux.Handle("POST /api/v1/products", chain(http.HandlerFunc(h.CreateProduct), middleware.Logger, middleware.Gzip)) + mux.Handle("GET /api/v1/products", chain(http.HandlerFunc(h.ListProducts), middleware.Logger, middleware.Gzip)) + mux.Handle("GET /api/v1/products/", chain(http.HandlerFunc(h.GetProduct), middleware.Logger, middleware.Gzip)) + mux.Handle("PATCH /api/v1/products/", chain(http.HandlerFunc(h.UpdateProduct), middleware.Logger, middleware.Gzip)) + mux.Handle("DELETE /api/v1/products/", chain(http.HandlerFunc(h.DeleteProduct), middleware.Logger, middleware.Gzip)) mux.Handle("POST /api/v1/products", chain(http.HandlerFunc(h.CreateProduct), middleware.Logger, middleware.Gzip)) mux.Handle("GET /api/v1/products", chain(http.HandlerFunc(h.ListProducts), middleware.Logger, middleware.Gzip)) mux.Handle("GET /api/v1/products/", chain(http.HandlerFunc(h.GetProduct), middleware.Logger, middleware.Gzip)) @@ -90,12 +90,12 @@ func New(cfg config.Config) (*Server, error) { mux.Handle("GET /api/v1/inventory", chain(http.HandlerFunc(h.ListInventory), middleware.Logger, middleware.Gzip, auth)) mux.Handle("POST /api/v1/inventory/adjust", chain(http.HandlerFunc(h.AdjustInventory), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("POST /api/orders", chain(http.HandlerFunc(h.CreateOrder), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("GET /api/orders", chain(http.HandlerFunc(h.ListOrders), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("GET /api/orders/", chain(http.HandlerFunc(h.GetOrder), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("PATCH /api/orders/", chain(http.HandlerFunc(h.UpdateOrderStatus), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("DELETE /api/orders/", chain(http.HandlerFunc(h.DeleteOrder), middleware.Logger, middleware.Gzip, auth)) - mux.Handle("POST /api/orders/", chain(http.HandlerFunc(h.CreatePaymentPreference), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("POST /api/v1/orders", chain(http.HandlerFunc(h.CreateOrder), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("GET /api/v1/orders", chain(http.HandlerFunc(h.ListOrders), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("GET /api/v1/orders/", chain(http.HandlerFunc(h.GetOrder), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("PATCH /api/v1/orders/", chain(http.HandlerFunc(h.UpdateOrderStatus), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("DELETE /api/v1/orders/", chain(http.HandlerFunc(h.DeleteOrder), middleware.Logger, middleware.Gzip, auth)) + mux.Handle("POST /api/v1/orders/", chain(http.HandlerFunc(h.CreatePaymentPreference), middleware.Logger, middleware.Gzip, auth)) mux.Handle("POST /api/v1/orders", chain(http.HandlerFunc(h.CreateOrder), middleware.Logger, middleware.Gzip, auth)) mux.Handle("GET /api/v1/orders", chain(http.HandlerFunc(h.ListOrders), middleware.Logger, middleware.Gzip, auth)) mux.Handle("GET /api/v1/orders/", chain(http.HandlerFunc(h.GetOrder), middleware.Logger, middleware.Gzip, auth))