From 08be61cbcd3451d047fd9c82f3ceedc6f0007c9d Mon Sep 17 00:00:00 2001 From: GuwandykA Date: Mon, 6 Jul 2026 19:13:54 +0500 Subject: [PATCH] changed column name --- README_2.md | 1 + app.go | 2 - config.yaml | 8 +- db/migrations/20260702125108_init.down.sql | 1 - db/migrations/20260702125108_init.up.sql | 48 +- ...706155000_rename_status_to_active.down.sql | 4 + ...60706155000_rename_status_to_active.up.sql | 4 + docs/docs.go | 537 ++---------------- docs/swagger.json | 534 ++--------------- docs/swagger.yaml | 361 ++---------- docs/tag_order.go | 1 - internal/admin/branches/db/postgresql.go | 202 ++++--- internal/admin/branches/dto.go | 90 +-- internal/admin/branches/handler.go | 17 +- internal/admin/loansdocument/db/postgresql.go | 38 +- internal/admin/loansdocument/dto.go | 12 +- internal/admin/loansdocument/handler.go | 26 +- internal/admin/loansdocument/storage.go | 2 +- internal/admin/loantype/db/postgresql.go | 6 +- internal/admin/location/db/postgresql.go | 222 -------- internal/admin/location/dto.go | 44 -- internal/admin/location/handler.go | 315 ---------- internal/admin/location/storage.go | 12 - internal/admin/paymentcard/db/postgresql.go | 38 +- internal/admin/paymentcard/dto.go | 12 +- internal/admin/paymentcard/handler.go | 26 +- internal/admin/paymentcard/storage.go | 2 +- internal/admin/province/db/postgresql.go | 45 +- internal/admin/province/dto.go | 19 +- internal/admin/province/handler.go | 2 +- internal/admin/reasonscard/db/postgresql.go | 6 +- internal/handlers/manager/manager.go | 3 - logs/all.log | 33 ++ 33 files changed, 544 insertions(+), 2129 deletions(-) create mode 100644 db/migrations/20260706155000_rename_status_to_active.down.sql create mode 100644 db/migrations/20260706155000_rename_status_to_active.up.sql delete mode 100644 internal/admin/location/db/postgresql.go delete mode 100644 internal/admin/location/dto.go delete mode 100644 internal/admin/location/handler.go delete mode 100644 internal/admin/location/storage.go diff --git a/README_2.md b/README_2.md index 0cc83fb..7dc25f5 100644 --- a/README_2.md +++ b/README_2.md @@ -377,3 +377,4 @@ Legend used in ASCII diagrams: | 🔑 | Primary key | | 🔗 | Foreign key | | ⭐ | Unique column | + \ No newline at end of file diff --git a/app.go b/app.go index a4bc56a..d77a9dd 100755 --- a/app.go +++ b/app.go @@ -25,8 +25,6 @@ import ( // @schemes http // @tag.name auth // @tag.description Authentication -// @tag.name location -// @tag.description Locations // @tag.name province // @tag.description Provinces // @tag.name branches diff --git a/config.yaml b/config.yaml index 54d9a5e..315f3ee 100755 --- a/config.yaml +++ b/config.yaml @@ -4,10 +4,10 @@ listen: port: 5050 jwt_key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX@VCJ9.yueyJzdWIiOiIyNTEyNzMiLCJpYXQiOjE1MTYy#MzkwMjJ9.o_LoJm03CaE6!0dugdR8sjIuFgPxGT7I2W8NvugFqHRY storage: - host: main-db -# host: localhost - port: 5432 -# port: 5424 + host: localhost +# host: main-db + port: 5424 +# port: 5432 database: bank_db username: bank_admin password: bank@#23#@_password diff --git a/db/migrations/20260702125108_init.down.sql b/db/migrations/20260702125108_init.down.sql index 2dec9d8..51a134e 100644 --- a/db/migrations/20260702125108_init.down.sql +++ b/db/migrations/20260702125108_init.down.sql @@ -3,6 +3,5 @@ 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 provinces; DROP TABLE IF EXISTS users; diff --git a/db/migrations/20260702125108_init.up.sql b/db/migrations/20260702125108_init.up.sql index c78629f..c719d7b 100644 --- a/db/migrations/20260702125108_init.up.sql +++ b/db/migrations/20260702125108_init.up.sql @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS users ( "social_media" json NOT NULL DEFAULT '{}'::json, "light_mode" integer DEFAULT 1 NOT NULL, "role" character varying(250) NOT NULL DEFAULT 'user', - "status" boolean NOT NULL DEFAULT true, + "active" 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 ); @@ -26,36 +26,30 @@ insert into users( CREATE TABLE IF NOT EXISTS provinces ( id bigserial PRIMARY KEY, - title json NOT NULL DEFAULT '{}'::json, - status boolean NOT NULL DEFAULT true, + name json NOT NULL DEFAULT '{}'::json, + region json NOT NULL DEFAULT '{}'::json, + active 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 ); -CREATE TABLE IF NOT EXISTS location ( - id bigserial PRIMARY KEY, - 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, - "created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL -); - CREATE TABLE IF NOT EXISTS branches ( id bigserial PRIMARY KEY, - title json NOT NULL DEFAULT '{}'::json, - 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" 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 '', + unique_code character varying(255) UNIQUE, + name json NOT NULL DEFAULT '{}'::json, + address json NOT NULL DEFAULT '{}'::json, + region character varying(2) NOT NULL DEFAULT '', + province_id bigint REFERENCES provinces(id) ON DELETE SET NULL, + phone_numbers json NOT NULL DEFAULT '[]'::json, + billing_username character varying(255) NOT NULL DEFAULT '', + billing_password character varying(255) NOT NULL DEFAULT '', + billing_swift_username character varying(255) NOT NULL DEFAULT '', + billing_swift_password character varying(255) NOT NULL DEFAULT '', + billing_visa_master_username character varying(255) NOT NULL DEFAULT '', + billing_visa_master_password character varying(255) NOT NULL DEFAULT '', + billing_sber_username character varying(255) NOT NULL DEFAULT '', + billing_sber_password character varying(255) NOT NULL DEFAULT '', + active 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 ); @@ -65,7 +59,7 @@ CREATE TABLE IF NOT EXISTS payment_cards ( price numeric(12, 2) NOT NULL DEFAULT 0, title json NOT NULL DEFAULT '{}'::json, content json NOT NULL DEFAULT '{}'::json, - status boolean NOT NULL DEFAULT true, + active 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 ); @@ -95,7 +89,7 @@ CREATE TABLE IF NOT EXISTS loan_required_documents ( content_en text NOT NULL DEFAULT '', content_ru text NOT NULL DEFAULT '', content_tm text NOT NULL DEFAULT '', - status boolean NOT NULL DEFAULT true, + active boolean NOT NULL DEFAULT true, created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); diff --git a/db/migrations/20260706155000_rename_status_to_active.down.sql b/db/migrations/20260706155000_rename_status_to_active.down.sql new file mode 100644 index 0000000..c8d8b63 --- /dev/null +++ b/db/migrations/20260706155000_rename_status_to_active.down.sql @@ -0,0 +1,4 @@ +ALTER TABLE loan_required_documents RENAME COLUMN active TO status; +ALTER TABLE payment_cards RENAME COLUMN active TO status; +ALTER TABLE provinces RENAME COLUMN active TO status; +ALTER TABLE users RENAME COLUMN active TO status; diff --git a/db/migrations/20260706155000_rename_status_to_active.up.sql b/db/migrations/20260706155000_rename_status_to_active.up.sql new file mode 100644 index 0000000..7e38410 --- /dev/null +++ b/db/migrations/20260706155000_rename_status_to_active.up.sql @@ -0,0 +1,4 @@ +ALTER TABLE users RENAME COLUMN status TO active; +ALTER TABLE provinces RENAME COLUMN status TO active; +ALTER TABLE payment_cards RENAME COLUMN status TO active; +ALTER TABLE loan_required_documents RENAME COLUMN status TO active; diff --git a/docs/docs.go b/docs/docs.go index 7378276..7a83863 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -37,12 +37,6 @@ const docTemplate = `{ "name": "province_id", "in": "query" }, - { - "type": "integer", - "description": "Filter by location ID", - "name": "location_id", - "in": "query" - }, { "type": "string", "description": "Filter by province name (en, ru, tm)", @@ -607,8 +601,8 @@ const docTemplate = `{ }, { "type": "boolean", - "description": "Filter by status", - "name": "status", + "description": "Filter by active", + "name": "active", "in": "query" }, { @@ -861,7 +855,7 @@ const docTemplate = `{ } } }, - "/loans-documents/{id}/status": { + "/loans-documents/{id}/active": { "put": { "security": [ { @@ -878,7 +872,7 @@ const docTemplate = `{ "tags": [ "loan-document" ], - "summary": "Update loan document status", + "summary": "Update loan document active", "parameters": [ { "type": "integer", @@ -888,366 +882,12 @@ const docTemplate = `{ "required": true }, { - "description": "Status payload", + "description": "Active 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" - } - } - } - } - }, - "/locations": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Returns paginated locations with optional filters", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "List locations", - "parameters": [ - { - "type": "integer", - "description": "Filter by province ID", - "name": "province_id", - "in": "query" - }, - { - "type": "string", - "description": "Filter by province name (en, ru, tm)", - "name": "province_name", - "in": "query" - }, - { - "type": "string", - "description": "Filter by location name (en, ru, tm)", - "name": "location_name", - "in": "query" - }, - { - "type": "boolean", - "description": "Filter by location 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 location in a province", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Create location", - "parameters": [ - { - "description": "Location payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.CreateLocationDTO" - } - } - ], - "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" - } - } - } - } - }, - "/locations/{id}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Returns a single location", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Get location by ID", - "parameters": [ - { - "type": "integer", - "description": "Location 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 location", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Update location", - "parameters": [ - { - "type": "integer", - "description": "Location ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Location payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.UpdateLocationDTO" - } - } - ], - "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 location", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Delete location", - "parameters": [ - { - "type": "integer", - "description": "Location 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" - } - } - } - } - }, - "/locations/{id}/status": { - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Enables or disables a location", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Update location status", - "parameters": [ - { - "type": "integer", - "description": "Location ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Status payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.UpdateLocationStatusDTO" + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentActiveDTO" } } ], @@ -1349,8 +989,8 @@ const docTemplate = `{ }, { "type": "boolean", - "description": "Filter by status", - "name": "status", + "description": "Filter by active", + "name": "active", "in": "query" }, { @@ -1603,7 +1243,7 @@ const docTemplate = `{ } } }, - "/payment-cards/{id}/status": { + "/payment-cards/{id}/active": { "put": { "security": [ { @@ -1620,7 +1260,7 @@ const docTemplate = `{ "tags": [ "payment-card" ], - "summary": "Update payment card status", + "summary": "Update payment card active", "parameters": [ { "type": "integer", @@ -1630,12 +1270,12 @@ const docTemplate = `{ "required": true }, { - "description": "Status payload", + "description": "Active payload", "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/paymentcard.UpdatePaymentCardStatusDTO" + "$ref": "#/definitions/paymentcard.UpdatePaymentCardActiveDTO" } } ], @@ -1915,7 +1555,7 @@ const docTemplate = `{ "BearerAuth": [] } ], - "description": "Deletes a province and its locations", + "description": "Deletes a province", "produces": [ "application/json" ], @@ -2339,7 +1979,6 @@ const docTemplate = `{ "type": "object", "required": [ "address", - "locationId", "provinceId", "title", "unikalNomer" @@ -2372,9 +2011,6 @@ const docTemplate = `{ "billingUsernameVisa": { "type": "string" }, - "locationId": { - "type": "integer" - }, "provinceId": { "type": "integer" }, @@ -2404,7 +2040,6 @@ const docTemplate = `{ "type": "object", "required": [ "address", - "locationId", "provinceId", "title", "unikalNomer" @@ -2437,9 +2072,6 @@ const docTemplate = `{ "billingUsernameVisa": { "type": "string" }, - "locationId": { - "type": "integer" - }, "provinceId": { "type": "integer" }, @@ -2460,6 +2092,9 @@ const docTemplate = `{ "title" ], "properties": { + "active": { + "type": "boolean" + }, "contentEn": { "type": "string" }, @@ -2469,9 +2104,6 @@ const docTemplate = `{ "contentTm": { "type": "string" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/loansdocument.LocalizedTitle" } @@ -2491,6 +2123,14 @@ const docTemplate = `{ } } }, + "loansdocument.UpdateLoanDocumentActiveDTO": { + "type": "object", + "properties": { + "active": { + "type": "boolean" + } + } + }, "loansdocument.UpdateLoanDocumentDTO": { "type": "object", "required": [ @@ -2500,6 +2140,9 @@ const docTemplate = `{ "title" ], "properties": { + "active": { + "type": "boolean" + }, "contentEn": { "type": "string" }, @@ -2509,22 +2152,11 @@ const docTemplate = `{ "contentTm": { "type": "string" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/loansdocument.LocalizedTitle" } } }, - "loansdocument.UpdateLoanDocumentStatusDTO": { - "type": "object", - "properties": { - "status": { - "type": "boolean" - } - } - }, "loantype.CreateLoanTypeDTO": { "type": "object", "required": [ @@ -2585,64 +2217,6 @@ const docTemplate = `{ } } }, - "location.CreateLocationDTO": { - "type": "object", - "required": [ - "provinceId", - "title" - ], - "properties": { - "provinceId": { - "type": "integer" - }, - "status": { - "type": "boolean" - }, - "title": { - "$ref": "#/definitions/location.LocalizedTitle" - } - } - }, - "location.LocalizedTitle": { - "type": "object", - "properties": { - "en": { - "type": "string" - }, - "ru": { - "type": "string" - }, - "tm": { - "type": "string" - } - } - }, - "location.UpdateLocationDTO": { - "type": "object", - "required": [ - "provinceId", - "title" - ], - "properties": { - "provinceId": { - "type": "integer" - }, - "status": { - "type": "boolean" - }, - "title": { - "$ref": "#/definitions/location.LocalizedTitle" - } - } - }, - "location.UpdateLocationStatusDTO": { - "type": "object", - "properties": { - "status": { - "type": "boolean" - } - } - }, "paymentcard.CreatePaymentCardDTO": { "type": "object", "required": [ @@ -2651,15 +2225,15 @@ const docTemplate = `{ "title" ], "properties": { + "active": { + "type": "boolean" + }, "content": { "$ref": "#/definitions/paymentcard.LocalizedText" }, "price": { "type": "number" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/paymentcard.LocalizedText" } @@ -2679,6 +2253,14 @@ const docTemplate = `{ } } }, + "paymentcard.UpdatePaymentCardActiveDTO": { + "type": "object", + "properties": { + "active": { + "type": "boolean" + } + } + }, "paymentcard.UpdatePaymentCardDTO": { "type": "object", "required": [ @@ -2687,43 +2269,39 @@ const docTemplate = `{ "title" ], "properties": { + "active": { + "type": "boolean" + }, "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" + "name", + "region" ], "properties": { - "status": { + "active": { "type": "boolean" }, - "title": { - "$ref": "#/definitions/province.LocalizedTitle" + "name": { + "$ref": "#/definitions/province.LocalizedName" + }, + "region": { + "$ref": "#/definitions/province.LocalizedName" } } }, - "province.LocalizedTitle": { + "province.LocalizedName": { "type": "object", "properties": { "en": { @@ -2740,14 +2318,18 @@ const docTemplate = `{ "province.UpdateProvinceDTO": { "type": "object", "required": [ - "title" + "name", + "region" ], "properties": { - "status": { + "active": { "type": "boolean" }, - "title": { - "$ref": "#/definitions/province.LocalizedTitle" + "name": { + "$ref": "#/definitions/province.LocalizedName" + }, + "region": { + "$ref": "#/definitions/province.LocalizedName" } } }, @@ -2818,7 +2400,7 @@ var SwaggerInfo = &swag.Spec{ Version: "1.0", Host: "localhost:5050", BasePath: "/api/admin", - Schemes: []string{"http"}, + Schemes: []string{}, Title: "Service APIs", Description: "Online payment system admin API.", InfoInstanceName: "swagger", @@ -2828,6 +2410,5 @@ var SwaggerInfo = &swag.Spec{ } func init() { - applySwaggerTagOrder() swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) } diff --git a/docs/swagger.json b/docs/swagger.json index 8e21233..e24aeb6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -31,12 +31,6 @@ "name": "province_id", "in": "query" }, - { - "type": "integer", - "description": "Filter by location ID", - "name": "location_id", - "in": "query" - }, { "type": "string", "description": "Filter by province name (en, ru, tm)", @@ -601,8 +595,8 @@ }, { "type": "boolean", - "description": "Filter by status", - "name": "status", + "description": "Filter by active", + "name": "active", "in": "query" }, { @@ -855,7 +849,7 @@ } } }, - "/loans-documents/{id}/status": { + "/loans-documents/{id}/active": { "put": { "security": [ { @@ -872,7 +866,7 @@ "tags": [ "loan-document" ], - "summary": "Update loan document status", + "summary": "Update loan document active", "parameters": [ { "type": "integer", @@ -882,366 +876,12 @@ "required": true }, { - "description": "Status payload", + "description": "Active 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" - } - } - } - } - }, - "/locations": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Returns paginated locations with optional filters", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "List locations", - "parameters": [ - { - "type": "integer", - "description": "Filter by province ID", - "name": "province_id", - "in": "query" - }, - { - "type": "string", - "description": "Filter by province name (en, ru, tm)", - "name": "province_name", - "in": "query" - }, - { - "type": "string", - "description": "Filter by location name (en, ru, tm)", - "name": "location_name", - "in": "query" - }, - { - "type": "boolean", - "description": "Filter by location 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 location in a province", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Create location", - "parameters": [ - { - "description": "Location payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.CreateLocationDTO" - } - } - ], - "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" - } - } - } - } - }, - "/locations/{id}": { - "get": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Returns a single location", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Get location by ID", - "parameters": [ - { - "type": "integer", - "description": "Location 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 location", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Update location", - "parameters": [ - { - "type": "integer", - "description": "Location ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Location payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.UpdateLocationDTO" - } - } - ], - "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 location", - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Delete location", - "parameters": [ - { - "type": "integer", - "description": "Location 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" - } - } - } - } - }, - "/locations/{id}/status": { - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Enables or disables a location", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "location" - ], - "summary": "Update location status", - "parameters": [ - { - "type": "integer", - "description": "Location ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Status payload", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/location.UpdateLocationStatusDTO" + "$ref": "#/definitions/loansdocument.UpdateLoanDocumentActiveDTO" } } ], @@ -1343,8 +983,8 @@ }, { "type": "boolean", - "description": "Filter by status", - "name": "status", + "description": "Filter by active", + "name": "active", "in": "query" }, { @@ -1597,7 +1237,7 @@ } } }, - "/payment-cards/{id}/status": { + "/payment-cards/{id}/active": { "put": { "security": [ { @@ -1614,7 +1254,7 @@ "tags": [ "payment-card" ], - "summary": "Update payment card status", + "summary": "Update payment card active", "parameters": [ { "type": "integer", @@ -1624,12 +1264,12 @@ "required": true }, { - "description": "Status payload", + "description": "Active payload", "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/paymentcard.UpdatePaymentCardStatusDTO" + "$ref": "#/definitions/paymentcard.UpdatePaymentCardActiveDTO" } } ], @@ -1909,7 +1549,7 @@ "BearerAuth": [] } ], - "description": "Deletes a province and its locations", + "description": "Deletes a province", "produces": [ "application/json" ], @@ -2333,7 +1973,6 @@ "type": "object", "required": [ "address", - "locationId", "provinceId", "title", "unikalNomer" @@ -2366,9 +2005,6 @@ "billingUsernameVisa": { "type": "string" }, - "locationId": { - "type": "integer" - }, "provinceId": { "type": "integer" }, @@ -2398,7 +2034,6 @@ "type": "object", "required": [ "address", - "locationId", "provinceId", "title", "unikalNomer" @@ -2431,9 +2066,6 @@ "billingUsernameVisa": { "type": "string" }, - "locationId": { - "type": "integer" - }, "provinceId": { "type": "integer" }, @@ -2454,6 +2086,9 @@ "title" ], "properties": { + "active": { + "type": "boolean" + }, "contentEn": { "type": "string" }, @@ -2463,9 +2098,6 @@ "contentTm": { "type": "string" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/loansdocument.LocalizedTitle" } @@ -2485,6 +2117,14 @@ } } }, + "loansdocument.UpdateLoanDocumentActiveDTO": { + "type": "object", + "properties": { + "active": { + "type": "boolean" + } + } + }, "loansdocument.UpdateLoanDocumentDTO": { "type": "object", "required": [ @@ -2494,6 +2134,9 @@ "title" ], "properties": { + "active": { + "type": "boolean" + }, "contentEn": { "type": "string" }, @@ -2503,22 +2146,11 @@ "contentTm": { "type": "string" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/loansdocument.LocalizedTitle" } } }, - "loansdocument.UpdateLoanDocumentStatusDTO": { - "type": "object", - "properties": { - "status": { - "type": "boolean" - } - } - }, "loantype.CreateLoanTypeDTO": { "type": "object", "required": [ @@ -2579,64 +2211,6 @@ } } }, - "location.CreateLocationDTO": { - "type": "object", - "required": [ - "provinceId", - "title" - ], - "properties": { - "provinceId": { - "type": "integer" - }, - "status": { - "type": "boolean" - }, - "title": { - "$ref": "#/definitions/location.LocalizedTitle" - } - } - }, - "location.LocalizedTitle": { - "type": "object", - "properties": { - "en": { - "type": "string" - }, - "ru": { - "type": "string" - }, - "tm": { - "type": "string" - } - } - }, - "location.UpdateLocationDTO": { - "type": "object", - "required": [ - "provinceId", - "title" - ], - "properties": { - "provinceId": { - "type": "integer" - }, - "status": { - "type": "boolean" - }, - "title": { - "$ref": "#/definitions/location.LocalizedTitle" - } - } - }, - "location.UpdateLocationStatusDTO": { - "type": "object", - "properties": { - "status": { - "type": "boolean" - } - } - }, "paymentcard.CreatePaymentCardDTO": { "type": "object", "required": [ @@ -2645,15 +2219,15 @@ "title" ], "properties": { + "active": { + "type": "boolean" + }, "content": { "$ref": "#/definitions/paymentcard.LocalizedText" }, "price": { "type": "number" }, - "status": { - "type": "boolean" - }, "title": { "$ref": "#/definitions/paymentcard.LocalizedText" } @@ -2673,6 +2247,14 @@ } } }, + "paymentcard.UpdatePaymentCardActiveDTO": { + "type": "object", + "properties": { + "active": { + "type": "boolean" + } + } + }, "paymentcard.UpdatePaymentCardDTO": { "type": "object", "required": [ @@ -2681,43 +2263,39 @@ "title" ], "properties": { + "active": { + "type": "boolean" + }, "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" + "name", + "region" ], "properties": { - "status": { + "active": { "type": "boolean" }, - "title": { - "$ref": "#/definitions/province.LocalizedTitle" + "name": { + "$ref": "#/definitions/province.LocalizedName" + }, + "region": { + "$ref": "#/definitions/province.LocalizedName" } } }, - "province.LocalizedTitle": { + "province.LocalizedName": { "type": "object", "properties": { "en": { @@ -2734,14 +2312,18 @@ "province.UpdateProvinceDTO": { "type": "object", "required": [ - "title" + "name", + "region" ], "properties": { - "status": { + "active": { "type": "boolean" }, - "title": { - "$ref": "#/definitions/province.LocalizedTitle" + "name": { + "$ref": "#/definitions/province.LocalizedName" + }, + "region": { + "$ref": "#/definitions/province.LocalizedName" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 075b0c5..974a95c 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -56,8 +56,6 @@ definitions: type: string billingUsernameVisa: type: string - locationId: - type: integer provinceId: type: integer title: @@ -66,7 +64,6 @@ definitions: type: string required: - address - - locationId - provinceId - title - unikalNomer @@ -100,8 +97,6 @@ definitions: type: string billingUsernameVisa: type: string - locationId: - type: integer provinceId: type: integer title: @@ -110,21 +105,20 @@ definitions: type: string required: - address - - locationId - provinceId - title - unikalNomer type: object loansdocument.CreateLoanDocumentDTO: properties: + active: + type: boolean contentEn: type: string contentRu: type: string contentTm: type: string - status: - type: boolean title: $ref: '#/definitions/loansdocument.LocalizedTitle' required: @@ -142,16 +136,21 @@ definitions: tm: type: string type: object + loansdocument.UpdateLoanDocumentActiveDTO: + properties: + active: + type: boolean + type: object loansdocument.UpdateLoanDocumentDTO: properties: + active: + type: boolean contentEn: type: string contentRu: type: string contentTm: type: string - status: - type: boolean title: $ref: '#/definitions/loansdocument.LocalizedTitle' required: @@ -160,11 +159,6 @@ definitions: - contentTm - title type: object - loansdocument.UpdateLoanDocumentStatusDTO: - properties: - status: - type: boolean - type: object loantype.CreateLoanTypeDTO: properties: content: @@ -206,52 +200,14 @@ definitions: - tax - title type: object - location.CreateLocationDTO: - properties: - provinceId: - type: integer - status: - type: boolean - title: - $ref: '#/definitions/location.LocalizedTitle' - required: - - provinceId - - title - type: object - location.LocalizedTitle: - properties: - en: - type: string - ru: - type: string - tm: - type: string - type: object - location.UpdateLocationDTO: - properties: - provinceId: - type: integer - status: - type: boolean - title: - $ref: '#/definitions/location.LocalizedTitle' - required: - - provinceId - - title - type: object - location.UpdateLocationStatusDTO: - properties: - status: - type: boolean - type: object paymentcard.CreatePaymentCardDTO: properties: + active: + type: boolean content: $ref: '#/definitions/paymentcard.LocalizedText' price: type: number - status: - type: boolean title: $ref: '#/definitions/paymentcard.LocalizedText' required: @@ -268,14 +224,19 @@ definitions: tm: type: string type: object + paymentcard.UpdatePaymentCardActiveDTO: + properties: + active: + type: boolean + type: object paymentcard.UpdatePaymentCardDTO: properties: + active: + type: boolean content: $ref: '#/definitions/paymentcard.LocalizedText' price: type: number - status: - type: boolean title: $ref: '#/definitions/paymentcard.LocalizedText' required: @@ -283,21 +244,19 @@ definitions: - price - title type: object - paymentcard.UpdatePaymentCardStatusDTO: - properties: - status: - type: boolean - type: object province.CreateProvinceDTO: properties: - status: + active: type: boolean - title: - $ref: '#/definitions/province.LocalizedTitle' + name: + $ref: '#/definitions/province.LocalizedName' + region: + $ref: '#/definitions/province.LocalizedName' required: - - title + - name + - region type: object - province.LocalizedTitle: + province.LocalizedName: properties: en: type: string @@ -308,12 +267,15 @@ definitions: type: object province.UpdateProvinceDTO: properties: - status: + active: type: boolean - title: - $ref: '#/definitions/province.LocalizedTitle' + name: + $ref: '#/definitions/province.LocalizedName' + region: + $ref: '#/definitions/province.LocalizedName' required: - - title + - name + - region type: object reasonscard.CreateReasonCardDTO: properties: @@ -365,10 +327,6 @@ paths: in: query name: province_id type: integer - - description: Filter by location ID - in: query - name: location_id - type: integer - description: Filter by province name (en, ru, tm) in: query name: province_name @@ -729,9 +687,9 @@ paths: in: query name: document_name type: string - - description: Filter by status + - description: Filter by active in: query - name: status + name: active type: boolean - default: 1 description: Page number @@ -899,7 +857,7 @@ paths: summary: Update loan document tags: - loan-document - /loans-documents/{id}/status: + /loans-documents/{id}/active: put: consumes: - application/json @@ -910,12 +868,12 @@ paths: name: id required: true type: integer - - description: Status payload + - description: Active payload in: body name: body required: true schema: - $ref: '#/definitions/loansdocument.UpdateLoanDocumentStatusDTO' + $ref: '#/definitions/loansdocument.UpdateLoanDocumentActiveDTO' produces: - application/json responses: @@ -937,236 +895,9 @@ paths: $ref: '#/definitions/appresult.AppError' security: - BearerAuth: [] - summary: Update loan document status + summary: Update loan document active tags: - loan-document - /locations: - get: - description: Returns paginated locations with optional filters - parameters: - - description: Filter by province ID - in: query - name: province_id - type: integer - - description: Filter by province name (en, ru, tm) - in: query - name: province_name - type: string - - description: Filter by location name (en, ru, tm) - in: query - name: location_name - type: string - - description: Filter by location 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 locations - tags: - - location - post: - consumes: - - application/json - description: Creates a new location in a province - parameters: - - description: Location payload - in: body - name: body - required: true - schema: - $ref: '#/definitions/location.CreateLocationDTO' - 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 location - tags: - - location - /locations/{id}: - delete: - description: Deletes a location - parameters: - - description: Location 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 location - tags: - - location - get: - description: Returns a single location - parameters: - - description: Location 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 location by ID - tags: - - location - put: - consumes: - - application/json - description: Updates an existing location - parameters: - - description: Location ID - in: path - name: id - required: true - type: integer - - description: Location payload - in: body - name: body - required: true - schema: - $ref: '#/definitions/location.UpdateLocationDTO' - 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 location - tags: - - location - /locations/{id}/status: - put: - consumes: - - application/json - description: Enables or disables a location - parameters: - - description: Location ID - in: path - name: id - required: true - type: integer - - description: Status payload - in: body - name: body - required: true - schema: - $ref: '#/definitions/location.UpdateLocationStatusDTO' - 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 location status - tags: - - location /login: post: consumes: @@ -1205,9 +936,9 @@ paths: in: query name: card_name type: string - - description: Filter by status + - description: Filter by active in: query - name: status + name: active type: boolean - default: 1 description: Page number @@ -1375,7 +1106,7 @@ paths: summary: Update payment card tags: - payment-card - /payment-cards/{id}/status: + /payment-cards/{id}/active: put: consumes: - application/json @@ -1386,12 +1117,12 @@ paths: name: id required: true type: integer - - description: Status payload + - description: Active payload in: body name: body required: true schema: - $ref: '#/definitions/paymentcard.UpdatePaymentCardStatusDTO' + $ref: '#/definitions/paymentcard.UpdatePaymentCardActiveDTO' produces: - application/json responses: @@ -1413,7 +1144,7 @@ paths: $ref: '#/definitions/appresult.AppError' security: - BearerAuth: [] - summary: Update payment card status + summary: Update payment card active tags: - payment-card /profile: @@ -1499,7 +1230,7 @@ paths: - province /provinces/{id}: delete: - description: Deletes a province and its locations + description: Deletes a province parameters: - description: Province ID in: path diff --git a/docs/tag_order.go b/docs/tag_order.go index 3cfc9f5..7ff3d5c 100644 --- a/docs/tag_order.go +++ b/docs/tag_order.go @@ -8,7 +8,6 @@ var swaggerTagOrder = []struct { Description string }{ {Name: "auth", Description: "Authentication"}, - {Name: "location", Description: "Locations"}, {Name: "province", Description: "Provinces"}, {Name: "branches", Description: "Branches"}, {Name: "payment-card", Description: "Payment cards"}, diff --git a/internal/admin/branches/db/postgresql.go b/internal/admin/branches/db/postgresql.go index 738e567..db91a83 100644 --- a/internal/admin/branches/db/postgresql.go +++ b/internal/admin/branches/db/postgresql.go @@ -24,16 +24,37 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) branches.Re return &repository{client: client, logger: logger} } -const branchColumns = `b.id, b.title, b.province_id, b.location_id, b.unikal_nomer, b.address, - 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` +const branchFromClause = ` FROM branches b + LEFT JOIN provinces p ON p.id = b.province_id` + +const branchSelectColumns = `b.id, b.unique_code, b.name, b.address, b.region, b.province_id, p.name, + b.phone_numbers, b.billing_username, b.billing_password, + b.billing_sber_username, b.billing_sber_password, + b.billing_visa_master_username, b.billing_visa_master_password, + b.billing_swift_username, b.billing_swift_password, b.active` + +const branchReturningColumns = `id, unique_code, name, address, region, province_id, phone_numbers, + billing_username, billing_password, billing_sber_username, billing_sber_password, + billing_visa_master_username, billing_visa_master_password, + billing_swift_username, billing_swift_password, active` + +const branchReturnedSelectColumns = `i.id, i.unique_code, i.name, i.address, i.region, i.province_id, p.name, + i.phone_numbers, i.billing_username, i.billing_password, + i.billing_sber_username, i.billing_sber_password, + i.billing_visa_master_username, i.billing_visa_master_password, + i.billing_swift_username, i.billing_swift_password, i.active` + +const branchUpdatedSelectColumns = `u.id, u.unique_code, u.name, u.address, u.region, u.province_id, p.name, + u.phone_numbers, u.billing_username, u.billing_password, + u.billing_sber_username, u.billing_sber_password, + u.billing_visa_master_username, u.billing_visa_master_password, + u.billing_swift_username, u.billing_swift_password, u.active` func (r *repository) List(ctx context.Context, filter branches.ListFilter) (branches.ListBranchDTO, error) { - fromClause, whereClause, args := buildListQuery(filter) + whereClause, args := buildListQuery(filter) var count int64 - countQuery := `SELECT COUNT(*) ` + fromClause + whereClause + countQuery := `SELECT COUNT(*)` + branchFromClause + whereClause if err := r.client.QueryRow(ctx, countQuery, args...).Scan(&count); err != nil { return branches.ListBranchDTO{}, err } @@ -43,7 +64,7 @@ func (r *repository) List(ctx context.Context, filter branches.ListFilter) (bran offsetPlaceholder := len(args) + 2 listQuery := fmt.Sprintf( `SELECT %s%s%s ORDER BY b.id LIMIT $%d OFFSET $%d`, - branchColumns, fromClause, whereClause, limitPlaceholder, offsetPlaceholder, + branchSelectColumns, branchFromClause, whereClause, limitPlaceholder, offsetPlaceholder, ) listArgs := append(args, filter.Limit, offset) @@ -68,13 +89,7 @@ func (r *repository) List(ctx context.Context, filter branches.ListFilter) (bran return branches.ListBranchDTO{Count: count, Branches: items}, nil } -func buildListQuery(filter branches.ListFilter) (fromClause, whereClause string, args []interface{}) { - fromClause = ` FROM branches b` - - if filter.ProvinceName != "" { - fromClause += ` JOIN provinces p ON p.id = b.province_id` - } - +func buildListQuery(filter branches.ListFilter) (whereClause string, args []interface{}) { var conditions []string if filter.ProvinceID != nil { @@ -82,16 +97,11 @@ func buildListQuery(filter branches.ListFilter) (fromClause, whereClause string, conditions = append(conditions, fmt.Sprintf("b.province_id = $%d", len(args))) } - if filter.LocationID != nil { - args = append(args, *filter.LocationID) - conditions = append(conditions, fmt.Sprintf("b.location_id = $%d", len(args))) - } - if filter.ProvinceName != "" { args = append(args, likePattern(filter.ProvinceName)) n := len(args) conditions = append(conditions, fmt.Sprintf(`( - p.title->>'en' ILIKE $%[1]d OR p.title->>'ru' ILIKE $%[1]d OR p.title->>'tm' ILIKE $%[1]d + p.name->>'en' ILIKE $%[1]d OR p.name->>'ru' ILIKE $%[1]d OR p.name->>'tm' ILIKE $%[1]d )`, n)) } @@ -99,21 +109,21 @@ func buildListQuery(filter branches.ListFilter) (fromClause, whereClause string, args = append(args, likePattern(filter.BranchName)) n := len(args) conditions = append(conditions, fmt.Sprintf(`( - b.title->>'en' ILIKE $%[1]d OR b.title->>'ru' ILIKE $%[1]d OR b.title->>'tm' ILIKE $%[1]d + b.name->>'en' ILIKE $%[1]d OR b.name->>'ru' ILIKE $%[1]d OR b.name->>'tm' ILIKE $%[1]d )`, n)) } - if filter.UnikalNomer != "" { - args = append(args, likePattern(filter.UnikalNomer)) + if filter.UniqueCode != "" { + args = append(args, likePattern(filter.UniqueCode)) n := len(args) - conditions = append(conditions, fmt.Sprintf("b.unikal_nomer ILIKE $%d", n)) + conditions = append(conditions, fmt.Sprintf("b.unique_code ILIKE $%d", n)) } if len(conditions) == 0 { - return fromClause, "", args + return "", args } - return fromClause, " WHERE " + strings.Join(conditions, " AND "), args + return " WHERE " + strings.Join(conditions, " AND "), args } func likePattern(term string) string { @@ -124,7 +134,7 @@ func likePattern(term string) string { } func (r *repository) GetByID(ctx context.Context, id int64) (branches.BranchDTO, error) { - query := fmt.Sprintf(`SELECT %s FROM branches b WHERE b.id = $1`, branchColumns) + query := fmt.Sprintf(`SELECT %s%s WHERE b.id = $1`, branchSelectColumns, branchFromClause) row := r.client.QueryRow(ctx, query, id) item, err := scanBranch(row) if errors.Is(err, pgx.ErrNoRows) { @@ -134,68 +144,84 @@ func (r *repository) GetByID(ctx context.Context, id int64) (branches.BranchDTO, } func (r *repository) Create(ctx context.Context, dto branches.CreateBranchDTO) (branches.BranchDTO, error) { - if err := r.ensureRelations(ctx, dto.ProvinceId, dto.LocationId); err != nil { + if err := r.ensureProvince(ctx, dto.ProvinceId); err != nil { return branches.BranchDTO{}, err } - title, address, err := marshalBranchJSON(dto.Title, dto.Address) + name, address, phoneNumbers, err := marshalBranchJSON(dto.Name, dto.Address, dto.PhoneNumbers) if err != nil { return branches.BranchDTO{}, err } - query := fmt.Sprintf(` - INSERT INTO branches ( - title, province_id, location_id, unikal_nomer, address, - 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) + active := true + if dto.Active != nil { + active = *dto.Active + } + + query := ` + WITH inserted AS ( + INSERT INTO branches ( + unique_code, name, address, region, province_id, phone_numbers, + billing_username, billing_password, billing_sber_username, billing_sber_password, + billing_visa_master_username, billing_visa_master_password, + billing_swift_username, billing_swift_password, active + ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16) + RETURNING ` + branchReturningColumns + ` + ) + SELECT ` + branchReturnedSelectColumns + ` + FROM inserted i + LEFT JOIN provinces p ON p.id = i.province_id` row := r.client.QueryRow(ctx, query, - title, dto.ProvinceId, dto.LocationId, dto.UnikalNomer, address, - dto.BillingUsername, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, - dto.BillingUsernameVisa, dto.BillingPasswordVisa, - dto.BillingUsernameSwift, dto.BillingPasswordSwift, + nullIfEmpty(dto.UniqueCode), name, address, dto.Region, dto.ProvinceId, phoneNumbers, + dto.BillingUsername, dto.BillingPassword, dto.BillingSberUsername, dto.BillingSberPassword, + dto.BillingVisaMasterUsername, dto.BillingVisaMasterPassword, + dto.BillingSwiftUsername, dto.BillingSwiftPassword, active, ) item, err := scanBranch(row) if isUniqueViolation(err) { - return branches.BranchDTO{}, fmt.Errorf("unikal nomer already exists") + return branches.BranchDTO{}, fmt.Errorf("unique code already exists") } return item, err } func (r *repository) Update(ctx context.Context, id int64, dto branches.UpdateBranchDTO) (branches.BranchDTO, error) { - if err := r.ensureRelations(ctx, dto.ProvinceId, dto.LocationId); err != nil { + if err := r.ensureProvince(ctx, dto.ProvinceId); err != nil { return branches.BranchDTO{}, err } - title, address, err := marshalBranchJSON(dto.Title, dto.Address) + name, address, phoneNumbers, err := marshalBranchJSON(dto.Name, dto.Address, dto.PhoneNumbers) if err != nil { return branches.BranchDTO{}, err } - query := fmt.Sprintf(` - UPDATE branches SET - title = $1, province_id = $2, location_id = $3, unikal_nomer = $4, address = $5, - 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) + query := ` + WITH updated AS ( + UPDATE branches SET + unique_code = $1, name = $2, address = $3, region = $4, province_id = $5, + phone_numbers = $6, billing_username = $7, billing_password = $8, + billing_sber_username = $9, billing_sber_password = $10, + billing_visa_master_username = $11, billing_visa_master_password = $12, + billing_swift_username = $13, billing_swift_password = $14, active = $15 + WHERE id = $16 + RETURNING ` + branchReturningColumns + ` + ) + SELECT ` + branchUpdatedSelectColumns + ` + FROM updated u + LEFT JOIN provinces p ON p.id = u.province_id` row := r.client.QueryRow(ctx, query, - title, dto.ProvinceId, dto.LocationId, dto.UnikalNomer, address, - dto.BillingUsername, dto.BillingPassword, dto.BillingUsernameSber, dto.BillingPasswordSber, - dto.BillingUsernameVisa, dto.BillingPasswordVisa, - dto.BillingUsernameSwift, dto.BillingPasswordSwift, id, + nullIfEmpty(dto.UniqueCode), name, address, dto.Region, dto.ProvinceId, phoneNumbers, + dto.BillingUsername, dto.BillingPassword, dto.BillingSberUsername, dto.BillingSberPassword, + dto.BillingVisaMasterUsername, dto.BillingVisaMasterPassword, + dto.BillingSwiftUsername, dto.BillingSwiftPassword, dto.Active, id, ) item, err := scanBranch(row) if errors.Is(err, pgx.ErrNoRows) { return branches.BranchDTO{}, err } if isUniqueViolation(err) { - return branches.BranchDTO{}, fmt.Errorf("unikal nomer already exists") + return branches.BranchDTO{}, fmt.Errorf("unique code already exists") } return item, err } @@ -211,27 +237,44 @@ func (r *repository) Delete(ctx context.Context, id int64) error { return nil } -func (r *repository) ensureRelations(ctx context.Context, provinceID, locationID int64) error { +func (r *repository) ensureProvince(ctx context.Context, provinceID *int64) error { + if provinceID == nil { + return nil + } var id int64 err := r.client.QueryRow(ctx, - `SELECT id FROM location WHERE id = $1 AND province_id = $2`, locationID, provinceID, + `SELECT id FROM provinces WHERE id = $1`, *provinceID, ).Scan(&id) if errors.Is(err, pgx.ErrNoRows) { - return fmt.Errorf("location not found in province") + return fmt.Errorf("province not found") } return err } -func marshalBranchJSON(title, address branches.LocalizedText) ([]byte, []byte, error) { - titleJSON, err := json.Marshal(title) +func marshalBranchJSON(name, address branches.LocalizedText, phoneNumbers []string) ([]byte, []byte, []byte, error) { + nameJSON, err := json.Marshal(name) if err != nil { - return nil, nil, err + return nil, nil, nil, err } addressJSON, err := json.Marshal(address) if err != nil { - return nil, nil, err + return nil, nil, nil, err } - return titleJSON, addressJSON, nil + if phoneNumbers == nil { + phoneNumbers = []string{} + } + phoneNumbersJSON, err := json.Marshal(phoneNumbers) + if err != nil { + return nil, nil, nil, err + } + return nameJSON, addressJSON, phoneNumbersJSON, nil +} + +func nullIfEmpty(value string) interface{} { + if value == "" { + return nil + } + return value } func isUniqueViolation(err error) bool { @@ -245,22 +288,39 @@ type scannable interface { func scanBranch(row scannable) (branches.BranchDTO, error) { var item branches.BranchDTO - var titleJSON, addressJSON []byte + var nameJSON, addressJSON, provinceNameJSON, phoneNumbersJSON []byte + var uniqueCode *string err := row.Scan( - &item.Id, &titleJSON, &item.ProvinceId, &item.LocationId, &item.UnikalNomer, &addressJSON, - &item.BillingUsername, &item.BillingPassword, &item.BillingUsernameSber, &item.BillingPasswordSber, - &item.BillingUsernameVisa, &item.BillingPasswordVisa, - &item.BillingUsernameSwift, &item.BillingPasswordSwift, + &item.Id, &uniqueCode, &nameJSON, &addressJSON, &item.Region, &item.ProvinceId, &provinceNameJSON, + &phoneNumbersJSON, + &item.BillingUsername, &item.BillingPassword, + &item.BillingSberUsername, &item.BillingSberPassword, + &item.BillingVisaMasterUsername, &item.BillingVisaMasterPassword, + &item.BillingSwiftUsername, &item.BillingSwiftPassword, &item.Active, ) if err != nil { return branches.BranchDTO{}, err } - if err := json.Unmarshal(titleJSON, &item.Title); err != nil { + if uniqueCode != nil { + item.UniqueCode = *uniqueCode + } + if err := json.Unmarshal(nameJSON, &item.Name); err != nil { return branches.BranchDTO{}, err } if err := json.Unmarshal(addressJSON, &item.Address); err != nil { return branches.BranchDTO{}, err } + if provinceNameJSON != nil { + if err := json.Unmarshal(provinceNameJSON, &item.ProvinceName); err != nil { + return branches.BranchDTO{}, err + } + } + if err := json.Unmarshal(phoneNumbersJSON, &item.PhoneNumbers); err != nil { + return branches.BranchDTO{}, err + } + if item.PhoneNumbers == nil { + item.PhoneNumbers = []string{} + } return item, nil } diff --git a/internal/admin/branches/dto.go b/internal/admin/branches/dto.go index 94c992e..283f1b5 100644 --- a/internal/admin/branches/dto.go +++ b/internal/admin/branches/dto.go @@ -7,60 +7,66 @@ type LocalizedText struct { } type BranchDTO struct { - Id int64 `json:"id"` - Title LocalizedText `json:"title"` - ProvinceId int64 `json:"provinceId"` - LocationId int64 `json:"locationId"` - UnikalNomer string `json:"unikalNomer"` - Address LocalizedText `json:"address"` - BillingUsername string `json:"billingUsername"` - BillingPassword string `json:"billingPassword"` - BillingUsernameSber string `json:"billingUsernameSber"` - BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` - BillingUsernameSwift string `json:"billingUsernameSwift"` - BillingPasswordSwift string `json:"billingPasswordSwift"` + Id int64 `json:"id"` + UniqueCode string `json:"uniqueCode"` + Name LocalizedText `json:"name"` + Address LocalizedText `json:"address"` + Region string `json:"region"` + ProvinceId *int64 `json:"provinceId"` + ProvinceName LocalizedText `json:"provinceName"` + PhoneNumbers []string `json:"phoneNumbers"` + BillingUsername string `json:"billingUsername"` + BillingPassword string `json:"billingPassword"` + BillingSberUsername string `json:"billingSberUsername"` + BillingSberPassword string `json:"billingSberPassword"` + BillingVisaMasterUsername string `json:"billingVisaMasterUsername"` + BillingVisaMasterPassword string `json:"billingVisaMasterPassword"` + BillingSwiftUsername string `json:"billingSwiftUsername"` + BillingSwiftPassword string `json:"billingSwiftPassword"` + Active bool `json:"active"` } type CreateBranchDTO struct { - Title LocalizedText `json:"title" binding:"required"` - ProvinceId int64 `json:"provinceId" binding:"required"` - LocationId int64 `json:"locationId" binding:"required"` - UnikalNomer string `json:"unikalNomer" binding:"required"` - Address LocalizedText `json:"address" binding:"required"` - BillingUsername string `json:"billingUsername"` - BillingPassword string `json:"billingPassword"` - BillingUsernameSber string `json:"billingUsernameSber"` - BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` - BillingUsernameSwift string `json:"billingUsernameSwift"` - BillingPasswordSwift string `json:"billingPasswordSwift"` + UniqueCode string `json:"uniqueCode"` + Name LocalizedText `json:"name" binding:"required"` + Address LocalizedText `json:"address" binding:"required"` + Region string `json:"region" binding:"required"` + ProvinceId *int64 `json:"provinceId"` + PhoneNumbers []string `json:"phoneNumbers"` + BillingUsername string `json:"billingUsername"` + BillingPassword string `json:"billingPassword"` + BillingSberUsername string `json:"billingSberUsername"` + BillingSberPassword string `json:"billingSberPassword"` + BillingVisaMasterUsername string `json:"billingVisaMasterUsername"` + BillingVisaMasterPassword string `json:"billingVisaMasterPassword"` + BillingSwiftUsername string `json:"billingSwiftUsername"` + BillingSwiftPassword string `json:"billingSwiftPassword"` + Active *bool `json:"active"` } type UpdateBranchDTO struct { - Title LocalizedText `json:"title" binding:"required"` - ProvinceId int64 `json:"provinceId" binding:"required"` - LocationId int64 `json:"locationId" binding:"required"` - UnikalNomer string `json:"unikalNomer" binding:"required"` - Address LocalizedText `json:"address" binding:"required"` - BillingUsername string `json:"billingUsername"` - BillingPassword string `json:"billingPassword"` - BillingUsernameSber string `json:"billingUsernameSber"` - BillingPasswordSber string `json:"billingPasswordSber"` - BillingUsernameVisa string `json:"billingUsernameVisa"` - BillingPasswordVisa string `json:"billingPasswordVisa"` - BillingUsernameSwift string `json:"billingUsernameSwift"` - BillingPasswordSwift string `json:"billingPasswordSwift"` + UniqueCode string `json:"uniqueCode"` + Name LocalizedText `json:"name" binding:"required"` + Address LocalizedText `json:"address" binding:"required"` + Region string `json:"region" binding:"required"` + ProvinceId *int64 `json:"provinceId"` + PhoneNumbers []string `json:"phoneNumbers"` + BillingUsername string `json:"billingUsername"` + BillingPassword string `json:"billingPassword"` + BillingSberUsername string `json:"billingSberUsername"` + BillingSberPassword string `json:"billingSberPassword"` + BillingVisaMasterUsername string `json:"billingVisaMasterUsername"` + BillingVisaMasterPassword string `json:"billingVisaMasterPassword"` + BillingSwiftUsername string `json:"billingSwiftUsername"` + BillingSwiftPassword string `json:"billingSwiftPassword"` + Active bool `json:"active"` } type ListFilter struct { ProvinceID *int64 - LocationID *int64 ProvinceName string BranchName string - UnikalNomer string + UniqueCode string Page int Limit int } diff --git a/internal/admin/branches/handler.go b/internal/admin/branches/handler.go index 95b6d1b..3ca0453 100644 --- a/internal/admin/branches/handler.go +++ b/internal/admin/branches/handler.go @@ -41,10 +41,9 @@ func (h *handler) Register(router *gin.RouterGroup) { // @Produce json // @Security BearerAuth // @Param province_id query int false "Filter by province ID" -// @Param location_id query int false "Filter by location ID" // @Param province_name query string false "Filter by province name (en, ru, tm)" // @Param branch_name query string false "Filter by branch name (en, ru, tm)" -// @Param unikal_nomer query string false "Filter by unique number" +// @Param unique_code query string false "Filter by unique code" // @Param page query int false "Page number" default(1) // @Param limit query int false "Items per page" default(10) // @Success 200 {object} appresult.AppSuccess @@ -212,7 +211,7 @@ func (h *handler) delete(c *gin.Context) { func isClientError(err error) bool { msg := err.Error() - return msg == "location not found in province" || msg == "unikal nomer already exists" + return msg == "province not found" || msg == "unique code already exists" } func parseID(raw string) (int64, bool) { @@ -243,14 +242,6 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) { filter.ProvinceID = &id } - if raw := c.Query("location_id"); raw != "" { - id, ok := parseID(raw) - if !ok { - return ListFilter{}, false - } - filter.LocationID = &id - } - if raw := c.Query("page"); raw != "" { page, err := strconv.Atoi(raw) if err != nil || page < 1 { @@ -275,8 +266,8 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) { filter.BranchName = raw } - if raw := strings.TrimSpace(c.Query("unikal_nomer")); raw != "" { - filter.UnikalNomer = raw + if raw := strings.TrimSpace(c.Query("unique_code")); raw != "" { + filter.UniqueCode = raw } return filter, true diff --git a/internal/admin/loansdocument/db/postgresql.go b/internal/admin/loansdocument/db/postgresql.go index dfaa63d..bb1da7a 100644 --- a/internal/admin/loansdocument/db/postgresql.go +++ b/internal/admin/loansdocument/db/postgresql.go @@ -23,7 +23,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) loansdocume return &repository{client: client, logger: logger} } -const documentColumns = `d.id, d.title, d.content_en, d.content_ru, d.content_tm, d.status, d.created_at, d.updated_at` +const documentColumns = `d.id, d.title, d.content_en, d.content_ru, d.content_tm, d.active, d.created_at, d.updated_at` + +const documentReturningColumns = `id, title, content_en, content_ru, content_tm, active, created_at, updated_at` func (r *repository) List(ctx context.Context, filter loansdocument.ListFilter) (loansdocument.ListLoanDocumentDTO, error) { fromClause, whereClause, args := buildListQuery(filter) @@ -75,9 +77,9 @@ func buildListQuery(filter loansdocument.ListFilter) (fromClause, whereClause st )`, n)) } - if filter.Status != nil { - args = append(args, *filter.Status) - conditions = append(conditions, fmt.Sprintf("d.status = $%d", len(args))) + if filter.Active != nil { + args = append(args, *filter.Active) + conditions = append(conditions, fmt.Sprintf("d.active = $%d", len(args))) } if len(conditions) == 0 { @@ -109,17 +111,17 @@ func (r *repository) Create(ctx context.Context, dto loansdocument.CreateLoanDoc return loansdocument.LoanDocumentDTO{}, err } - status := true - if dto.Status != nil { - status = *dto.Status + active := true + if dto.Active != nil { + active = *dto.Active } query := fmt.Sprintf(` - INSERT INTO loan_required_documents (title, content_en, content_ru, content_tm, status) + INSERT INTO loan_required_documents (title, content_en, content_ru, content_tm, active) VALUES ($1, $2, $3, $4, $5) - RETURNING %s`, documentColumns) + RETURNING %s`, documentReturningColumns) - return scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, status)) + return scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, active)) } func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.UpdateLoanDocumentDTO) (loansdocument.LoanDocumentDTO, error) { @@ -130,27 +132,27 @@ func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.Upd query := fmt.Sprintf(` UPDATE loan_required_documents SET - title = $1, content_en = $2, content_ru = $3, content_tm = $4, status = $5, + title = $1, content_en = $2, content_ru = $3, content_tm = $4, active = $5, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $6 - RETURNING %s`, documentColumns) + RETURNING %s`, documentReturningColumns) - item, err := scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, dto.Status, id)) + item, err := scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, dto.Active, id)) if errors.Is(err, pgx.ErrNoRows) { return loansdocument.LoanDocumentDTO{}, err } return item, err } -func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (loansdocument.LoanDocumentDTO, error) { +func (r *repository) UpdateActive(ctx context.Context, id int64, active bool) (loansdocument.LoanDocumentDTO, error) { query := fmt.Sprintf(` UPDATE loan_required_documents SET - status = $1, + active = $1, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $2 - RETURNING %s`, documentColumns) + RETURNING %s`, documentReturningColumns) - item, err := scanLoanDocument(r.client.QueryRow(ctx, query, status, id)) + item, err := scanLoanDocument(r.client.QueryRow(ctx, query, active, id)) if errors.Is(err, pgx.ErrNoRows) { return loansdocument.LoanDocumentDTO{}, err } @@ -178,7 +180,7 @@ func scanLoanDocument(row scannable) (loansdocument.LoanDocumentDTO, error) { if err := row.Scan( &item.Id, &titleJSON, &item.ContentEn, &item.ContentRu, &item.ContentTm, - &item.Status, &item.CreatedAt, &item.UpdatedAt, + &item.Active, &item.CreatedAt, &item.UpdatedAt, ); err != nil { return loansdocument.LoanDocumentDTO{}, err } diff --git a/internal/admin/loansdocument/dto.go b/internal/admin/loansdocument/dto.go index 7186de3..c6b619f 100644 --- a/internal/admin/loansdocument/dto.go +++ b/internal/admin/loansdocument/dto.go @@ -14,7 +14,7 @@ type LoanDocumentDTO struct { ContentEn string `json:"contentEn"` ContentRu string `json:"contentRu"` ContentTm string `json:"contentTm"` - Status bool `json:"status"` + Active bool `json:"active"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } @@ -24,7 +24,7 @@ type CreateLoanDocumentDTO struct { ContentEn string `json:"contentEn" binding:"required"` ContentRu string `json:"contentRu" binding:"required"` ContentTm string `json:"contentTm" binding:"required"` - Status *bool `json:"status"` + Active *bool `json:"active"` } type UpdateLoanDocumentDTO struct { @@ -32,16 +32,16 @@ type UpdateLoanDocumentDTO struct { ContentEn string `json:"contentEn" binding:"required"` ContentRu string `json:"contentRu" binding:"required"` ContentTm string `json:"contentTm" binding:"required"` - Status bool `json:"status"` + Active bool `json:"active"` } -type UpdateLoanDocumentStatusDTO struct { - Status bool `json:"status"` +type UpdateLoanDocumentActiveDTO struct { + Active bool `json:"active"` } type ListFilter struct { DocumentName string - Status *bool + Active *bool Page int Limit int } diff --git a/internal/admin/loansdocument/handler.go b/internal/admin/loansdocument/handler.go index 21d3184..1b8d8d7 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.PUT("/:id/status", h.updateStatus) + group.PUT("/:id/active", h.updateActive) group.DELETE("/:id", h.delete) } @@ -42,7 +42,7 @@ func (h *handler) Register(router *gin.RouterGroup) { // @Produce json // @Security BearerAuth // @Param document_name query string false "Filter by title (en, ru, tm)" -// @Param status query bool false "Filter by status" +// @Param active query bool false "Filter by active" // @Param page query int false "Page number" default(1) // @Param limit query int false "Items per page" default(10) // @Success 200 {object} appresult.AppSuccess @@ -169,40 +169,40 @@ func (h *handler) update(c *gin.Context) { c.JSON(http.StatusOK, appresult.SuccessWithData(item)) } -// updateStatus godoc -// @Summary Update loan document status +// updateActive godoc +// @Summary Update loan document active // @Description Enables or disables a loan document // @Tags loan-document // @Accept json // @Produce json // @Security BearerAuth // @Param id path int true "Loan document ID" -// @Param body body UpdateLoanDocumentStatusDTO true "Status payload" +// @Param body body UpdateLoanDocumentActiveDTO true "Active payload" // @Success 200 {object} appresult.AppSuccess // @Failure 400 {object} appresult.AppError // @Failure 404 {object} appresult.AppError // @Failure 500 {object} appresult.AppError -// @Router /loans-documents/{id}/status [put] -func (h *handler) updateStatus(c *gin.Context) { +// @Router /loans-documents/{id}/active [put] +func (h *handler) updateActive(c *gin.Context) { id, ok := parseID(c.Param("id")) if !ok { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - var dto UpdateLoanDocumentStatusDTO + var dto UpdateLoanDocumentActiveDTO if err := c.ShouldBindJSON(&dto); err != nil { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - item, err := h.repository.UpdateStatus(c.Request.Context(), id, dto.Status) + item, err := h.repository.UpdateActive(c.Request.Context(), id, dto.Active) if errors.Is(err, pgx.ErrNoRows) { c.JSON(http.StatusNotFound, appresult.ErrNotFound) return } if err != nil { - h.logger.Errorf("update loan document status failed: %v", err) + h.logger.Errorf("update loan document active failed: %v", err) c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) return } @@ -281,12 +281,12 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) { filter.DocumentName = raw } - if raw := c.Query("status"); raw != "" { - status, err := strconv.ParseBool(raw) + if raw := c.Query("active"); raw != "" { + active, err := strconv.ParseBool(raw) if err != nil { return ListFilter{}, false } - filter.Status = &status + filter.Active = &active } return filter, true diff --git a/internal/admin/loansdocument/storage.go b/internal/admin/loansdocument/storage.go index c946f36..160ddb9 100644 --- a/internal/admin/loansdocument/storage.go +++ b/internal/admin/loansdocument/storage.go @@ -7,6 +7,6 @@ type Repository interface { GetByID(ctx context.Context, id int64) (LoanDocumentDTO, error) Create(ctx context.Context, dto CreateLoanDocumentDTO) (LoanDocumentDTO, error) Update(ctx context.Context, id int64, dto UpdateLoanDocumentDTO) (LoanDocumentDTO, error) - UpdateStatus(ctx context.Context, id int64, status bool) (LoanDocumentDTO, error) + UpdateActive(ctx context.Context, id int64, active bool) (LoanDocumentDTO, error) Delete(ctx context.Context, id int64) error } diff --git a/internal/admin/loantype/db/postgresql.go b/internal/admin/loantype/db/postgresql.go index d366b22..e2431b3 100644 --- a/internal/admin/loantype/db/postgresql.go +++ b/internal/admin/loantype/db/postgresql.go @@ -25,6 +25,8 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) loantype.Re const loanTypeColumns = `lt.id, lt.title, lt.tax, lt.loan_term, lt.content, lt.created_at, lt.updated_at` +const loanTypeReturningColumns = `id, title, tax, loan_term, content, created_at, updated_at` + func (r *repository) List(ctx context.Context, filter loantype.ListFilter) (loantype.ListLoanTypeDTO, error) { fromClause, whereClause, args := buildListQuery(filter) @@ -106,7 +108,7 @@ func (r *repository) Create(ctx context.Context, dto loantype.CreateLoanTypeDTO) query := fmt.Sprintf(` INSERT INTO loan_types (title, tax, loan_term, content) VALUES ($1, $2, $3, $4) - RETURNING %s`, loanTypeColumns) + RETURNING %s`, loanTypeReturningColumns) return scanLoanType(r.client.QueryRow(ctx, query, title, dto.Tax, dto.LoanTerm, content)) } @@ -122,7 +124,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto loantype.UpdateLo title = $1, tax = $2, loan_term = $3, content = $4, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $5 - RETURNING %s`, loanTypeColumns) + RETURNING %s`, loanTypeReturningColumns) item, err := scanLoanType(r.client.QueryRow(ctx, query, title, dto.Tax, dto.LoanTerm, content, id)) if errors.Is(err, pgx.ErrNoRows) { diff --git a/internal/admin/location/db/postgresql.go b/internal/admin/location/db/postgresql.go deleted file mode 100644 index 015349f..0000000 --- a/internal/admin/location/db/postgresql.go +++ /dev/null @@ -1,222 +0,0 @@ -package db - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "strings" - - "online-back/internal/admin/location" - "online-back/pkg/client/postgresql" - "online-back/pkg/logging" - - "github.com/jackc/pgx/v4" -) - -type repository struct { - client postgresql.Client - logger *logging.Logger -} - -func NewRepository(client postgresql.Client, logger *logging.Logger) location.Repository { - return &repository{client: client, logger: logger} -} - -func (r *repository) List(ctx context.Context, filter location.ListFilter) (location.ListLocationDTO, error) { - fromClause, whereClause, args := buildListQuery(filter) - - var count int64 - countQuery := `SELECT COUNT(*) ` + fromClause + whereClause - if err := r.client.QueryRow(ctx, countQuery, args...).Scan(&count); err != nil { - return location.ListLocationDTO{}, err - } - - offset := (filter.Page - 1) * filter.Limit - limitPlaceholder := len(args) + 1 - offsetPlaceholder := len(args) + 2 - listQuery := fmt.Sprintf( - `SELECT l.id, l.province_id, l.title, l.status%s%s ORDER BY l.id LIMIT $%d OFFSET $%d`, - fromClause, whereClause, limitPlaceholder, offsetPlaceholder, - ) - listArgs := append(args, filter.Limit, offset) - - rows, err := r.client.Query(ctx, listQuery, listArgs...) - if err != nil { - return location.ListLocationDTO{}, err - } - defer rows.Close() - - var items []location.LocationDTO - for rows.Next() { - item, err := scanLocation(rows) - if err != nil { - return location.ListLocationDTO{}, err - } - items = append(items, item) - } - if err := rows.Err(); err != nil { - return location.ListLocationDTO{}, err - } - - return location.ListLocationDTO{ - Count: count, - Locations: items, - }, nil -} - -func buildListQuery(filter location.ListFilter) (fromClause, whereClause string, args []interface{}) { - fromClause = ` FROM location l` - - if filter.ProvinceName != "" { - fromClause += ` JOIN provinces p ON p.id = l.province_id` - } - - var conditions []string - - if filter.ProvinceID != nil { - args = append(args, *filter.ProvinceID) - conditions = append(conditions, fmt.Sprintf("l.province_id = $%d", len(args))) - } - - if filter.ProvinceName != "" { - args = append(args, likePattern(filter.ProvinceName)) - n := len(args) - conditions = append(conditions, fmt.Sprintf(`( - p.title->>'en' ILIKE $%[1]d OR p.title->>'ru' ILIKE $%[1]d OR p.title->>'tm' ILIKE $%[1]d - )`, n)) - } - - if filter.LocationName != "" { - args = append(args, likePattern(filter.LocationName)) - n := len(args) - conditions = append(conditions, fmt.Sprintf(`( - l.title->>'en' ILIKE $%[1]d OR l.title->>'ru' ILIKE $%[1]d OR l.title->>'tm' ILIKE $%[1]d - )`, n)) - } - - if filter.Status != nil { - args = append(args, *filter.Status) - conditions = append(conditions, fmt.Sprintf("l.status = $%d", len(args))) - } - - if len(conditions) == 0 { - return fromClause, "", args - } - - return fromClause, " WHERE " + strings.Join(conditions, " AND "), args -} - -func likePattern(term string) string { - term = strings.ReplaceAll(term, `\`, `\\`) - term = strings.ReplaceAll(term, `%`, `\%`) - term = strings.ReplaceAll(term, `_`, `\_`) - return "%" + term + "%" -} - -func (r *repository) GetByID(ctx context.Context, id int64) (location.LocationDTO, error) { - row := r.client.QueryRow(ctx, - `SELECT id, province_id, title, status FROM location WHERE id = $1`, id, - ) - item, err := scanLocation(row) - if errors.Is(err, pgx.ErrNoRows) { - return location.LocationDTO{}, err - } - return item, err -} - -func (r *repository) Create(ctx context.Context, dto location.CreateLocationDTO) (location.LocationDTO, error) { - if err := r.ensureProvinceExists(ctx, dto.ProvinceId); err != nil { - return location.LocationDTO{}, err - } - - title, err := json.Marshal(dto.Title) - if err != nil { - return location.LocationDTO{}, err - } - - status := true - if dto.Status != nil { - status = *dto.Status - } - - row := r.client.QueryRow(ctx, - `INSERT INTO location (province_id, title, status) VALUES ($1, $2, $3) - RETURNING id, province_id, title, status`, - dto.ProvinceId, title, status, - ) - return scanLocation(row) -} - -func (r *repository) Update(ctx context.Context, id int64, dto location.UpdateLocationDTO) (location.LocationDTO, error) { - if err := r.ensureProvinceExists(ctx, dto.ProvinceId); err != nil { - return location.LocationDTO{}, err - } - - title, err := json.Marshal(dto.Title) - if err != nil { - return location.LocationDTO{}, err - } - - row := r.client.QueryRow(ctx, - `UPDATE location SET province_id = $1, title = $2, status = $3 - WHERE id = $4 - RETURNING id, province_id, title, status`, - dto.ProvinceId, title, dto.Status, id, - ) - item, err := scanLocation(row) - if errors.Is(err, pgx.ErrNoRows) { - return location.LocationDTO{}, err - } - return item, err -} - -func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (location.LocationDTO, error) { - row := r.client.QueryRow(ctx, - `UPDATE location SET status = $1 WHERE id = $2 - RETURNING id, province_id, title, status`, - status, id, - ) - item, err := scanLocation(row) - if errors.Is(err, pgx.ErrNoRows) { - return location.LocationDTO{}, err - } - return item, err -} - -func (r *repository) Delete(ctx context.Context, id int64) error { - tag, err := r.client.Exec(ctx, `DELETE FROM location WHERE id = $1`, id) - if err != nil { - return err - } - if tag.RowsAffected() == 0 { - return pgx.ErrNoRows - } - return nil -} - -func (r *repository) ensureProvinceExists(ctx context.Context, provinceID int64) error { - var id int64 - 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") - } - return err -} - -type scannable interface { - Scan(dest ...interface{}) error -} - -func scanLocation(row scannable) (location.LocationDTO, error) { - var item location.LocationDTO - var titleJSON []byte - - if err := row.Scan(&item.Id, &item.ProvinceId, &titleJSON, &item.Status); err != nil { - return location.LocationDTO{}, err - } - if err := json.Unmarshal(titleJSON, &item.Title); err != nil { - return location.LocationDTO{}, err - } - return item, nil -} diff --git a/internal/admin/location/dto.go b/internal/admin/location/dto.go deleted file mode 100644 index bfe4711..0000000 --- a/internal/admin/location/dto.go +++ /dev/null @@ -1,44 +0,0 @@ -package location - -type LocalizedTitle struct { - En string `json:"en"` - Ru string `json:"ru"` - Tm string `json:"tm"` -} - -type LocationDTO struct { - Id int64 `json:"id"` - ProvinceId int64 `json:"provinceId"` - Title LocalizedTitle `json:"title"` - Status bool `json:"status"` -} - -type CreateLocationDTO struct { - ProvinceId int64 `json:"provinceId" binding:"required"` - Title LocalizedTitle `json:"title" binding:"required"` - Status *bool `json:"status"` -} - -type UpdateLocationDTO struct { - ProvinceId int64 `json:"provinceId" binding:"required"` - Title LocalizedTitle `json:"title" binding:"required"` - Status bool `json:"status"` -} - -type UpdateLocationStatusDTO struct { - Status bool `json:"status"` -} - -type ListFilter struct { - ProvinceID *int64 - ProvinceName string - LocationName string - Status *bool - Page int - Limit int -} - -type ListLocationDTO struct { - Count int64 `json:"count"` - Locations []LocationDTO `json:"locations"` -} diff --git a/internal/admin/location/handler.go b/internal/admin/location/handler.go deleted file mode 100644 index d1628c9..0000000 --- a/internal/admin/location/handler.go +++ /dev/null @@ -1,315 +0,0 @@ -package location - -import ( - "errors" - "net/http" - "strconv" - "strings" - - "online-back/internal/appresult" - "online-back/internal/handlers" - "online-back/pkg/logging" - - "github.com/gin-gonic/gin" - "github.com/jackc/pgx/v4" -) - -const baseURL = "/locations" - -type handler struct { - logger *logging.Logger - repository Repository -} - -func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler { - return &handler{logger: logger, repository: repository} -} - -func (h *handler) Register(router *gin.RouterGroup) { - group := router.Group(baseURL, appresult.JwtTokenCheck()) - group.GET("", h.list) - group.GET("/:id", h.getByID) - group.POST("", h.create) - group.PUT("/:id", h.update) - group.PUT("/:id/status", h.updateStatus) - group.DELETE("/:id", h.delete) -} - -// list godoc -// @Summary List locations -// @Description Returns paginated locations with optional filters -// @Tags location -// @Produce json -// @Security BearerAuth -// @Param province_id query int false "Filter by province ID" -// @Param province_name query string false "Filter by province name (en, ru, tm)" -// @Param location_name query string false "Filter by location name (en, ru, tm)" -// @Param status query bool false "Filter by location status" -// @Param page query int false "Page number" default(1) -// @Param limit query int false "Items per page" default(10) -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations [get] -func (h *handler) list(c *gin.Context) { - filter, ok := parseListFilter(c) - if !ok { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - result, err := h.repository.List(c.Request.Context(), filter) - if err != nil { - h.logger.Errorf("list locations failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData(result)) -} - -// getByID godoc -// @Summary Get location by ID -// @Description Returns a single location -// @Tags location -// @Produce json -// @Security BearerAuth -// @Param id path int true "Location ID" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 404 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations/{id} [get] -func (h *handler) getByID(c *gin.Context) { - id, ok := parseID(c.Param("id")) - if !ok { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - item, err := h.repository.GetByID(c.Request.Context(), id) - if errors.Is(err, pgx.ErrNoRows) { - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } - if err != nil { - h.logger.Errorf("get location failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData(item)) -} - -// create godoc -// @Summary Create location -// @Description Creates a new location in a province -// @Tags location -// @Accept json -// @Produce json -// @Security BearerAuth -// @Param body body CreateLocationDTO true "Location payload" -// @Success 201 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations [post] -func (h *handler) create(c *gin.Context) { - var dto CreateLocationDTO - if err := c.ShouldBindJSON(&dto); err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - item, err := h.repository.Create(c.Request.Context(), dto) - if err != nil { - if err.Error() == "province not found" { - c.JSON(http.StatusBadRequest, appresult.ErrNotFound) - return - } - h.logger.Errorf("create location failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusCreated, appresult.SuccessWithData(item)) -} - -// update godoc -// @Summary Update location -// @Description Updates an existing location -// @Tags location -// @Accept json -// @Produce json -// @Security BearerAuth -// @Param id path int true "Location ID" -// @Param body body UpdateLocationDTO true "Location payload" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 404 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations/{id} [put] -func (h *handler) update(c *gin.Context) { - id, ok := parseID(c.Param("id")) - if !ok { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - var dto UpdateLocationDTO - if err := c.ShouldBindJSON(&dto); err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - item, err := h.repository.Update(c.Request.Context(), id, dto) - if errors.Is(err, pgx.ErrNoRows) { - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } - if err != nil { - if err.Error() == "province not found" { - c.JSON(http.StatusBadRequest, appresult.ErrNotFound) - return - } - h.logger.Errorf("update location failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData(item)) -} - -// updateStatus godoc -// @Summary Update location status -// @Description Enables or disables a location -// @Tags location -// @Accept json -// @Produce json -// @Security BearerAuth -// @Param id path int true "Location ID" -// @Param body body UpdateLocationStatusDTO true "Status payload" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 404 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations/{id}/status [put] -func (h *handler) updateStatus(c *gin.Context) { - id, ok := parseID(c.Param("id")) - if !ok { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - var dto UpdateLocationStatusDTO - if err := c.ShouldBindJSON(&dto); err != nil { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - item, err := h.repository.UpdateStatus(c.Request.Context(), id, dto.Status) - if errors.Is(err, pgx.ErrNoRows) { - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } - if err != nil { - h.logger.Errorf("update location status failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData(item)) -} - -// delete godoc -// @Summary Delete location -// @Description Deletes a location -// @Tags location -// @Produce json -// @Security BearerAuth -// @Param id path int true "Location ID" -// @Success 200 {object} appresult.AppSuccess -// @Failure 400 {object} appresult.AppError -// @Failure 404 {object} appresult.AppError -// @Failure 500 {object} appresult.AppError -// @Router /locations/{id} [delete] -func (h *handler) delete(c *gin.Context) { - id, ok := parseID(c.Param("id")) - if !ok { - c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) - return - } - - if err := h.repository.Delete(c.Request.Context(), id); errors.Is(err, pgx.ErrNoRows) { - c.JSON(http.StatusNotFound, appresult.ErrNotFound) - return - } else if err != nil { - h.logger.Errorf("delete location failed: %v", err) - c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) - return - } - - c.JSON(http.StatusOK, appresult.SuccessWithData("location removed")) -} - -func parseID(raw string) (int64, bool) { - id, err := strconv.ParseInt(raw, 10, 64) - if err != nil || id <= 0 { - return 0, false - } - return id, true -} - -const ( - defaultPage = 1 - defaultLimit = 10 - maxLimit = 100 -) - -func parseListFilter(c *gin.Context) (ListFilter, bool) { - filter := ListFilter{ - Page: defaultPage, - Limit: defaultLimit, - } - - if raw := c.Query("province_id"); raw != "" { - id, ok := parseID(raw) - if !ok { - return ListFilter{}, false - } - filter.ProvinceID = &id - } - - if raw := c.Query("page"); raw != "" { - page, err := strconv.Atoi(raw) - if err != nil || page < 1 { - return ListFilter{}, false - } - filter.Page = page - } - - if raw := c.Query("limit"); raw != "" { - limit, err := strconv.Atoi(raw) - if err != nil || limit < 1 || limit > maxLimit { - return ListFilter{}, false - } - filter.Limit = limit - } - - if raw := strings.TrimSpace(c.Query("province_name")); raw != "" { - filter.ProvinceName = raw - } - - if raw := strings.TrimSpace(c.Query("location_name")); raw != "" { - filter.LocationName = raw - } - - if raw := c.Query("status"); raw != "" { - status, err := strconv.ParseBool(raw) - if err != nil { - return ListFilter{}, false - } - filter.Status = &status - } - - return filter, true -} diff --git a/internal/admin/location/storage.go b/internal/admin/location/storage.go deleted file mode 100644 index 791e1cd..0000000 --- a/internal/admin/location/storage.go +++ /dev/null @@ -1,12 +0,0 @@ -package location - -import "context" - -type Repository interface { - List(ctx context.Context, filter ListFilter) (ListLocationDTO, error) - GetByID(ctx context.Context, id int64) (LocationDTO, error) - Create(ctx context.Context, dto CreateLocationDTO) (LocationDTO, error) - Update(ctx context.Context, id int64, dto UpdateLocationDTO) (LocationDTO, error) - UpdateStatus(ctx context.Context, id int64, status bool) (LocationDTO, error) - Delete(ctx context.Context, id int64) error -} diff --git a/internal/admin/paymentcard/db/postgresql.go b/internal/admin/paymentcard/db/postgresql.go index 4eec245..add1a68 100644 --- a/internal/admin/paymentcard/db/postgresql.go +++ b/internal/admin/paymentcard/db/postgresql.go @@ -23,7 +23,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) paymentcard return &repository{client: client, logger: logger} } -const cardColumns = `c.id, c.price, c.title, c.content, c.status` +const cardColumns = `c.id, c.price, c.title, c.content, c.active` + +const cardReturningColumns = `id, price, title, content, active` func (r *repository) List(ctx context.Context, filter paymentcard.ListFilter) (paymentcard.ListPaymentCardDTO, error) { fromClause, whereClause, args := buildListQuery(filter) @@ -75,9 +77,9 @@ func buildListQuery(filter paymentcard.ListFilter) (fromClause, whereClause stri )`, n)) } - if filter.Status != nil { - args = append(args, *filter.Status) - conditions = append(conditions, fmt.Sprintf("c.status = $%d", len(args))) + if filter.Active != nil { + args = append(args, *filter.Active) + conditions = append(conditions, fmt.Sprintf("c.active = $%d", len(args))) } if len(conditions) == 0 { @@ -109,17 +111,17 @@ func (r *repository) Create(ctx context.Context, dto paymentcard.CreatePaymentCa return paymentcard.PaymentCardDTO{}, err } - status := true - if dto.Status != nil { - status = *dto.Status + active := true + if dto.Active != nil { + active = *dto.Active } query := fmt.Sprintf(` - INSERT INTO payment_cards (price, title, content, status) + INSERT INTO payment_cards (price, title, content, active) VALUES ($1, $2, $3, $4) - RETURNING %s`, cardColumns) + RETURNING %s`, cardReturningColumns) - return scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, status)) + return scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, active)) } func (r *repository) Update(ctx context.Context, id int64, dto paymentcard.UpdatePaymentCardDTO) (paymentcard.PaymentCardDTO, error) { @@ -130,24 +132,24 @@ func (r *repository) Update(ctx context.Context, id int64, dto paymentcard.Updat query := fmt.Sprintf(` UPDATE payment_cards SET - price = $1, title = $2, content = $3, status = $4 + price = $1, title = $2, content = $3, active = $4 WHERE id = $5 - RETURNING %s`, cardColumns) + RETURNING %s`, cardReturningColumns) - item, err := scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, dto.Status, id)) + item, err := scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, dto.Active, id)) if errors.Is(err, pgx.ErrNoRows) { return paymentcard.PaymentCardDTO{}, err } return item, err } -func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (paymentcard.PaymentCardDTO, error) { +func (r *repository) UpdateActive(ctx context.Context, id int64, active bool) (paymentcard.PaymentCardDTO, error) { query := fmt.Sprintf(` - UPDATE payment_cards SET status = $1 + UPDATE payment_cards SET active = $1 WHERE id = $2 - RETURNING %s`, cardColumns) + RETURNING %s`, cardReturningColumns) - item, err := scanPaymentCard(r.client.QueryRow(ctx, query, status, id)) + item, err := scanPaymentCard(r.client.QueryRow(ctx, query, active, id)) if errors.Is(err, pgx.ErrNoRows) { return paymentcard.PaymentCardDTO{}, err } @@ -186,7 +188,7 @@ func scanPaymentCard(row scannable) (paymentcard.PaymentCardDTO, error) { var titleJSON, contentJSON []byte if err := row.Scan( - &item.Id, &item.Price, &titleJSON, &contentJSON, &item.Status, + &item.Id, &item.Price, &titleJSON, &contentJSON, &item.Active, ); err != nil { return paymentcard.PaymentCardDTO{}, err } diff --git a/internal/admin/paymentcard/dto.go b/internal/admin/paymentcard/dto.go index 140f537..218b144 100644 --- a/internal/admin/paymentcard/dto.go +++ b/internal/admin/paymentcard/dto.go @@ -11,30 +11,30 @@ type PaymentCardDTO struct { Price float64 `json:"price"` Title LocalizedText `json:"title"` Content LocalizedText `json:"content"` - Status bool `json:"status"` + Active bool `json:"active"` } type CreatePaymentCardDTO struct { Price float64 `json:"price" binding:"required"` Title LocalizedText `json:"title" binding:"required"` Content LocalizedText `json:"content" binding:"required"` - Status *bool `json:"status"` + Active *bool `json:"active"` } type UpdatePaymentCardDTO struct { Price float64 `json:"price" binding:"required"` Title LocalizedText `json:"title" binding:"required"` Content LocalizedText `json:"content" binding:"required"` - Status bool `json:"status"` + Active bool `json:"active"` } -type UpdatePaymentCardStatusDTO struct { - Status bool `json:"status"` +type UpdatePaymentCardActiveDTO struct { + Active bool `json:"active"` } type ListFilter struct { CardName string - Status *bool + Active *bool Page int Limit int } diff --git a/internal/admin/paymentcard/handler.go b/internal/admin/paymentcard/handler.go index ac76a7f..5527c2f 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.PUT("/:id/status", h.updateStatus) + group.PUT("/:id/active", h.updateActive) group.DELETE("/:id", h.delete) } @@ -42,7 +42,7 @@ func (h *handler) Register(router *gin.RouterGroup) { // @Produce json // @Security BearerAuth // @Param card_name query string false "Filter by card title (en, ru, tm)" -// @Param status query bool false "Filter by status" +// @Param active query bool false "Filter by active" // @Param page query int false "Page number" default(1) // @Param limit query int false "Items per page" default(10) // @Success 200 {object} appresult.AppSuccess @@ -169,40 +169,40 @@ func (h *handler) update(c *gin.Context) { c.JSON(http.StatusOK, appresult.SuccessWithData(item)) } -// updateStatus godoc -// @Summary Update payment card status +// updateActive godoc +// @Summary Update payment card active // @Description Enables or disables a payment card // @Tags payment-card // @Accept json // @Produce json // @Security BearerAuth // @Param id path int true "Payment card ID" -// @Param body body UpdatePaymentCardStatusDTO true "Status payload" +// @Param body body UpdatePaymentCardActiveDTO true "Active payload" // @Success 200 {object} appresult.AppSuccess // @Failure 400 {object} appresult.AppError // @Failure 404 {object} appresult.AppError // @Failure 500 {object} appresult.AppError -// @Router /payment-cards/{id}/status [put] -func (h *handler) updateStatus(c *gin.Context) { +// @Router /payment-cards/{id}/active [put] +func (h *handler) updateActive(c *gin.Context) { id, ok := parseID(c.Param("id")) if !ok { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - var dto UpdatePaymentCardStatusDTO + var dto UpdatePaymentCardActiveDTO if err := c.ShouldBindJSON(&dto); err != nil { c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) return } - item, err := h.repository.UpdateStatus(c.Request.Context(), id, dto.Status) + item, err := h.repository.UpdateActive(c.Request.Context(), id, dto.Active) if errors.Is(err, pgx.ErrNoRows) { c.JSON(http.StatusNotFound, appresult.ErrNotFound) return } if err != nil { - h.logger.Errorf("update payment card status failed: %v", err) + h.logger.Errorf("update payment card active failed: %v", err) c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) return } @@ -281,12 +281,12 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) { filter.CardName = raw } - if raw := c.Query("status"); raw != "" { - status, err := strconv.ParseBool(raw) + if raw := c.Query("active"); raw != "" { + active, err := strconv.ParseBool(raw) if err != nil { return ListFilter{}, false } - filter.Status = &status + filter.Active = &active } return filter, true diff --git a/internal/admin/paymentcard/storage.go b/internal/admin/paymentcard/storage.go index e96a4e7..ab52a3c 100644 --- a/internal/admin/paymentcard/storage.go +++ b/internal/admin/paymentcard/storage.go @@ -7,6 +7,6 @@ type Repository interface { GetByID(ctx context.Context, id int64) (PaymentCardDTO, error) Create(ctx context.Context, dto CreatePaymentCardDTO) (PaymentCardDTO, error) Update(ctx context.Context, id int64, dto UpdatePaymentCardDTO) (PaymentCardDTO, error) - UpdateStatus(ctx context.Context, id int64, status bool) (PaymentCardDTO, error) + UpdateActive(ctx context.Context, id int64, active bool) (PaymentCardDTO, error) Delete(ctx context.Context, id int64) error } diff --git a/internal/admin/province/db/postgresql.go b/internal/admin/province/db/postgresql.go index 2101816..07436c2 100644 --- a/internal/admin/province/db/postgresql.go +++ b/internal/admin/province/db/postgresql.go @@ -21,8 +21,10 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) province.Re return &repository{client: client, logger: logger} } +const provinceSelectColumns = `id, name, region, active` + func (r *repository) List(ctx context.Context) ([]province.ProvinceDTO, error) { - rows, err := r.client.Query(ctx, `SELECT id, title, status FROM provinces ORDER BY id`) + rows, err := r.client.Query(ctx, `SELECT `+provinceSelectColumns+` FROM provinces ORDER BY id`) if err != nil { return nil, err } @@ -41,7 +43,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, status FROM provinces WHERE id = $1`, id) + row := r.client.QueryRow(ctx, `SELECT `+provinceSelectColumns+` FROM provinces WHERE id = $1`, id) item, err := scanProvince(row) if errors.Is(err, pgx.ErrNoRows) { return province.ProvinceDTO{}, err @@ -50,32 +52,32 @@ func (r *repository) GetByID(ctx context.Context, id int64) (province.ProvinceDT } func (r *repository) Create(ctx context.Context, dto province.CreateProvinceDTO) (province.ProvinceDTO, error) { - title, err := json.Marshal(dto.Title) + name, region, err := marshalProvinceJSON(dto.Name, dto.Region) if err != nil { return province.ProvinceDTO{}, err } - status := true - if dto.Status != nil { - status = *dto.Status + active := true + if dto.Active != nil { + active = *dto.Active } row := r.client.QueryRow(ctx, - `INSERT INTO provinces (title, status) VALUES ($1, $2) RETURNING id, title, status`, - title, status, + `INSERT INTO provinces (name, region, active) VALUES ($1, $2, $3) RETURNING `+provinceSelectColumns, + name, region, active, ) return scanProvince(row) } func (r *repository) Update(ctx context.Context, id int64, dto province.UpdateProvinceDTO) (province.ProvinceDTO, error) { - title, err := json.Marshal(dto.Title) + name, region, err := marshalProvinceJSON(dto.Name, dto.Region) if err != nil { return province.ProvinceDTO{}, err } row := r.client.QueryRow(ctx, - `UPDATE provinces SET title = $1, status = $2 WHERE id = $3 RETURNING id, title, status`, - title, dto.Status, id, + `UPDATE provinces SET name = $1, region = $2, active = $3 WHERE id = $4 RETURNING `+provinceSelectColumns, + name, region, dto.Active, id, ) item, err := scanProvince(row) if errors.Is(err, pgx.ErrNoRows) { @@ -95,17 +97,32 @@ func (r *repository) Delete(ctx context.Context, id int64) error { return nil } +func marshalProvinceJSON(name, region province.LocalizedName) ([]byte, []byte, error) { + nameJSON, err := json.Marshal(name) + if err != nil { + return nil, nil, err + } + regionJSON, err := json.Marshal(region) + if err != nil { + return nil, nil, err + } + return nameJSON, regionJSON, nil +} + type scannable interface { Scan(dest ...interface{}) error } func scanProvince(row scannable) (province.ProvinceDTO, error) { var item province.ProvinceDTO - var titleJSON []byte - if err := row.Scan(&item.Id, &titleJSON, &item.Status); err != nil { + var nameJSON, regionJSON []byte + if err := row.Scan(&item.Id, &nameJSON, ®ionJSON, &item.Active); err != nil { return province.ProvinceDTO{}, err } - if err := json.Unmarshal(titleJSON, &item.Title); err != nil { + if err := json.Unmarshal(nameJSON, &item.Name); err != nil { + return province.ProvinceDTO{}, err + } + if err := json.Unmarshal(regionJSON, &item.Region); err != nil { return province.ProvinceDTO{}, err } return item, nil diff --git a/internal/admin/province/dto.go b/internal/admin/province/dto.go index a22dd57..6c59d1c 100644 --- a/internal/admin/province/dto.go +++ b/internal/admin/province/dto.go @@ -1,23 +1,26 @@ package province -type LocalizedTitle struct { +type LocalizedName struct { En string `json:"en"` Ru string `json:"ru"` Tm string `json:"tm"` } type ProvinceDTO struct { - Id int64 `json:"id"` - Title LocalizedTitle `json:"title"` - Status bool `json:"status"` + Id int64 `json:"id"` + Name LocalizedName `json:"name"` + Region LocalizedName `json:"region"` + Active bool `json:"active"` } type CreateProvinceDTO struct { - Title LocalizedTitle `json:"title" binding:"required"` - Status *bool `json:"status"` + Name LocalizedName `json:"name" binding:"required"` + Region LocalizedName `json:"region" binding:"required"` + Active *bool `json:"active"` } type UpdateProvinceDTO struct { - Title LocalizedTitle `json:"title" binding:"required"` - Status bool `json:"status"` + Name LocalizedName `json:"name" binding:"required"` + Region LocalizedName `json:"region" binding:"required"` + Active bool `json:"active"` } diff --git a/internal/admin/province/handler.go b/internal/admin/province/handler.go index 4c2a5cc..cb1c39c 100644 --- a/internal/admin/province/handler.go +++ b/internal/admin/province/handler.go @@ -159,7 +159,7 @@ func (h *handler) update(c *gin.Context) { // delete godoc // @Summary Delete province -// @Description Deletes a province and its locations +// @Description Deletes a province // @Tags province // @Produce json // @Security BearerAuth diff --git a/internal/admin/reasonscard/db/postgresql.go b/internal/admin/reasonscard/db/postgresql.go index 10bcc7d..6f4742e 100644 --- a/internal/admin/reasonscard/db/postgresql.go +++ b/internal/admin/reasonscard/db/postgresql.go @@ -25,6 +25,8 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) reasonscard const reasonColumns = `r.id, r.title, r.price, r.content, r.created_at, r.updated_at` +const reasonReturningColumns = `id, title, price, content, created_at, updated_at` + func (r *repository) List(ctx context.Context, filter reasonscard.ListFilter) (reasonscard.ListReasonCardDTO, error) { fromClause, whereClause, args := buildListQuery(filter) @@ -106,7 +108,7 @@ func (r *repository) Create(ctx context.Context, dto reasonscard.CreateReasonCar query := fmt.Sprintf(` INSERT INTO reasons_cards (title, price, content) VALUES ($1, $2, $3) - RETURNING %s`, reasonColumns) + RETURNING %s`, reasonReturningColumns) return scanReasonCard(r.client.QueryRow(ctx, query, title, dto.Price, content)) } @@ -122,7 +124,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto reasonscard.Updat title = $1, price = $2, content = $3, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $4 - RETURNING %s`, reasonColumns) + RETURNING %s`, reasonReturningColumns) item, err := scanReasonCard(r.client.QueryRow(ctx, query, title, dto.Price, content, id)) if errors.Is(err, pgx.ErrNoRows) { diff --git a/internal/handlers/manager/manager.go b/internal/handlers/manager/manager.go index 057e8a7..1817246 100755 --- a/internal/handlers/manager/manager.go +++ b/internal/handlers/manager/manager.go @@ -7,8 +7,6 @@ import ( authdb "online-back/internal/admin/auth/db" "online-back/internal/admin/branches" branchesdb "online-back/internal/admin/branches/db" - "online-back/internal/admin/location" - locationdb "online-back/internal/admin/location/db" "online-back/internal/admin/loantype" loantypedb "online-back/internal/admin/loantype/db" "online-back/internal/admin/loansdocument" @@ -67,7 +65,6 @@ func adminHandlers(client *pgxpool.Pool, logger *logging.Logger) []handlers.Hand return []handlers.Handler{ auth.NewHandler(logger, authdb.NewRepository(client, logger)), province.NewHandler(logger, provincedb.NewRepository(client, logger)), - location.NewHandler(logger, locationdb.NewRepository(client, logger)), branches.NewHandler(logger, branchesdb.NewRepository(client, logger)), paymentcard.NewHandler(logger, paymentcarddb.NewRepository(client, logger)), reasonscard.NewHandler(logger, reasonscarddb.NewRepository(client, logger)), diff --git a/logs/all.log b/logs/all.log index e69de29..07e95e2 100644 --- a/logs/all.log +++ b/logs/all.log @@ -0,0 +1,33 @@ +time="2026-07-06T12:22:36+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:22:36+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:54" +time="2026-07-06T12:22:36+05:00" level=fatal msg="listen tcp 0.0.0.0:5050: bind: address already in use" func="main.main()" file="app.go:56" +time="2026-07-06T12:23:43+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:23:43+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:54" +time="2026-07-06T12:31:34+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:31:34+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:45" +time="2026-07-06T12:41:53+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:41:53+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:45" +time="2026-07-06T12:51:53+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:51:53+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:61" +time="2026-07-06T12:59:05+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T12:59:05+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:61" +time="2026-07-06T14:03:17+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:03:17+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:61" +time="2026-07-06T14:07:23+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:07:23+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T14:36:02+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:36:03+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T14:36:03+05:00" level=fatal msg="listen tcp 0.0.0.0:5050: bind: address already in use" func="main.main()" file="app.go:61" +time="2026-07-06T14:36:16+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:36:16+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T14:38:41+05:00" level=error msg="create branch failed: ERROR: missing FROM-clause entry for table \"b\" (SQLSTATE 42P01)" func="online-back/internal/admin/branches.(*handler).create()" file="handler.go:129" +time="2026-07-06T14:40:42+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:40:42+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T14:43:25+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:43:25+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T14:56:42+05:00" level=error msg="create loan type failed: ERROR: missing FROM-clause entry for table \"lt\" (SQLSTATE 42P01)" func="online-back/internal/admin/loantype.(*handler).create()" file="handler.go:121" +time="2026-07-06T14:58:32+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T14:58:32+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T15:53:35+05:00" level=info msg="read application configuration" func="online-back/internal/config.GetConfig.func1()" file="config.go:41" +time="2026-07-06T15:53:35+05:00" level=info msg="starting server on 0.0.0.0:5050" func="main.main()" file="app.go:59" +time="2026-07-06T15:53:35+05:00" level=fatal msg="listen tcp 0.0.0.0:5050: bind: address already in use" func="main.main()" file="app.go:61"