From 4d1942d7fe0a6b4c40d237595fa99cff11f2d087 Mon Sep 17 00:00:00 2001 From: GuwandykA Date: Tue, 7 Jul 2026 18:06:50 +0500 Subject: [PATCH] add roles --- config.yaml | 8 +- db/migrations/20260702125108_init.down.sql | 1 + db/migrations/20260702125108_init.up.sql | 8 + ...706155000_rename_status_to_active.down.sql | 4 - ...60706155000_rename_status_to_active.up.sql | 4 - internal/.DS_Store | Bin 6148 -> 6148 bytes internal/admin/.DS_Store | Bin 6148 -> 6148 bytes internal/admin/role/db/postgresql.go | 146 +++++++++++ internal/admin/role/dto.go | 35 +++ internal/admin/role/handler.go | 242 ++++++++++++++++++ internal/admin/role/storage.go | 11 + internal/handlers/manager/manager.go | 3 + 12 files changed, 450 insertions(+), 12 deletions(-) delete mode 100644 db/migrations/20260706155000_rename_status_to_active.down.sql delete mode 100644 db/migrations/20260706155000_rename_status_to_active.up.sql create mode 100644 internal/admin/role/db/postgresql.go create mode 100644 internal/admin/role/dto.go create mode 100644 internal/admin/role/handler.go create mode 100644 internal/admin/role/storage.go diff --git a/config.yaml b/config.yaml index 315f3ee..1affccb 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: localhost -# host: main-db - port: 5424 -# port: 5432 + # 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 b389ab3..f93da00 100644 --- a/db/migrations/20260702125108_init.down.sql +++ b/db/migrations/20260702125108_init.down.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS roles; DROP TABLE IF EXISTS loan_order_required_docs; DROP TABLE IF EXISTS loan_types; DROP TABLE IF EXISTS card_states; diff --git a/db/migrations/20260702125108_init.up.sql b/db/migrations/20260702125108_init.up.sql index 377eacb..f395b21 100644 --- a/db/migrations/20260702125108_init.up.sql +++ b/db/migrations/20260702125108_init.up.sql @@ -94,3 +94,11 @@ CREATE TABLE IF NOT EXISTS loan_order_required_docs ( updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL ); +CREATE TABLE IF NOT EXISTS roles ( + id bigserial PRIMARY KEY, + code character varying(255) NOT NULL DEFAULT '', + name character varying(255) NOT NULL, + guard_name character varying(255) NOT NULL, + created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, + updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL +); \ No newline at end of file diff --git a/db/migrations/20260706155000_rename_status_to_active.down.sql b/db/migrations/20260706155000_rename_status_to_active.down.sql deleted file mode 100644 index d52185c..0000000 --- a/db/migrations/20260706155000_rename_status_to_active.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE loan_order_required_docs RENAME COLUMN active TO status; -ALTER TABLE card_types 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 deleted file mode 100644 index 1ac21e4..0000000 --- a/db/migrations/20260706155000_rename_status_to_active.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE users RENAME COLUMN status TO active; -ALTER TABLE provinces RENAME COLUMN status TO active; -ALTER TABLE card_types RENAME COLUMN status TO active; -ALTER TABLE loan_order_required_docs RENAME COLUMN status TO active; diff --git a/internal/.DS_Store b/internal/.DS_Store index c598a81dcfbc47cfe831ed587165a9f552771c2f..af89f41c3cc2eb0e7d7ec035adc6657a3ffc58f9 100644 GIT binary patch delta 31 ncmZoMXfc@J&&a+pU^g=(`(_>%bLPqU>@y}d=xk=^_{$FfnCuC_ delta 54 zcmZoMXfc@J&&aVcU^g=($7UWDb7sjLhD?T3hCGH6&z$_^q@4UD1_lNJ1_nl@$p-AJ KH?wp65OUAS@M1#Hto3$c}^72M?v9>pVh5q;mxM`@;Y zD@DE!X5LKZz4>_wnHc~w+)i(S0f3xIF}q-PB(z=AL1gyioG9AIL%pgd^=iVpcIa{X z4(Pk&{m?!V=k!^S1A;Lm(Ot2<*i3)Sf&?Nj%vTpYHm#DD{{038&Dvt6(-4dIw zQmzwazEf`Sj#tbQ{zt;^lQSmMdgn-E&UD&UW%|AD&o8HH&3V0H5!RH9lC2YdpX?cX zZm3x@KR(J=qGHv<9dHNSffI9pd$va2kLbBO;10M0I|uatP%tT$hHb>~>tLowDsAs6 zYOoxR{=~xSrC}S9EewfLVw8$qF~n{T66I_!jo(I$a!44N{n*H2Hx#jphZKPhDICJzu~2NHo+2aT!~knX#>qTP(!5R#3=B5^!9d`^=0fIaESnpc_cCo} j=iui6Y5 maxLimit { + return ListFilter{}, false + } + filter.Limit = limit + } + + if raw := strings.TrimSpace(c.Query("role_name")); raw != "" { + filter.RoleName = raw + } + + return filter, true +} diff --git a/internal/admin/role/storage.go b/internal/admin/role/storage.go new file mode 100644 index 0000000..d0925c6 --- /dev/null +++ b/internal/admin/role/storage.go @@ -0,0 +1,11 @@ +package role + +import "context" + +type Repository interface { + List(ctx context.Context, filter ListFilter) (ListRoleDTO, error) + GetByID(ctx context.Context, id int64) (RoleDTO, error) + Create(ctx context.Context, dto CreateRoleDTO) (RoleDTO, error) + Update(ctx context.Context, id int64, dto UpdateRoleDTO) (RoleDTO, error) + Delete(ctx context.Context, id int64) error +} diff --git a/internal/handlers/manager/manager.go b/internal/handlers/manager/manager.go index 1817246..fa1cf5a 100755 --- a/internal/handlers/manager/manager.go +++ b/internal/handlers/manager/manager.go @@ -17,6 +17,8 @@ import ( provincedb "online-back/internal/admin/province/db" "online-back/internal/admin/reasonscard" reasonscarddb "online-back/internal/admin/reasonscard/db" + "online-back/internal/admin/role" + roledb "online-back/internal/admin/role/db" "online-back/internal/config" "online-back/internal/handlers" "online-back/pkg/logging" @@ -70,5 +72,6 @@ func adminHandlers(client *pgxpool.Pool, logger *logging.Logger) []handlers.Hand reasonscard.NewHandler(logger, reasonscarddb.NewRepository(client, logger)), loantype.NewHandler(logger, loantypedb.NewRepository(client, logger)), loansdocument.NewHandler(logger, loansdocumentdb.NewRepository(client, logger)), + role.NewHandler(logger, roledb.NewRepository(client, logger)), } }