diff --git a/app.go b/app.go index 9c06f45..a4bc56a 100755 --- a/app.go +++ b/app.go @@ -3,8 +3,7 @@ package main import ( "context" - _ "online-back/docs" - "online-back/internal/admin/auth" + "online-back/docs" "online-back/internal/config" handlermanager "online-back/internal/handlers/manager" "online-back/pkg/client/postgresql" @@ -15,32 +14,39 @@ import ( ginSwagger "github.com/swaggo/gin-swagger" ) -// @title Service APIs +// @title Service APIs // @version 1.0 // @description Online payment system admin API. -// @termsOfService http://swagger.io/terms/ -// @contact.name API Support -// @contact.url http://www.swagger.io/support -// @contact.email support@swagger.io -// @license.name Apache 2.0 -// @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @host localhost:5050 -// @BasePath /v1/admin +// @BasePath /api/admin // @securityDefinitions.apikey BearerAuth // @in header // @name Authorization -// @tag.name auth -// @tag.name province -// @tag.name location -// @tag.name branches -// @tag.name payment-card -// @tag.name reason-card -// @tag.name loan-type -// @tag.name loan-document -// @Success 200 {object} appresult.AppSuccess "Success Code" -// @Failure 400 {object} appresult.AppError "Error Code" // @schemes http +// @tag.name auth +// @tag.description Authentication +// @tag.name location +// @tag.description Locations +// @tag.name province +// @tag.description Provinces +// @tag.name branches +// @tag.description Branches +// @tag.name payment-card +// @tag.description Payment cards +// @tag.name reason-card +// @tag.description Reason cards +// @tag.name loan-type +// @tag.description Loan types +// @tag.name loan-document +// @tag.description Loan required documents func main() { + docs.SwaggerInfo.Title = "Service APIs" + docs.SwaggerInfo.Version = "1.0" + docs.SwaggerInfo.Description = "Online payment system admin API." + docs.SwaggerInfo.Host = "localhost:5050" + docs.SwaggerInfo.BasePath = "/api/admin" + docs.SwaggerInfo.Schemes = []string{"http"} + cfg := config.GetConfig() logger := logging.GetLogger() @@ -48,7 +54,6 @@ func main() { router := handlermanager.New(cfg, pool, logger) router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - router.GET("/images/:id", auth.GetObject) addr := cfg.Listen.BindIP + ":" + cfg.Listen.Port logger.Infof("starting server on %s", addr) diff --git a/db/migrations/20260702125108_init.down.sql b/db/migrations/20260702125108_init.down.sql index 4ab90af..2dec9d8 100644 --- a/db/migrations/20260702125108_init.down.sql +++ b/db/migrations/20260702125108_init.down.sql @@ -1,8 +1,8 @@ -DROP TABLE IF EXISTS loans_documents; +DROP TABLE IF EXISTS loan_required_documents; DROP TABLE IF EXISTS loan_types; DROP TABLE IF EXISTS reasons_cards; DROP TABLE IF EXISTS payment_cards; DROP TABLE IF EXISTS branches; DROP TABLE IF EXISTS location; -DROP TABLE IF EXISTS province; -DROP TABLE IF EXISTS admin; +DROP TABLE IF EXISTS provinces; +DROP TABLE IF EXISTS users; diff --git a/db/migrations/20260702125108_init.up.sql b/db/migrations/20260702125108_init.up.sql index 880833b..c78629f 100644 --- a/db/migrations/20260702125108_init.up.sql +++ b/db/migrations/20260702125108_init.up.sql @@ -1,6 +1,6 @@ -CREATE TABLE IF NOT EXISTS admin ( +CREATE TABLE IF NOT EXISTS users ( "id" bigserial primary key, - "login" character varying(250) NOT NULL DEFAULT '', + "email" character varying(250) NOT NULL DEFAULT '', "password" character varying(250) NOT NULL DEFAULT '', "fullname" character varying(250) NOT NULL DEFAULT '', "username" character varying(250) NOT NULL DEFAULT '', @@ -14,8 +14,8 @@ CREATE TABLE IF NOT EXISTS admin ( "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); -insert into admin( - phone_number, password, fullname, login, role +insert into users( + phone_number, password, fullname, email, role ) values ( '61531216', '$2a$12$8ZbKmoSwna4CASQptM2/SubwvsBUR1YhABULd.2/QJB.13Wi2v55m', @@ -24,16 +24,17 @@ insert into admin( 'admin' ); -CREATE TABLE IF NOT EXISTS province ( +CREATE TABLE IF NOT EXISTS provinces ( id bigserial PRIMARY KEY, - title json NOT NULL DEFAULT '{}'::json + title json NOT NULL DEFAULT '{}'::json, + status boolean NOT NULL DEFAULT true, "updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, - "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, + "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); CREATE TABLE IF NOT EXISTS location ( id bigserial PRIMARY KEY, - province_id bigint NOT NULL REFERENCES province(id) ON DELETE CASCADE, + province_id bigint NOT NULL REFERENCES provinces(id) ON DELETE CASCADE, title json NOT NULL DEFAULT '{}'::json, status boolean NOT NULL DEFAULT true, "updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, @@ -43,15 +44,18 @@ CREATE TABLE IF NOT EXISTS location ( CREATE TABLE IF NOT EXISTS branches ( id bigserial PRIMARY KEY, title json NOT NULL DEFAULT '{}'::json, - province_id bigint NOT NULL REFERENCES province(id) ON DELETE CASCADE, + province_id bigint NOT NULL REFERENCES provinces(id) ON DELETE CASCADE, location_id bigint NOT NULL REFERENCES location(id) ON DELETE CASCADE, unikal_nomer character varying(250) NOT NULL UNIQUE, - address json NOT NULL DEFAULT '{}'::json, - billing_login character varying(250) NOT NULL DEFAULT '', + "address" text NOT NULL DEFAULT '', + billing_username character varying(250) NOT NULL DEFAULT '', billing_password character varying(250) NOT NULL DEFAULT '', billing_username_sber character varying(250) NOT NULL DEFAULT '', billing_password_sber character varying(250) NOT NULL DEFAULT '', billing_username_visa character varying(250) NOT NULL DEFAULT '', + billing_password_visa character varying(250) NOT NULL DEFAULT '', + billing_username_swift character varying(250) NOT NULL DEFAULT '', + billing_password_swift character varying(250) NOT NULL DEFAULT '', "updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); @@ -85,7 +89,7 @@ CREATE TABLE IF NOT EXISTS loan_types ( updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); -CREATE TABLE IF NOT EXISTS loans_documents ( +CREATE TABLE IF NOT EXISTS loan_required_documents ( id bigserial PRIMARY KEY, title json NOT NULL DEFAULT '{}'::json, content_en text NOT NULL DEFAULT '', diff --git a/docs/docs.go b/docs/docs.go index cabc823..7378276 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -311,30 +311,41 @@ const docTemplate = `{ } } }, - "/file": { - "post": { + "/loan-types": { + "get": { "security": [ { "BearerAuth": [] } ], - "description": "file upload", - "consumes": [ - "multipart/form-data" - ], + "description": "Returns paginated loan types with optional filters", "produces": [ "application/json" ], "tags": [ - "file-upload" + "loan-type" ], + "summary": "List loan types", "parameters": [ { - "type": "file", - "description": "upload file", - "name": "file", - "in": "formData", - "required": true + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "loan_type_name", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" } ], "responses": { @@ -349,18 +360,22 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } - } - }, - "/file/{id}": { - "delete": { + }, + "post": { "security": [ { "BearerAuth": [] } ], - "description": "remove file", + "description": "Creates a new loan type", "consumes": [ "application/json" ], @@ -368,12 +383,61 @@ const docTemplate = `{ "application/json" ], "tags": [ - "file-upload" + "loan-type" ], + "summary": "Create loan type", "parameters": [ { - "type": "string", - "description": "file name", + "description": "Loan type payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loantype.CreateLoanTypeDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loan-types/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single loan type", + "produces": [ + "application/json" + ], + "tags": [ + "loan-type" + ], + "summary": "Get loan type by ID", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", "name": "id", "in": "path", "required": true @@ -391,18 +455,28 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } - } - }, - "/get-profile": { - "get": { + }, + "put": { "security": [ { "BearerAuth": [] } ], - "description": "profile data for Admin", + "description": "Updates an existing loan type", "consumes": [ "application/json" ], @@ -410,7 +484,26 @@ const docTemplate = `{ "application/json" ], "tags": [ - "admin" + "loan-type" + ], + "summary": "Update loan type", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Loan type payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loantype.UpdateLoanTypeDTO" + } + } ], "responses": { "200": { @@ -424,6 +517,410 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a loan type", + "produces": [ + "application/json" + ], + "tags": [ + "loan-type" + ], + "summary": "Delete loan type", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated loan documents with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "List loan documents", + "parameters": [ + { + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "document_name", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by status", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Create loan document", + "parameters": [ + { + "description": "Loan document payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.CreateLoanDocumentDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single loan document", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Get loan document by ID", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Update loan document", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Loan document payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a loan document", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Delete loan document", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents/{id}/status": { + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Enables or disables a loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Update loan document status", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Status payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentStatusDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -719,7 +1216,7 @@ const docTemplate = `{ } }, "/locations/{id}/status": { - "patch": { + "put": { "security": [ { "BearerAuth": [] @@ -784,7 +1281,7 @@ const docTemplate = `{ }, "/login": { "post": { - "description": "login for Admin", + "description": "Authenticates a user by email and password", "consumes": [ "application/json" ], @@ -794,10 +1291,11 @@ const docTemplate = `{ "tags": [ "auth" ], + "summary": "Login", "parameters": [ { - "description": "Login JSON", - "name": "auth", + "description": "Login payload", + "name": "body", "in": "body", "required": true, "schema": { @@ -817,6 +1315,397 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated payment cards with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "List payment cards", + "parameters": [ + { + "type": "string", + "description": "Filter by card title (en, ru, tm)", + "name": "card_name", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by status", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Create payment card", + "parameters": [ + { + "description": "Payment card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.CreatePaymentCardDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single payment card", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Get payment card by ID", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Update payment card", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Payment card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.UpdatePaymentCardDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a payment card", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Delete payment card", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards/{id}/status": { + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Enables or disables a payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Update payment card status", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Status payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.UpdatePaymentCardStatusDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/profile": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns the authenticated user's profile", + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Get profile", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -1071,9 +1960,71 @@ const docTemplate = `{ } } }, - "/token": { + "/reasons-cards": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated reason cards with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "List reason cards", + "parameters": [ + { + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "reason_name", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, "post": { - "description": "refresh admin tokens", + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new reason card", "consumes": [ "application/json" ], @@ -1081,16 +2032,125 @@ const docTemplate = `{ "application/json" ], "tags": [ - "auth" + "reason-card" ], + "summary": "Create reason card", "parameters": [ { - "description": "Token JSON", - "name": "auth", + "description": "Reason card payload", + "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/auth.TokenReqBody" + "$ref": "#/definitions/reasonscard.CreateReasonCardDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/reasons-cards/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single reason card", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Get reason card by ID", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing reason card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Update reason card", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Reason card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/reasonscard.UpdateReasonCardDTO" } } ], @@ -1106,6 +2166,114 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a reason card", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Delete reason card", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/token": { + "post": { + "description": "Issues a new access and refresh token pair", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Refresh tokens", + "parameters": [ + { + "description": "Refresh token payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/auth.RefreshTokenDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -1144,11 +2312,11 @@ const docTemplate = `{ "auth.LoginDTO": { "type": "object", "required": [ - "login", + "email", "password" ], "properties": { - "login": { + "email": { "type": "string" }, "password": { @@ -1156,7 +2324,7 @@ const docTemplate = `{ } } }, - "auth.TokenReqBody": { + "auth.RefreshTokenDTO": { "type": "object", "required": [ "refreshToken" @@ -1180,21 +2348,27 @@ const docTemplate = `{ "address": { "$ref": "#/definitions/branches.LocalizedText" }, - "billingLogin": { - "type": "string" - }, "billingPassword": { "type": "string" }, "billingPasswordSber": { "type": "string" }, + "billingPasswordSwift": { + "type": "string" + }, "billingPasswordVisa": { "type": "string" }, + "billingUsername": { + "type": "string" + }, "billingUsernameSber": { "type": "string" }, + "billingUsernameSwift": { + "type": "string" + }, "billingUsernameVisa": { "type": "string" }, @@ -1239,21 +2413,27 @@ const docTemplate = `{ "address": { "$ref": "#/definitions/branches.LocalizedText" }, - "billingLogin": { - "type": "string" - }, "billingPassword": { "type": "string" }, "billingPasswordSber": { "type": "string" }, + "billingPasswordSwift": { + "type": "string" + }, "billingPasswordVisa": { "type": "string" }, + "billingUsername": { + "type": "string" + }, "billingUsernameSber": { "type": "string" }, + "billingUsernameSwift": { + "type": "string" + }, "billingUsernameVisa": { "type": "string" }, @@ -1271,6 +2451,140 @@ const docTemplate = `{ } } }, + "loansdocument.CreateLoanDocumentDTO": { + "type": "object", + "required": [ + "contentEn", + "contentRu", + "contentTm", + "title" + ], + "properties": { + "contentEn": { + "type": "string" + }, + "contentRu": { + "type": "string" + }, + "contentTm": { + "type": "string" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/loansdocument.LocalizedTitle" + } + } + }, + "loansdocument.LocalizedTitle": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "loansdocument.UpdateLoanDocumentDTO": { + "type": "object", + "required": [ + "contentEn", + "contentRu", + "contentTm", + "title" + ], + "properties": { + "contentEn": { + "type": "string" + }, + "contentRu": { + "type": "string" + }, + "contentTm": { + "type": "string" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/loansdocument.LocalizedTitle" + } + } + }, + "loansdocument.UpdateLoanDocumentStatusDTO": { + "type": "object", + "properties": { + "status": { + "type": "boolean" + } + } + }, + "loantype.CreateLoanTypeDTO": { + "type": "object", + "required": [ + "content", + "loanTerm", + "tax", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/loantype.LocalizedTitle" + }, + "loanTerm": { + "type": "string" + }, + "tax": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/loantype.LocalizedTitle" + } + } + }, + "loantype.LocalizedTitle": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "loantype.UpdateLoanTypeDTO": { + "type": "object", + "required": [ + "content", + "loanTerm", + "tax", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/loantype.LocalizedTitle" + }, + "loanTerm": { + "type": "string" + }, + "tax": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/loantype.LocalizedTitle" + } + } + }, "location.CreateLocationDTO": { "type": "object", "required": [ @@ -1329,12 +2643,81 @@ const docTemplate = `{ } } }, + "paymentcard.CreatePaymentCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/paymentcard.LocalizedText" + }, + "price": { + "type": "number" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/paymentcard.LocalizedText" + } + } + }, + "paymentcard.LocalizedText": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "paymentcard.UpdatePaymentCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/paymentcard.LocalizedText" + }, + "price": { + "type": "number" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/paymentcard.LocalizedText" + } + } + }, + "paymentcard.UpdatePaymentCardStatusDTO": { + "type": "object", + "properties": { + "status": { + "type": "boolean" + } + } + }, "province.CreateProvinceDTO": { "type": "object", "required": [ "title" ], "properties": { + "status": { + "type": "boolean" + }, "title": { "$ref": "#/definitions/province.LocalizedTitle" } @@ -1360,22 +2743,84 @@ const docTemplate = `{ "title" ], "properties": { + "status": { + "type": "boolean" + }, "title": { "$ref": "#/definitions/province.LocalizedTitle" } } + }, + "reasonscard.CreateReasonCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/reasonscard.LocalizedText" + }, + "price": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/reasonscard.LocalizedText" + } + } + }, + "reasonscard.LocalizedText": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "reasonscard.UpdateReasonCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/reasonscard.LocalizedText" + }, + "price": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/reasonscard.LocalizedText" + } + } + } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", + Version: "1.0", + Host: "localhost:5050", + BasePath: "/api/admin", + Schemes: []string{"http"}, + Title: "Service APIs", + Description: "Online payment system admin API.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", @@ -1383,5 +2828,6 @@ var SwaggerInfo = &swag.Spec{ } func init() { + applySwaggerTagOrder() swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) } diff --git a/docs/swagger.json b/docs/swagger.json index 02c7655..8e21233 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,8 +1,13 @@ { "swagger": "2.0", "info": { - "contact": {} + "description": "Online payment system admin API.", + "title": "Service APIs", + "contact": {}, + "version": "1.0" }, + "host": "localhost:5050", + "basePath": "/api/admin", "paths": { "/branches": { "get": { @@ -300,30 +305,41 @@ } } }, - "/file": { - "post": { + "/loan-types": { + "get": { "security": [ { "BearerAuth": [] } ], - "description": "file upload", - "consumes": [ - "multipart/form-data" - ], + "description": "Returns paginated loan types with optional filters", "produces": [ "application/json" ], "tags": [ - "file-upload" + "loan-type" ], + "summary": "List loan types", "parameters": [ { - "type": "file", - "description": "upload file", - "name": "file", - "in": "formData", - "required": true + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "loan_type_name", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" } ], "responses": { @@ -338,18 +354,22 @@ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } - } - }, - "/file/{id}": { - "delete": { + }, + "post": { "security": [ { "BearerAuth": [] } ], - "description": "remove file", + "description": "Creates a new loan type", "consumes": [ "application/json" ], @@ -357,12 +377,61 @@ "application/json" ], "tags": [ - "file-upload" + "loan-type" ], + "summary": "Create loan type", "parameters": [ { - "type": "string", - "description": "file name", + "description": "Loan type payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loantype.CreateLoanTypeDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loan-types/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single loan type", + "produces": [ + "application/json" + ], + "tags": [ + "loan-type" + ], + "summary": "Get loan type by ID", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", "name": "id", "in": "path", "required": true @@ -380,18 +449,28 @@ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } - } - }, - "/get-profile": { - "get": { + }, + "put": { "security": [ { "BearerAuth": [] } ], - "description": "profile data for Admin", + "description": "Updates an existing loan type", "consumes": [ "application/json" ], @@ -399,7 +478,26 @@ "application/json" ], "tags": [ - "admin" + "loan-type" + ], + "summary": "Update loan type", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Loan type payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loantype.UpdateLoanTypeDTO" + } + } ], "responses": { "200": { @@ -413,6 +511,410 @@ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a loan type", + "produces": [ + "application/json" + ], + "tags": [ + "loan-type" + ], + "summary": "Delete loan type", + "parameters": [ + { + "type": "integer", + "description": "Loan type ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated loan documents with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "List loan documents", + "parameters": [ + { + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "document_name", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by status", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Create loan document", + "parameters": [ + { + "description": "Loan document payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.CreateLoanDocumentDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single loan document", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Get loan document by ID", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Update loan document", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Loan document payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a loan document", + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Delete loan document", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/loans-documents/{id}/status": { + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Enables or disables a loan document", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "loan-document" + ], + "summary": "Update loan document status", + "parameters": [ + { + "type": "integer", + "description": "Loan document ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Status payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentStatusDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -708,7 +1210,7 @@ } }, "/locations/{id}/status": { - "patch": { + "put": { "security": [ { "BearerAuth": [] @@ -773,7 +1275,7 @@ }, "/login": { "post": { - "description": "login for Admin", + "description": "Authenticates a user by email and password", "consumes": [ "application/json" ], @@ -783,10 +1285,11 @@ "tags": [ "auth" ], + "summary": "Login", "parameters": [ { - "description": "Login JSON", - "name": "auth", + "description": "Login payload", + "name": "body", "in": "body", "required": true, "schema": { @@ -806,6 +1309,397 @@ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated payment cards with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "List payment cards", + "parameters": [ + { + "type": "string", + "description": "Filter by card title (en, ru, tm)", + "name": "card_name", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by status", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Create payment card", + "parameters": [ + { + "description": "Payment card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.CreatePaymentCardDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single payment card", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Get payment card by ID", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Update payment card", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Payment card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.UpdatePaymentCardDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a payment card", + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Delete payment card", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-cards/{id}/status": { + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Enables or disables a payment card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "payment-card" + ], + "summary": "Update payment card status", + "parameters": [ + { + "type": "integer", + "description": "Payment card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Status payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/paymentcard.UpdatePaymentCardStatusDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/profile": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns the authenticated user's profile", + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Get profile", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -1060,9 +1954,71 @@ } } }, - "/token": { + "/reasons-cards": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns paginated reason cards with optional filters", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "List reason cards", + "parameters": [ + { + "type": "string", + "description": "Filter by title (en, ru, tm)", + "name": "reason_name", + "in": "query" + }, + { + "type": "integer", + "default": 1, + "description": "Page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "Items per page", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, "post": { - "description": "refresh admin tokens", + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Creates a new reason card", "consumes": [ "application/json" ], @@ -1070,16 +2026,125 @@ "application/json" ], "tags": [ - "auth" + "reason-card" ], + "summary": "Create reason card", "parameters": [ { - "description": "Token JSON", - "name": "auth", + "description": "Reason card payload", + "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/auth.TokenReqBody" + "$ref": "#/definitions/reasonscard.CreateReasonCardDTO" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/reasons-cards/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Returns a single reason card", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Get reason card by ID", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Updates an existing reason card", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Update reason card", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Reason card payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/reasonscard.UpdateReasonCardDTO" } } ], @@ -1095,6 +2160,114 @@ "schema": { "$ref": "#/definitions/appresult.AppError" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Deletes a reason card", + "produces": [ + "application/json" + ], + "tags": [ + "reason-card" + ], + "summary": "Delete reason card", + "parameters": [ + { + "type": "integer", + "description": "Reason card ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/token": { + "post": { + "description": "Issues a new access and refresh token pair", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Refresh tokens", + "parameters": [ + { + "description": "Refresh token payload", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/auth.RefreshTokenDTO" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/appresult.AppSuccess" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } } } } @@ -1133,11 +2306,11 @@ "auth.LoginDTO": { "type": "object", "required": [ - "login", + "email", "password" ], "properties": { - "login": { + "email": { "type": "string" }, "password": { @@ -1145,7 +2318,7 @@ } } }, - "auth.TokenReqBody": { + "auth.RefreshTokenDTO": { "type": "object", "required": [ "refreshToken" @@ -1169,21 +2342,27 @@ "address": { "$ref": "#/definitions/branches.LocalizedText" }, - "billingLogin": { - "type": "string" - }, "billingPassword": { "type": "string" }, "billingPasswordSber": { "type": "string" }, + "billingPasswordSwift": { + "type": "string" + }, "billingPasswordVisa": { "type": "string" }, + "billingUsername": { + "type": "string" + }, "billingUsernameSber": { "type": "string" }, + "billingUsernameSwift": { + "type": "string" + }, "billingUsernameVisa": { "type": "string" }, @@ -1228,21 +2407,27 @@ "address": { "$ref": "#/definitions/branches.LocalizedText" }, - "billingLogin": { - "type": "string" - }, "billingPassword": { "type": "string" }, "billingPasswordSber": { "type": "string" }, + "billingPasswordSwift": { + "type": "string" + }, "billingPasswordVisa": { "type": "string" }, + "billingUsername": { + "type": "string" + }, "billingUsernameSber": { "type": "string" }, + "billingUsernameSwift": { + "type": "string" + }, "billingUsernameVisa": { "type": "string" }, @@ -1260,6 +2445,140 @@ } } }, + "loansdocument.CreateLoanDocumentDTO": { + "type": "object", + "required": [ + "contentEn", + "contentRu", + "contentTm", + "title" + ], + "properties": { + "contentEn": { + "type": "string" + }, + "contentRu": { + "type": "string" + }, + "contentTm": { + "type": "string" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/loansdocument.LocalizedTitle" + } + } + }, + "loansdocument.LocalizedTitle": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "loansdocument.UpdateLoanDocumentDTO": { + "type": "object", + "required": [ + "contentEn", + "contentRu", + "contentTm", + "title" + ], + "properties": { + "contentEn": { + "type": "string" + }, + "contentRu": { + "type": "string" + }, + "contentTm": { + "type": "string" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/loansdocument.LocalizedTitle" + } + } + }, + "loansdocument.UpdateLoanDocumentStatusDTO": { + "type": "object", + "properties": { + "status": { + "type": "boolean" + } + } + }, + "loantype.CreateLoanTypeDTO": { + "type": "object", + "required": [ + "content", + "loanTerm", + "tax", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/loantype.LocalizedTitle" + }, + "loanTerm": { + "type": "string" + }, + "tax": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/loantype.LocalizedTitle" + } + } + }, + "loantype.LocalizedTitle": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "loantype.UpdateLoanTypeDTO": { + "type": "object", + "required": [ + "content", + "loanTerm", + "tax", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/loantype.LocalizedTitle" + }, + "loanTerm": { + "type": "string" + }, + "tax": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/loantype.LocalizedTitle" + } + } + }, "location.CreateLocationDTO": { "type": "object", "required": [ @@ -1318,12 +2637,81 @@ } } }, + "paymentcard.CreatePaymentCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/paymentcard.LocalizedText" + }, + "price": { + "type": "number" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/paymentcard.LocalizedText" + } + } + }, + "paymentcard.LocalizedText": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "paymentcard.UpdatePaymentCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/paymentcard.LocalizedText" + }, + "price": { + "type": "number" + }, + "status": { + "type": "boolean" + }, + "title": { + "$ref": "#/definitions/paymentcard.LocalizedText" + } + } + }, + "paymentcard.UpdatePaymentCardStatusDTO": { + "type": "object", + "properties": { + "status": { + "type": "boolean" + } + } + }, "province.CreateProvinceDTO": { "type": "object", "required": [ "title" ], "properties": { + "status": { + "type": "boolean" + }, "title": { "$ref": "#/definitions/province.LocalizedTitle" } @@ -1349,10 +2737,72 @@ "title" ], "properties": { + "status": { + "type": "boolean" + }, "title": { "$ref": "#/definitions/province.LocalizedTitle" } } + }, + "reasonscard.CreateReasonCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/reasonscard.LocalizedText" + }, + "price": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/reasonscard.LocalizedText" + } + } + }, + "reasonscard.LocalizedText": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "tm": { + "type": "string" + } + } + }, + "reasonscard.UpdateReasonCardDTO": { + "type": "object", + "required": [ + "content", + "price", + "title" + ], + "properties": { + "content": { + "$ref": "#/definitions/reasonscard.LocalizedText" + }, + "price": { + "type": "number" + }, + "title": { + "$ref": "#/definitions/reasonscard.LocalizedText" + } + } + } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b1466e6..075b0c5 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,3 +1,4 @@ +basePath: /api/admin definitions: appresult.AppError: properties: @@ -20,15 +21,15 @@ definitions: type: object auth.LoginDTO: properties: - login: + email: type: string password: type: string required: - - login + - email - password type: object - auth.TokenReqBody: + auth.RefreshTokenDTO: properties: refreshToken: type: string @@ -39,16 +40,20 @@ definitions: properties: address: $ref: '#/definitions/branches.LocalizedText' - billingLogin: - type: string billingPassword: type: string billingPasswordSber: type: string + billingPasswordSwift: + type: string billingPasswordVisa: type: string + billingUsername: + type: string billingUsernameSber: type: string + billingUsernameSwift: + type: string billingUsernameVisa: type: string locationId: @@ -79,16 +84,20 @@ definitions: properties: address: $ref: '#/definitions/branches.LocalizedText' - billingLogin: - type: string billingPassword: type: string billingPasswordSber: type: string + billingPasswordSwift: + type: string billingPasswordVisa: type: string + billingUsername: + type: string billingUsernameSber: type: string + billingUsernameSwift: + type: string billingUsernameVisa: type: string locationId: @@ -106,6 +115,97 @@ definitions: - title - unikalNomer type: object + loansdocument.CreateLoanDocumentDTO: + properties: + contentEn: + type: string + contentRu: + type: string + contentTm: + type: string + status: + type: boolean + title: + $ref: '#/definitions/loansdocument.LocalizedTitle' + required: + - contentEn + - contentRu + - contentTm + - title + type: object + loansdocument.LocalizedTitle: + properties: + en: + type: string + ru: + type: string + tm: + type: string + type: object + loansdocument.UpdateLoanDocumentDTO: + properties: + contentEn: + type: string + contentRu: + type: string + contentTm: + type: string + status: + type: boolean + title: + $ref: '#/definitions/loansdocument.LocalizedTitle' + required: + - contentEn + - contentRu + - contentTm + - title + type: object + loansdocument.UpdateLoanDocumentStatusDTO: + properties: + status: + type: boolean + type: object + loantype.CreateLoanTypeDTO: + properties: + content: + $ref: '#/definitions/loantype.LocalizedTitle' + loanTerm: + type: string + tax: + type: number + title: + $ref: '#/definitions/loantype.LocalizedTitle' + required: + - content + - loanTerm + - tax + - title + type: object + loantype.LocalizedTitle: + properties: + en: + type: string + ru: + type: string + tm: + type: string + type: object + loantype.UpdateLoanTypeDTO: + properties: + content: + $ref: '#/definitions/loantype.LocalizedTitle' + loanTerm: + type: string + tax: + type: number + title: + $ref: '#/definitions/loantype.LocalizedTitle' + required: + - content + - loanTerm + - tax + - title + type: object location.CreateLocationDTO: properties: provinceId: @@ -144,8 +244,54 @@ definitions: status: type: boolean type: object + paymentcard.CreatePaymentCardDTO: + properties: + content: + $ref: '#/definitions/paymentcard.LocalizedText' + price: + type: number + status: + type: boolean + title: + $ref: '#/definitions/paymentcard.LocalizedText' + required: + - content + - price + - title + type: object + paymentcard.LocalizedText: + properties: + en: + type: string + ru: + type: string + tm: + type: string + type: object + paymentcard.UpdatePaymentCardDTO: + properties: + content: + $ref: '#/definitions/paymentcard.LocalizedText' + price: + type: number + status: + type: boolean + title: + $ref: '#/definitions/paymentcard.LocalizedText' + required: + - content + - price + - title + type: object + paymentcard.UpdatePaymentCardStatusDTO: + properties: + status: + type: boolean + type: object province.CreateProvinceDTO: properties: + status: + type: boolean title: $ref: '#/definitions/province.LocalizedTitle' required: @@ -162,13 +308,54 @@ definitions: type: object province.UpdateProvinceDTO: properties: + status: + type: boolean title: $ref: '#/definitions/province.LocalizedTitle' required: - title type: object + reasonscard.CreateReasonCardDTO: + properties: + content: + $ref: '#/definitions/reasonscard.LocalizedText' + price: + type: number + title: + $ref: '#/definitions/reasonscard.LocalizedText' + required: + - content + - price + - title + type: object + reasonscard.LocalizedText: + properties: + en: + type: string + ru: + type: string + tm: + type: string + type: object + reasonscard.UpdateReasonCardDTO: + properties: + content: + $ref: '#/definitions/reasonscard.LocalizedText' + price: + type: number + title: + $ref: '#/definitions/reasonscard.LocalizedText' + required: + - content + - price + - title + type: object +host: localhost:5050 info: contact: {} + description: Online payment system admin API. + title: Service APIs + version: "1.0" paths: /branches: get: @@ -360,17 +547,24 @@ paths: summary: Update branch tags: - branches - /file: - post: - consumes: - - multipart/form-data - description: file upload + /loan-types: + get: + description: Returns paginated loan types with optional filters parameters: - - description: upload file - in: formData - name: file - required: true - type: file + - description: Filter by title (en, ru, tm) + in: query + name: loan_type_name + type: string + - default: 1 + description: Page number + in: query + name: page + type: integer + - default: 10 + description: Items per page + in: query + name: limit + type: integer produces: - application/json responses: @@ -382,21 +576,55 @@ paths: description: Bad Request schema: $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' security: - BearerAuth: [] + summary: List loan types tags: - - file-upload - /file/{id}: - delete: + - loan-type + post: consumes: - application/json - description: remove file + description: Creates a new loan type parameters: - - description: file name + - description: Loan type payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/loantype.CreateLoanTypeDTO' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Create loan type + tags: + - loan-type + /loan-types/{id}: + delete: + description: Deletes a loan type + parameters: + - description: Loan type ID in: path name: id required: true - type: string + type: integer produces: - application/json responses: @@ -408,15 +636,67 @@ paths: description: Bad Request schema: $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' security: - BearerAuth: [] + summary: Delete loan type tags: - - file-upload - /get-profile: + - loan-type get: + description: Returns a single loan type + parameters: + - description: Loan type ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Get loan type by ID + tags: + - loan-type + put: consumes: - application/json - description: profile data for Admin + description: Updates an existing loan type + parameters: + - description: Loan type ID + in: path + name: id + required: true + type: integer + - description: Loan type payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/loantype.UpdateLoanTypeDTO' produces: - application/json responses: @@ -428,10 +708,238 @@ paths: description: Bad Request schema: $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' security: - BearerAuth: [] + summary: Update loan type tags: - - admin + - loan-type + /loans-documents: + get: + description: Returns paginated loan documents with optional filters + parameters: + - description: Filter by title (en, ru, tm) + in: query + name: document_name + type: string + - description: Filter by status + in: query + name: status + type: boolean + - default: 1 + description: Page number + in: query + name: page + type: integer + - default: 10 + description: Items per page + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: List loan documents + tags: + - loan-document + post: + consumes: + - application/json + description: Creates a new loan document + parameters: + - description: Loan document payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/loansdocument.CreateLoanDocumentDTO' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Create loan document + tags: + - loan-document + /loans-documents/{id}: + delete: + description: Deletes a loan document + parameters: + - description: Loan document ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Delete loan document + tags: + - loan-document + get: + description: Returns a single loan document + parameters: + - description: Loan document ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Get loan document by ID + tags: + - loan-document + put: + consumes: + - application/json + description: Updates an existing loan document + parameters: + - description: Loan document ID + in: path + name: id + required: true + type: integer + - description: Loan document payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/loansdocument.UpdateLoanDocumentDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Update loan document + tags: + - loan-document + /loans-documents/{id}/status: + put: + consumes: + - application/json + description: Enables or disables a loan document + parameters: + - description: Loan document ID + in: path + name: id + required: true + type: integer + - description: Status payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/loansdocument.UpdateLoanDocumentStatusDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Update loan document status + tags: + - loan-document /locations: get: description: Returns paginated locations with optional filters @@ -619,7 +1127,7 @@ paths: tags: - location /locations/{id}/status: - patch: + put: consumes: - application/json description: Enables or disables a location @@ -663,11 +1171,11 @@ paths: post: consumes: - application/json - description: login for Admin + description: Authenticates a user by email and password parameters: - - description: Login JSON + - description: Login payload in: body - name: auth + name: body required: true schema: $ref: '#/definitions/auth.LoginDTO' @@ -682,6 +1190,257 @@ paths: description: Bad Request schema: $ref: '#/definitions/appresult.AppError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/appresult.AppError' + summary: Login + tags: + - auth + /payment-cards: + get: + description: Returns paginated payment cards with optional filters + parameters: + - description: Filter by card title (en, ru, tm) + in: query + name: card_name + type: string + - description: Filter by status + in: query + name: status + type: boolean + - default: 1 + description: Page number + in: query + name: page + type: integer + - default: 10 + description: Items per page + in: query + name: limit + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: List payment cards + tags: + - payment-card + post: + consumes: + - application/json + description: Creates a new payment card + parameters: + - description: Payment card payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/paymentcard.CreatePaymentCardDTO' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Create payment card + tags: + - payment-card + /payment-cards/{id}: + delete: + description: Deletes a payment card + parameters: + - description: Payment card ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Delete payment card + tags: + - payment-card + get: + description: Returns a single payment card + parameters: + - description: Payment card ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Get payment card by ID + tags: + - payment-card + put: + consumes: + - application/json + description: Updates an existing payment card + parameters: + - description: Payment card ID + in: path + name: id + required: true + type: integer + - description: Payment card payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/paymentcard.UpdatePaymentCardDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Update payment card + tags: + - payment-card + /payment-cards/{id}/status: + put: + consumes: + - application/json + description: Enables or disables a payment card + parameters: + - description: Payment card ID + in: path + name: id + required: true + type: integer + - description: Status payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/paymentcard.UpdatePaymentCardStatusDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Update payment card status + tags: + - payment-card + /profile: + get: + description: Returns the authenticated user's profile + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Get profile tags: - auth /provinces: @@ -843,18 +1602,24 @@ paths: summary: Update province tags: - province - /token: - post: - consumes: - - application/json - description: refresh admin tokens + /reasons-cards: + get: + description: Returns paginated reason cards with optional filters parameters: - - description: Token JSON - in: body - name: auth - required: true - schema: - $ref: '#/definitions/auth.TokenReqBody' + - description: Filter by title (en, ru, tm) + in: query + name: reason_name + type: string + - default: 1 + description: Page number + in: query + name: page + type: integer + - default: 10 + description: Items per page + in: query + name: limit + type: integer produces: - application/json responses: @@ -866,6 +1631,184 @@ paths: description: Bad Request schema: $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: List reason cards + tags: + - reason-card + post: + consumes: + - application/json + description: Creates a new reason card + parameters: + - description: Reason card payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/reasonscard.CreateReasonCardDTO' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Create reason card + tags: + - reason-card + /reasons-cards/{id}: + delete: + description: Deletes a reason card + parameters: + - description: Reason card ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Delete reason card + tags: + - reason-card + get: + description: Returns a single reason card + parameters: + - description: Reason card ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Get reason card by ID + tags: + - reason-card + put: + consumes: + - application/json + description: Updates an existing reason card + parameters: + - description: Reason card ID + in: path + name: id + required: true + type: integer + - description: Reason card payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/reasonscard.UpdateReasonCardDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: Update reason card + tags: + - reason-card + /token: + post: + consumes: + - application/json + description: Issues a new access and refresh token pair + parameters: + - description: Refresh token payload + in: body + name: body + required: true + schema: + $ref: '#/definitions/auth.RefreshTokenDTO' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/appresult.AppSuccess' + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/appresult.AppError' + summary: Refresh tokens tags: - auth +securityDefinitions: + BearerAuth: + in: header + name: Authorization + type: apiKey swagger: "2.0" diff --git a/docs/tag_order.go b/docs/tag_order.go new file mode 100644 index 0000000..3cfc9f5 --- /dev/null +++ b/docs/tag_order.go @@ -0,0 +1,60 @@ +package docs + +import "strings" + +// Swagger tag order for Swagger UI. Listed first appears at the top. +var swaggerTagOrder = []struct { + Name string + Description string +}{ + {Name: "auth", Description: "Authentication"}, + {Name: "location", Description: "Locations"}, + {Name: "province", Description: "Provinces"}, + {Name: "branches", Description: "Branches"}, + {Name: "payment-card", Description: "Payment cards"}, + {Name: "reason-card", Description: "Reason cards"}, + {Name: "loan-type", Description: "Loan types"}, + {Name: "loan-document", Description: "Loan required documents"}, +} + +func applySwaggerTagOrder() { + const anchor = ` }, + "securityDefinitions": {` + if !strings.Contains(SwaggerInfo.SwaggerTemplate, anchor) { + return + } + if strings.Contains(SwaggerInfo.SwaggerTemplate, ` "tags": [ + {"name": "auth"`) { + return + } + + SwaggerInfo.SwaggerTemplate = strings.Replace( + SwaggerInfo.SwaggerTemplate, + anchor, + ` }, + `+buildSwaggerTagsJSON()+`"securityDefinitions": {`, + 1, + ) +} + +func buildSwaggerTagsJSON() string { + var b strings.Builder + b.WriteString(`"tags": [`) + for i, tag := range swaggerTagOrder { + if i > 0 { + b.WriteString(",") + } + b.WriteString(`{"name":`) + b.WriteString(jsonString(tag.Name)) + b.WriteString(`,"description":`) + b.WriteString(jsonString(tag.Description)) + b.WriteString("}") + } + b.WriteString(`], + `) + return b.String() +} + +func jsonString(value string) string { + return `"` + strings.ReplaceAll(value, `"`, `\"`) + `"` +} diff --git a/internal/admin/auth/db/postgresql.go b/internal/admin/auth/db/postgresql.go index 1d8a0e2..ea54701 100755 --- a/internal/admin/auth/db/postgresql.go +++ b/internal/admin/auth/db/postgresql.go @@ -2,7 +2,6 @@ package db import ( "context" - "strconv" "online-back/internal/admin/auth" "online-back/pkg/client/postgresql" @@ -22,32 +21,27 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) auth.Reposi } const ( - loginQuery = `SELECT id, password FROM admin WHERE login = $1` - adminQuery = `SELECT id, password FROM admin WHERE id = $1` + loginQuery = `SELECT id, password FROM users WHERE email = $1` + userByIDQuery = `SELECT id, password FROM users WHERE id = $1` profileQuery = `SELECT id, fullname, phone_number, avatar, created_at - FROM admin WHERE id = $1` + FROM users WHERE id = $1` ) -func (r *repository) Login(ctx context.Context, dto auth.LoginDTO) (auth.ResLoginDTO, error) { - var result auth.ResLoginDTO - err := r.client.QueryRow(ctx, loginQuery, dto.Login).Scan(&result.Id, &result.Password) +func (r *repository) Login(ctx context.Context, dto auth.LoginDTO) (auth.UserCredentials, error) { + var result auth.UserCredentials + err := r.client.QueryRow(ctx, loginQuery, dto.Email).Scan(&result.Id, &result.Password) return result, err } -func (r *repository) CheckAdmin(ctx context.Context, id int) (auth.ResLoginDTO, error) { - var result auth.ResLoginDTO - err := r.client.QueryRow(ctx, adminQuery, id).Scan(&result.Id, &result.Password) +func (r *repository) GetUserByID(ctx context.Context, id int) (auth.UserCredentials, error) { + var result auth.UserCredentials + err := r.client.QueryRow(ctx, userByIDQuery, id).Scan(&result.Id, &result.Password) return result, err } -func (r *repository) GetProfile(ctx context.Context, id string) (auth.ResUserDTO, error) { - var profile auth.ResUserDTO - adminID, err := strconv.Atoi(id) - if err != nil { - return profile, err - } - - err = r.client.QueryRow(ctx, profileQuery, adminID).Scan( +func (r *repository) GetProfile(ctx context.Context, id int) (auth.UserProfileDTO, error) { + var profile auth.UserProfileDTO + err := r.client.QueryRow(ctx, profileQuery, id).Scan( &profile.Id, &profile.FullName, &profile.PhoneNumber, diff --git a/internal/admin/auth/dto.go b/internal/admin/auth/dto.go index bf21cd0..4fbb7c6 100755 --- a/internal/admin/auth/dto.go +++ b/internal/admin/auth/dto.go @@ -3,23 +3,23 @@ package auth import "time" type LoginDTO struct { - Login string `json:"login" binding:"required"` + Email string `json:"email" binding:"required"` Password string `json:"password" binding:"required"` } -type ResLoginDTO struct { - Id int `json:"id"` - Password string `json:"-"` -} - -type TokenReqBody struct { +type RefreshTokenDTO struct { RefreshToken string `json:"refreshToken" binding:"required"` } -type ResUserDTO struct { +type UserProfileDTO struct { Id int `json:"id"` FullName string `json:"fullName"` PhoneNumber string `json:"phoneNumber"` Avatar string `json:"avatar"` CreatedAt time.Time `json:"createdAt"` } + +type UserCredentials struct { + Id int + Password string +} diff --git a/internal/admin/auth/files.go b/internal/admin/auth/files.go deleted file mode 100644 index 547c664..0000000 --- a/internal/admin/auth/files.go +++ /dev/null @@ -1,35 +0,0 @@ -package auth - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "time" -) - -func imageStorageDir(publicRoot string) string { - return filepath.Join(publicRoot, "images") -} - -func imagePublicPath(filename string) string { - return "/images/" + filename -} - -func resolveImagePath(publicRoot, filename string) (string, error) { - if filename == "" || strings.Contains(filename, "..") || strings.ContainsAny(filename, `/\`) { - return "", fmt.Errorf("invalid file name") - } - - base := filepath.Clean(imageStorageDir(publicRoot)) - path := filepath.Clean(filepath.Join(base, filepath.Base(filename))) - if !strings.HasPrefix(path, base+string(os.PathSeparator)) && path != base { - return "", fmt.Errorf("invalid file path") - } - - return path, nil -} - -func newUploadFilename(original string) string { - return fmt.Sprintf("%d%s", time.Now().UnixNano(), filepath.Ext(original)) -} diff --git a/internal/admin/auth/handler.go b/internal/admin/auth/handler.go index a8e82ea..de0278e 100755 --- a/internal/admin/auth/handler.go +++ b/internal/admin/auth/handler.go @@ -1,13 +1,10 @@ package auth import ( - "fmt" "net/http" - "os" - "path/filepath" + "strconv" "online-back/internal/appresult" - "online-back/internal/config" "online-back/internal/handlers" "online-back/pkg/logging" "online-back/pkg/utils" @@ -17,11 +14,9 @@ import ( ) const ( - loginURL = "/login" - tokenURL = "/token" - getProfileURL = "/get-profile" - fileUploadURL = "/file" - fileRemoveURL = "/file/:id" + loginURL = "/login" + tokenURL = "/token" + profileURL = "/profile" ) type handler struct { @@ -30,50 +25,48 @@ type handler struct { } func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler { - return &handler{ - logger: logger, - repository: repository, - } + return &handler{logger: logger, repository: repository} } func (h *handler) Register(router *gin.RouterGroup) { router.POST(loginURL, h.login) - router.POST(tokenURL, h.token) - router.GET(getProfileURL, appresult.JwtTokenCheck(), h.getProfile) - router.POST(fileUploadURL, appresult.JwtTokenCheck(), h.fileUpload) - router.DELETE(fileRemoveURL, appresult.JwtTokenCheck(), h.deleteObject) + router.POST(tokenURL, h.refreshToken) + + protected := router.Group("", appresult.JwtTokenCheck()) + protected.GET(profileURL, h.getProfile) } // login godoc -// @Description login for Admin -// @Tags auth -// @Accept json -// @Produce json -// @Param auth body LoginDTO true "Login JSON" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Router /login [post] +// @Summary Login +// @Description Authenticates a user by email and password +// @Tags auth +// @Accept json +// @Produce json +// @Param body body LoginDTO true "Login payload" +// @Success 200 {object} appresult.AppSuccess +// @Failure 400 {object} appresult.AppError +// @Failure 401 {object} appresult.AppError +// @Router /login [post] func (h *handler) login(c *gin.Context) { - var loginReq LoginDTO - if err := c.ShouldBindJSON(&loginReq); err != nil { + var dto LoginDTO + if err := c.ShouldBindJSON(&dto); err != nil { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - ctx := c.Request.Context() - res, err := h.repository.Login(ctx, loginReq) + user, err := h.repository.Login(c.Request.Context(), dto) if err != nil { h.logger.Errorf("login lookup failed: %v", err) c.JSON(http.StatusUnauthorized, appresult.ErrUnauthorized) return } - if err := bcrypt.CompareHashAndPassword([]byte(res.Password), []byte(loginReq.Password)); err != nil { + if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(dto.Password)); err != nil { c.JSON(http.StatusUnauthorized, appresult.ErrUnauthorized) return } - tokenPair, err := utils.GenerateTokenPair(res.Id) + tokenPair, err := utils.GenerateTokenPair(user.Id) if err != nil { c.JSON(http.StatusBadRequest, appresult.ErrNotAcceptable) return @@ -82,23 +75,25 @@ func (h *handler) login(c *gin.Context) { c.JSON(http.StatusOK, appresult.SuccessWithData(tokenPair)) } -// token godoc -// @Description refresh admin tokens -// @Tags auth -// @Accept json -// @Produce json -// @Param auth body TokenReqBody true "Token JSON" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Router /token [post] -func (h *handler) token(c *gin.Context) { - var tokenReq TokenReqBody - if err := c.ShouldBindJSON(&tokenReq); err != nil { +// refreshToken godoc +// @Summary Refresh tokens +// @Description Issues a new access and refresh token pair +// @Tags auth +// @Accept json +// @Produce json +// @Param body body RefreshTokenDTO true "Refresh token payload" +// @Success 200 {object} appresult.AppSuccess +// @Failure 400 {object} appresult.AppError +// @Failure 401 {object} appresult.AppError +// @Router /token [post] +func (h *handler) refreshToken(c *gin.Context) { + var dto RefreshTokenDTO + if err := c.ShouldBindJSON(&dto); err != nil { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - claims, err := utils.ParseRefreshToken(tokenReq.RefreshToken) + claims, err := utils.ParseRefreshToken(dto.RefreshToken) if err != nil { c.JSON(http.StatusUnauthorized, appresult.ErrUnauthorized) return @@ -110,8 +105,8 @@ func (h *handler) token(c *gin.Context) { return } - admin, err := h.repository.CheckAdmin(c.Request.Context(), id) - if err != nil || admin.Id != id { + user, err := h.repository.GetUserByID(c.Request.Context(), id) + if err != nil || user.Id != id { c.JSON(http.StatusUnauthorized, appresult.ErrUnauthorized) return } @@ -126,100 +121,46 @@ func (h *handler) token(c *gin.Context) { } // getProfile godoc -// @Description profile data for Admin -// @Tags admin -// @Accept json -// @Produce json -// @Security BearerAuth -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Router /get-profile [get] +// @Summary Get profile +// @Description Returns the authenticated user's profile +// @Tags auth +// @Produce json +// @Security BearerAuth +// @Success 200 {object} appresult.AppSuccess +// @Failure 400 {object} appresult.AppError +// @Failure 401 {object} appresult.AppError +// @Failure 404 {object} appresult.AppError +// @Router /profile [get] func (h *handler) getProfile(c *gin.Context) { - adminID, _ := c.Get("id") - profile, err := h.repository.GetProfile(c.Request.Context(), fmt.Sprint(adminID)) + userID, ok := currentUserID(c) + if !ok { + c.JSON(http.StatusUnauthorized, appresult.ErrUnauthorized) + return + } + + profile, err := h.repository.GetProfile(c.Request.Context(), userID) if err != nil { h.logger.Errorf("get profile failed: %v", err) - c.JSON(http.StatusBadRequest, appresult.ErrNotFound) + c.JSON(http.StatusNotFound, appresult.ErrNotFound) return } c.JSON(http.StatusOK, appresult.SuccessWithData(profile)) } -// fileUpload godoc -// @Description file upload -// @Tags file-upload -// @Accept multipart/form-data -// @Produce json -// @Param file formData file true "upload file" -// @Security BearerAuth -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Router /file [post] -func (h *handler) fileUpload(c *gin.Context) { - header, err := c.FormFile("file") - if err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return +func currentUserID(c *gin.Context) (int, bool) { + rawID, exists := c.Get("id") + if !exists { + return 0, false } - cfg := config.GetConfig() - dir := imageStorageDir(cfg.PublicFilePath) - if err := os.MkdirAll(dir, 0755); err != nil { - h.logger.Errorf("create upload dir failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return + switch id := rawID.(type) { + case int: + return id, id > 0 + case string: + parsed, err := strconv.Atoi(id) + return parsed, err == nil && parsed > 0 + default: + return 0, false } - - filename := newUploadFilename(header.Filename) - if err := c.SaveUploadedFile(header, filepath.Join(dir, filename)); err != nil { - h.logger.Errorf("save upload failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData(imagePublicPath(filename))) -} - -// GetObject serves uploaded images from local storage. -func GetObject(c *gin.Context) { - path, err := resolveImagePath(config.GetConfig().PublicFilePath, c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrNotAcceptable) - return - } - - content, err := os.ReadFile(path) - if err != nil { - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } - - c.Data(http.StatusOK, http.DetectContentType(content), content) -} - -// deleteObject godoc -// @Description remove file -// @Tags file-upload -// @Accept json -// @Produce json -// @Param id path string true "file name" -// @Security BearerAuth -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Router /file/{id} [delete] -func (h *handler) deleteObject(c *gin.Context) { - path, err := resolveImagePath(config.GetConfig().PublicFilePath, c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrNotAcceptable) - return - } - - if err := os.Remove(path); err != nil { - h.logger.Errorf("delete file failed: %v", err) - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData("file removed")) } diff --git a/internal/admin/auth/storage.go b/internal/admin/auth/storage.go index a6844c8..433d259 100755 --- a/internal/admin/auth/storage.go +++ b/internal/admin/auth/storage.go @@ -3,7 +3,7 @@ package auth import "context" type Repository interface { - Login(ctx context.Context, dto LoginDTO) (ResLoginDTO, error) - CheckAdmin(ctx context.Context, id int) (ResLoginDTO, error) - GetProfile(ctx context.Context, req string) (ResUserDTO, error) + Login(ctx context.Context, dto LoginDTO) (UserCredentials, error) + GetUserByID(ctx context.Context, id int) (UserCredentials, error) + GetProfile(ctx context.Context, id int) (UserProfileDTO, error) } diff --git a/internal/admin/branches/db/postgresql.go b/internal/admin/branches/db/postgresql.go index 31829bc..738e567 100644 --- a/internal/admin/branches/db/postgresql.go +++ b/internal/admin/branches/db/postgresql.go @@ -25,8 +25,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) branches.Re } const branchColumns = `b.id, b.title, b.province_id, b.location_id, b.unikal_nomer, b.address, - b.billing_login, b.billing_password, b.billing_username_sber, b.billing_password_sber, - b.billing_username_visa, b.billing_password_visa` + b.billing_username, b.billing_password, b.billing_username_sber, b.billing_password_sber, + b.billing_username_visa, b.billing_password_visa, + b.billing_username_swift, b.billing_password_swift` func (r *repository) List(ctx context.Context, filter branches.ListFilter) (branches.ListBranchDTO, error) { fromClause, whereClause, args := buildListQuery(filter) @@ -71,7 +72,7 @@ func buildListQuery(filter branches.ListFilter) (fromClause, whereClause string, fromClause = ` FROM branches b` if filter.ProvinceName != "" { - fromClause += ` JOIN province p ON p.id = b.province_id` + fromClause += ` JOIN provinces p ON p.id = b.province_id` } var conditions []string @@ -145,15 +146,17 @@ func (r *repository) Create(ctx context.Context, dto branches.CreateBranchDTO) ( query := fmt.Sprintf(` INSERT INTO branches ( title, province_id, location_id, unikal_nomer, address, - billing_login, billing_password, billing_username_sber, billing_password_sber, - billing_username_visa, billing_password_visa - ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) + billing_username, billing_password, billing_username_sber, billing_password_sber, + billing_username_visa, billing_password_visa, + billing_username_swift, billing_password_swift + ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13) RETURNING %s`, branchColumns) row := r.client.QueryRow(ctx, query, title, dto.ProvinceId, dto.LocationId, dto.UnikalNomer, address, - dto.BillingLogin, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, + dto.BillingUsername, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, dto.BillingUsernameVisa, dto.BillingPasswordVisa, + dto.BillingUsernameSwift, dto.BillingPasswordSwift, ) item, err := scanBranch(row) if isUniqueViolation(err) { @@ -175,15 +178,17 @@ func (r *repository) Update(ctx context.Context, id int64, dto branches.UpdateBr query := fmt.Sprintf(` UPDATE branches SET title = $1, province_id = $2, location_id = $3, unikal_nomer = $4, address = $5, - billing_login = $6, billing_password = $7, billing_username_sber = $8, - billing_password_sber = $9, billing_username_visa = $10, billing_password_visa = $11 - WHERE id = $12 + billing_username = $6, billing_password = $7, billing_username_sber = $8, + billing_password_sber = $9, billing_username_visa = $10, billing_password_visa = $11, + billing_username_swift = $12, billing_password_swift = $13 + WHERE id = $14 RETURNING %s`, branchColumns) row := r.client.QueryRow(ctx, query, title, dto.ProvinceId, dto.LocationId, dto.UnikalNomer, address, - dto.BillingLogin, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, - dto.BillingUsernameVisa, dto.BillingPasswordVisa, id, + dto.BillingUsername, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, + dto.BillingUsernameVisa, dto.BillingPasswordVisa, + dto.BillingUsernameSwift, dto.BillingPasswordSwift, id, ) item, err := scanBranch(row) if errors.Is(err, pgx.ErrNoRows) { @@ -244,8 +249,9 @@ func scanBranch(row scannable) (branches.BranchDTO, error) { err := row.Scan( &item.Id, &titleJSON, &item.ProvinceId, &item.LocationId, &item.UnikalNomer, &addressJSON, - &item.BillingLogin, &item.BillingPassword, &item.BillingUsernameSber, &item.BillingPasswordSber, + &item.BillingUsername, &item.BillingPassword, &item.BillingUsernameSber, &item.BillingPasswordSber, &item.BillingUsernameVisa, &item.BillingPasswordVisa, + &item.BillingUsernameSwift, &item.BillingPasswordSwift, ) if err != nil { return branches.BranchDTO{}, err diff --git a/internal/admin/branches/dto.go b/internal/admin/branches/dto.go index 3c7fede..94c992e 100644 --- a/internal/admin/branches/dto.go +++ b/internal/admin/branches/dto.go @@ -13,12 +13,14 @@ type BranchDTO struct { LocationId int64 `json:"locationId"` UnikalNomer string `json:"unikalNomer"` Address LocalizedText `json:"address"` - BillingLogin string `json:"billingLogin"` + BillingUsername string `json:"billingUsername"` BillingPassword string `json:"billingPassword"` BillingUsernameSber string `json:"billingUsernameSber"` BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameVisa string `json:"billingUsernameVisa"` + BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameSwift string `json:"billingUsernameSwift"` + BillingPasswordSwift string `json:"billingPasswordSwift"` } type CreateBranchDTO struct { @@ -27,12 +29,14 @@ type CreateBranchDTO struct { LocationId int64 `json:"locationId" binding:"required"` UnikalNomer string `json:"unikalNomer" binding:"required"` Address LocalizedText `json:"address" binding:"required"` - BillingLogin string `json:"billingLogin"` + BillingUsername string `json:"billingUsername"` BillingPassword string `json:"billingPassword"` BillingUsernameSber string `json:"billingUsernameSber"` BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameVisa string `json:"billingUsernameVisa"` + BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameSwift string `json:"billingUsernameSwift"` + BillingPasswordSwift string `json:"billingPasswordSwift"` } type UpdateBranchDTO struct { @@ -41,12 +45,14 @@ type UpdateBranchDTO struct { LocationId int64 `json:"locationId" binding:"required"` UnikalNomer string `json:"unikalNomer" binding:"required"` Address LocalizedText `json:"address" binding:"required"` - BillingLogin string `json:"billingLogin"` + BillingUsername string `json:"billingUsername"` BillingPassword string `json:"billingPassword"` BillingUsernameSber string `json:"billingUsernameSber"` BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameVisa string `json:"billingUsernameVisa"` + BillingPasswordVisa string `json:"billingPasswordVisa"` + BillingUsernameSwift string `json:"billingUsernameSwift"` + BillingPasswordSwift string `json:"billingPasswordSwift"` } type ListFilter struct { diff --git a/internal/admin/loansdocument/db/postgresql.go b/internal/admin/loansdocument/db/postgresql.go index 59ceed3..dfaa63d 100644 --- a/internal/admin/loansdocument/db/postgresql.go +++ b/internal/admin/loansdocument/db/postgresql.go @@ -63,7 +63,7 @@ func (r *repository) List(ctx context.Context, filter loansdocument.ListFilter) } func buildListQuery(filter loansdocument.ListFilter) (fromClause, whereClause string, args []interface{}) { - fromClause = ` FROM loans_documents d` + fromClause = ` FROM loan_required_documents d` var conditions []string @@ -95,7 +95,7 @@ func likePattern(term string) string { } func (r *repository) GetByID(ctx context.Context, id int64) (loansdocument.LoanDocumentDTO, error) { - query := fmt.Sprintf(`SELECT %s FROM loans_documents d WHERE d.id = $1`, documentColumns) + query := fmt.Sprintf(`SELECT %s FROM loan_required_documents d WHERE d.id = $1`, documentColumns) item, err := scanLoanDocument(r.client.QueryRow(ctx, query, id)) if errors.Is(err, pgx.ErrNoRows) { return loansdocument.LoanDocumentDTO{}, err @@ -115,7 +115,7 @@ func (r *repository) Create(ctx context.Context, dto loansdocument.CreateLoanDoc } query := fmt.Sprintf(` - INSERT INTO loans_documents (title, content_en, content_ru, content_tm, status) + INSERT INTO loan_required_documents (title, content_en, content_ru, content_tm, status) VALUES ($1, $2, $3, $4, $5) RETURNING %s`, documentColumns) @@ -129,7 +129,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.Upd } query := fmt.Sprintf(` - UPDATE loans_documents SET + UPDATE loan_required_documents SET title = $1, content_en = $2, content_ru = $3, content_tm = $4, status = $5, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $6 @@ -144,7 +144,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.Upd func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (loansdocument.LoanDocumentDTO, error) { query := fmt.Sprintf(` - UPDATE loans_documents SET + UPDATE loan_required_documents SET status = $1, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $2 @@ -158,7 +158,7 @@ func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (l } func (r *repository) Delete(ctx context.Context, id int64) error { - tag, err := r.client.Exec(ctx, `DELETE FROM loans_documents WHERE id = $1`, id) + tag, err := r.client.Exec(ctx, `DELETE FROM loan_required_documents WHERE id = $1`, id) if err != nil { return err } diff --git a/internal/admin/loansdocument/handler.go b/internal/admin/loansdocument/handler.go index 0e05c3f..21d3184 100644 --- a/internal/admin/loansdocument/handler.go +++ b/internal/admin/loansdocument/handler.go @@ -31,7 +31,7 @@ func (h *handler) Register(router *gin.RouterGroup) { group.GET("/:id", h.getByID) group.POST("", h.create) group.PUT("/:id", h.update) - group.PATCH("/:id/status", h.updateStatus) + group.PUT("/:id/status", h.updateStatus) group.DELETE("/:id", h.delete) } @@ -182,7 +182,7 @@ func (h *handler) update(c *gin.Context) { // @Failure 400 {object} appresult.AppError // @Failure 404 {object} appresult.AppError // @Failure 500 {object} appresult.AppError -// @Router /loans-documents/{id}/status [patch] +// @Router /loans-documents/{id}/status [put] func (h *handler) updateStatus(c *gin.Context) { id, ok := parseID(c.Param("id")) if !ok { diff --git a/internal/admin/location/db/postgresql.go b/internal/admin/location/db/postgresql.go index 02a49c2..015349f 100644 --- a/internal/admin/location/db/postgresql.go +++ b/internal/admin/location/db/postgresql.go @@ -69,7 +69,7 @@ func buildListQuery(filter location.ListFilter) (fromClause, whereClause string, fromClause = ` FROM location l` if filter.ProvinceName != "" { - fromClause += ` JOIN province p ON p.id = l.province_id` + fromClause += ` JOIN provinces p ON p.id = l.province_id` } var conditions []string @@ -197,7 +197,7 @@ func (r *repository) Delete(ctx context.Context, id int64) error { func (r *repository) ensureProvinceExists(ctx context.Context, provinceID int64) error { var id int64 - err := r.client.QueryRow(ctx, `SELECT id FROM province WHERE id = $1`, provinceID).Scan(&id) + err := r.client.QueryRow(ctx, `SELECT id FROM provinces WHERE id = $1`, provinceID).Scan(&id) if errors.Is(err, pgx.ErrNoRows) { return fmt.Errorf("province not found") } diff --git a/internal/admin/location/handler.go b/internal/admin/location/handler.go index c0d88d0..d1628c9 100644 --- a/internal/admin/location/handler.go +++ b/internal/admin/location/handler.go @@ -31,7 +31,7 @@ func (h *handler) Register(router *gin.RouterGroup) { group.GET("/:id", h.getByID) group.POST("", h.create) group.PUT("/:id", h.update) - group.PATCH("/:id/status", h.updateStatus) + group.PUT("/:id/status", h.updateStatus) group.DELETE("/:id", h.delete) } @@ -192,7 +192,7 @@ func (h *handler) update(c *gin.Context) { // @Failure 400 {object} appresult.AppError // @Failure 404 {object} appresult.AppError // @Failure 500 {object} appresult.AppError -// @Router /locations/{id}/status [patch] +// @Router /locations/{id}/status [put] func (h *handler) updateStatus(c *gin.Context) { id, ok := parseID(c.Param("id")) if !ok { diff --git a/internal/admin/paymentcard/handler.go b/internal/admin/paymentcard/handler.go index 48d3a9b..ac76a7f 100644 --- a/internal/admin/paymentcard/handler.go +++ b/internal/admin/paymentcard/handler.go @@ -31,7 +31,7 @@ func (h *handler) Register(router *gin.RouterGroup) { group.GET("/:id", h.getByID) group.POST("", h.create) group.PUT("/:id", h.update) - group.PATCH("/:id/status", h.updateStatus) + group.PUT("/:id/status", h.updateStatus) group.DELETE("/:id", h.delete) } @@ -182,7 +182,7 @@ func (h *handler) update(c *gin.Context) { // @Failure 400 {object} appresult.AppError // @Failure 404 {object} appresult.AppError // @Failure 500 {object} appresult.AppError -// @Router /payment-cards/{id}/status [patch] +// @Router /payment-cards/{id}/status [put] func (h *handler) updateStatus(c *gin.Context) { id, ok := parseID(c.Param("id")) if !ok { diff --git a/internal/admin/province/db/postgresql.go b/internal/admin/province/db/postgresql.go index 198bf6f..2101816 100644 --- a/internal/admin/province/db/postgresql.go +++ b/internal/admin/province/db/postgresql.go @@ -22,7 +22,7 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) province.Re } func (r *repository) List(ctx context.Context) ([]province.ProvinceDTO, error) { - rows, err := r.client.Query(ctx, `SELECT id, title FROM province ORDER BY id`) + rows, err := r.client.Query(ctx, `SELECT id, title, status FROM provinces ORDER BY id`) if err != nil { return nil, err } @@ -41,7 +41,7 @@ func (r *repository) List(ctx context.Context) ([]province.ProvinceDTO, error) { } func (r *repository) GetByID(ctx context.Context, id int64) (province.ProvinceDTO, error) { - row := r.client.QueryRow(ctx, `SELECT id, title FROM province WHERE id = $1`, id) + row := r.client.QueryRow(ctx, `SELECT id, title, status FROM provinces WHERE id = $1`, id) item, err := scanProvince(row) if errors.Is(err, pgx.ErrNoRows) { return province.ProvinceDTO{}, err @@ -55,7 +55,15 @@ func (r *repository) Create(ctx context.Context, dto province.CreateProvinceDTO) return province.ProvinceDTO{}, err } - row := r.client.QueryRow(ctx, `INSERT INTO province (title) VALUES ($1) RETURNING id, title`, title) + status := true + if dto.Status != nil { + status = *dto.Status + } + + row := r.client.QueryRow(ctx, + `INSERT INTO provinces (title, status) VALUES ($1, $2) RETURNING id, title, status`, + title, status, + ) return scanProvince(row) } @@ -66,8 +74,8 @@ func (r *repository) Update(ctx context.Context, id int64, dto province.UpdatePr } row := r.client.QueryRow(ctx, - `UPDATE province SET title = $1 WHERE id = $2 RETURNING id, title`, - title, id, + `UPDATE provinces SET title = $1, status = $2 WHERE id = $3 RETURNING id, title, status`, + title, dto.Status, id, ) item, err := scanProvince(row) if errors.Is(err, pgx.ErrNoRows) { @@ -77,7 +85,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto province.UpdatePr } func (r *repository) Delete(ctx context.Context, id int64) error { - tag, err := r.client.Exec(ctx, `DELETE FROM province WHERE id = $1`, id) + tag, err := r.client.Exec(ctx, `DELETE FROM provinces WHERE id = $1`, id) if err != nil { return err } @@ -94,7 +102,7 @@ type scannable interface { func scanProvince(row scannable) (province.ProvinceDTO, error) { var item province.ProvinceDTO var titleJSON []byte - if err := row.Scan(&item.Id, &titleJSON); err != nil { + if err := row.Scan(&item.Id, &titleJSON, &item.Status); err != nil { return province.ProvinceDTO{}, err } if err := json.Unmarshal(titleJSON, &item.Title); err != nil { diff --git a/internal/admin/province/dto.go b/internal/admin/province/dto.go index 54a8adb..a22dd57 100644 --- a/internal/admin/province/dto.go +++ b/internal/admin/province/dto.go @@ -7,14 +7,17 @@ type LocalizedTitle struct { } type ProvinceDTO struct { - Id int64 `json:"id"` - Title LocalizedTitle `json:"title"` + Id int64 `json:"id"` + Title LocalizedTitle `json:"title"` + Status bool `json:"status"` } type CreateProvinceDTO struct { - Title LocalizedTitle `json:"title" binding:"required"` + Title LocalizedTitle `json:"title" binding:"required"` + Status *bool `json:"status"` } type UpdateProvinceDTO struct { - Title LocalizedTitle `json:"title" binding:"required"` + Title LocalizedTitle `json:"title" binding:"required"` + Status bool `json:"status"` } diff --git a/internal/handlers/manager/manager.go b/internal/handlers/manager/manager.go index 120b006..057e8a7 100755 --- a/internal/handlers/manager/manager.go +++ b/internal/handlers/manager/manager.go @@ -28,7 +28,7 @@ import ( "github.com/jackc/pgx/v4/pgxpool" ) -const adminAPIPrefix = "/v1/admin" +const adminAPIPrefix = "/api/admin" func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.Engine { if cfg.IsDebug != nil && !*cfg.IsDebug { @@ -43,7 +43,6 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin. http.MethodGet, http.MethodPost, http.MethodPut, - http.MethodPatch, http.MethodDelete, }, AllowHeaders: []string{