From b0ada3115af8beb2c0150b122ef0922d0fa5c5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20=C3=81lvarez?= <86166683+ralvarezdev@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:06:09 -0400 Subject: [PATCH] refactor: Substituted REST Mapper implementation by REST Handlers --- config/rest/api/children.go | 10 --- config/rest/api/endpoints.go | 8 ++ config/rest/api/map.go | 17 ---- .../api/v1/auth/access-tokens/endpoints.go | 3 + .../api/v1/auth/access-tokens/handlers.go | 11 +++ .../v1/auth/access-tokens/interceptions.go | 14 ---- config/rest/api/v1/auth/access-tokens/map.go | 11 --- config/rest/api/v1/auth/children.go | 15 ---- config/rest/api/v1/auth/endpoints.go | 3 + config/rest/api/v1/auth/handlers.go | 12 +++ config/rest/api/v1/auth/interceptions.go | 17 ---- config/rest/api/v1/auth/map.go | 27 ------- .../rest/api/v1/auth/permissions/endpoints.go | 3 + .../rest/api/v1/auth/permissions/handlers.go | 14 ++++ .../api/v1/auth/permissions/interceptions.go | 19 ----- config/rest/api/v1/auth/permissions/map.go | 11 --- .../api/v1/auth/refresh-tokens/endpoints.go | 3 + .../api/v1/auth/refresh-tokens/handlers.go | 16 ++++ .../v1/auth/refresh-tokens/interceptions.go | 23 ------ config/rest/api/v1/auth/refresh-tokens/map.go | 11 --- .../api/v1/auth/role-permissions/endpoints.go | 3 + .../api/v1/auth/role-permissions/handlers.go | 11 +++ .../v1/auth/role-permissions/interceptions.go | 14 ---- .../rest/api/v1/auth/role-permissions/map.go | 11 --- config/rest/api/v1/auth/roles/endpoints.go | 3 + config/rest/api/v1/auth/roles/handlers.go | 15 ++++ .../rest/api/v1/auth/roles/interceptions.go | 20 ----- config/rest/api/v1/auth/roles/map.go | 11 --- .../rest/api/v1/auth/user-roles/endpoints.go | 3 + .../rest/api/v1/auth/user-roles/handlers.go | 13 +++ .../api/v1/auth/user-roles/interceptions.go | 18 ----- config/rest/api/v1/auth/user-roles/map.go | 11 --- config/rest/api/v1/children.go | 11 --- config/rest/api/v1/endpoints.go | 8 ++ config/rest/api/v1/map.go | 19 ----- config/rest/api/v1/users/children.go | 13 --- config/rest/api/v1/users/emails/endpoints.go | 3 + config/rest/api/v1/users/emails/handlers.go | 17 ++++ .../rest/api/v1/users/emails/interceptions.go | 28 ------- config/rest/api/v1/users/emails/map.go | 11 --- config/rest/api/v1/users/endpoints.go | 3 + config/rest/api/v1/users/handlers.go | 18 +++++ config/rest/api/v1/users/interceptions.go | 35 -------- config/rest/api/v1/users/map.go | 23 ------ .../api/v1/users/phone-numbers/endpoints.go | 3 + .../api/v1/users/phone-numbers/handlers.go | 14 ++++ .../v1/users/phone-numbers/interceptions.go | 21 ----- config/rest/api/v1/users/phone-numbers/map.go | 11 --- .../rest/api/v1/users/profiles/endpoints.go | 3 + config/rest/api/v1/users/profiles/handlers.go | 12 +++ .../api/v1/users/profiles/interceptions.go | 17 ---- config/rest/api/v1/users/profiles/map.go | 11 --- .../rest/api/v1/users/usernames/endpoints.go | 3 + .../rest/api/v1/users/usernames/handlers.go | 12 +++ .../api/v1/users/usernames/interceptions.go | 17 ---- config/rest/api/v1/users/usernames/map.go | 11 --- config/rest/children.go | 10 --- config/rest/map.go | 17 ---- go.mod | 23 ++++++ go.sum | 77 ++++++++++++++++++ types/rest/errors.go | 5 -- types/rest/handlers.go | 24 ++++++ types/rest/map.go | 81 ------------------- 63 files changed, 341 insertions(+), 601 deletions(-) delete mode 100644 config/rest/api/children.go create mode 100644 config/rest/api/endpoints.go delete mode 100644 config/rest/api/map.go create mode 100644 config/rest/api/v1/auth/access-tokens/handlers.go delete mode 100644 config/rest/api/v1/auth/access-tokens/interceptions.go delete mode 100644 config/rest/api/v1/auth/access-tokens/map.go delete mode 100644 config/rest/api/v1/auth/children.go create mode 100644 config/rest/api/v1/auth/handlers.go delete mode 100644 config/rest/api/v1/auth/interceptions.go delete mode 100644 config/rest/api/v1/auth/map.go create mode 100644 config/rest/api/v1/auth/permissions/handlers.go delete mode 100644 config/rest/api/v1/auth/permissions/interceptions.go delete mode 100644 config/rest/api/v1/auth/permissions/map.go create mode 100644 config/rest/api/v1/auth/refresh-tokens/handlers.go delete mode 100644 config/rest/api/v1/auth/refresh-tokens/interceptions.go delete mode 100644 config/rest/api/v1/auth/refresh-tokens/map.go create mode 100644 config/rest/api/v1/auth/role-permissions/handlers.go delete mode 100644 config/rest/api/v1/auth/role-permissions/interceptions.go delete mode 100644 config/rest/api/v1/auth/role-permissions/map.go create mode 100644 config/rest/api/v1/auth/roles/handlers.go delete mode 100644 config/rest/api/v1/auth/roles/interceptions.go delete mode 100644 config/rest/api/v1/auth/roles/map.go create mode 100644 config/rest/api/v1/auth/user-roles/handlers.go delete mode 100644 config/rest/api/v1/auth/user-roles/interceptions.go delete mode 100644 config/rest/api/v1/auth/user-roles/map.go delete mode 100644 config/rest/api/v1/children.go create mode 100644 config/rest/api/v1/endpoints.go delete mode 100644 config/rest/api/v1/map.go delete mode 100644 config/rest/api/v1/users/children.go create mode 100644 config/rest/api/v1/users/emails/handlers.go delete mode 100644 config/rest/api/v1/users/emails/interceptions.go delete mode 100644 config/rest/api/v1/users/emails/map.go create mode 100644 config/rest/api/v1/users/handlers.go delete mode 100644 config/rest/api/v1/users/interceptions.go delete mode 100644 config/rest/api/v1/users/map.go create mode 100644 config/rest/api/v1/users/phone-numbers/handlers.go delete mode 100644 config/rest/api/v1/users/phone-numbers/interceptions.go delete mode 100644 config/rest/api/v1/users/phone-numbers/map.go create mode 100644 config/rest/api/v1/users/profiles/handlers.go delete mode 100644 config/rest/api/v1/users/profiles/interceptions.go delete mode 100644 config/rest/api/v1/users/profiles/map.go create mode 100644 config/rest/api/v1/users/usernames/handlers.go delete mode 100644 config/rest/api/v1/users/usernames/interceptions.go delete mode 100644 config/rest/api/v1/users/usernames/map.go delete mode 100644 config/rest/children.go delete mode 100644 config/rest/map.go delete mode 100644 types/rest/errors.go create mode 100644 types/rest/handlers.go delete mode 100644 types/rest/map.go diff --git a/config/rest/api/children.go b/config/rest/api/children.go deleted file mode 100644 index 93a5ff5..0000000 --- a/config/rest/api/children.go +++ /dev/null @@ -1,10 +0,0 @@ -package api - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// API Gateway router versions children REST endpoints -var ( - V1 = rest.NewEndpoint("v1") -) diff --git a/config/rest/api/endpoints.go b/config/rest/api/endpoints.go new file mode 100644 index 0000000..2eb73f1 --- /dev/null +++ b/config/rest/api/endpoints.go @@ -0,0 +1,8 @@ +package api + +import ( + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Base is the base endpoint for the API REST endpoints +var Base = typesrest.NewEndpoint("api") diff --git a/config/rest/api/map.go b/config/rest/api/map.go deleted file mode 100644 index 1251dc0..0000000 --- a/config/rest/api/map.go +++ /dev/null @@ -1,17 +0,0 @@ -package api - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// ChildrenMaps is the map of the REST API endpoints of the API Gateway router versions -var ChildrenMaps = map[string]*rest.Map{ - V1.String(): v1.Map, -} - -// Map is the map of the REST API endpoints of the API Gateway router versions -var Map = rest.NewMap( - nil, - &ChildrenMaps, -) diff --git a/config/rest/api/v1/auth/access-tokens/endpoints.go b/config/rest/api/v1/auth/access-tokens/endpoints.go index 2a5689f..55f6dd7 100644 --- a/config/rest/api/v1/auth/access-tokens/endpoints.go +++ b/config/rest/api/v1/auth/access-tokens/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service access tokens REST endpoints +var Base = typesrest.NewEndpoint("access-tokens") + // Auth service access tokens REST endpoints var ( ValidByJwtId = typesrest.NewEndpoint( diff --git a/config/rest/api/v1/auth/access-tokens/handlers.go b/config/rest/api/v1/auth/access-tokens/handlers.go new file mode 100644 index 0000000..a4eac0d --- /dev/null +++ b/config/rest/api/v1/auth/access-tokens/handlers.go @@ -0,0 +1,11 @@ +package access_tokens + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service access tokens endpoints handlers +var ( + IsAccessTokenValidHandler = typesrest.NewHandler(ValidByJwtId, grpcauth.IsAccessTokenValid) +) diff --git a/config/rest/api/v1/auth/access-tokens/interceptions.go b/config/rest/api/v1/auth/access-tokens/interceptions.go deleted file mode 100644 index 0c4beba..0000000 --- a/config/rest/api/v1/auth/access-tokens/interceptions.go +++ /dev/null @@ -1,14 +0,0 @@ -package access_tokens - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service access tokens gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - ValidByJwtId.String(): { - rest.GET: auth.IsAccessTokenValid, - }, -} diff --git a/config/rest/api/v1/auth/access-tokens/map.go b/config/rest/api/v1/auth/access-tokens/map.go deleted file mode 100644 index 98647ac..0000000 --- a/config/rest/api/v1/auth/access-tokens/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package access_tokens - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service access tokens -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/auth/children.go b/config/rest/api/v1/auth/children.go deleted file mode 100644 index 4255a38..0000000 --- a/config/rest/api/v1/auth/children.go +++ /dev/null @@ -1,15 +0,0 @@ -package auth - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Auth service children REST endpoints -var ( - AccessTokens = rest.NewEndpoint("access-tokens") - RefreshTokens = rest.NewEndpoint("refresh-tokens") - Permissions = rest.NewEndpoint("permissions") - RolePermissions = rest.NewEndpoint("role-permissions") - Roles = rest.NewEndpoint("roles") - UserRoles = rest.NewEndpoint("user-roles") -) diff --git a/config/rest/api/v1/auth/endpoints.go b/config/rest/api/v1/auth/endpoints.go index 81e4578..93ed0d4 100644 --- a/config/rest/api/v1/auth/endpoints.go +++ b/config/rest/api/v1/auth/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service REST endpoints +var Base = typesrest.NewEndpoint("auth") + // Auth service REST endpoints var ( LogIn = typesrest.NewEndpoint("log-in") diff --git a/config/rest/api/v1/auth/handlers.go b/config/rest/api/v1/auth/handlers.go new file mode 100644 index 0000000..a4d2947 --- /dev/null +++ b/config/rest/api/v1/auth/handlers.go @@ -0,0 +1,12 @@ +package auth + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service endpoints handlers +var ( + LogInHandler = typesrest.NewHandler(LogIn, grpcauth.LogIn) + LogOutHandler = typesrest.NewHandler(LogOut, grpcauth.LogOut) +) diff --git a/config/rest/api/v1/auth/interceptions.go b/config/rest/api/v1/auth/interceptions.go deleted file mode 100644 index f1564a0..0000000 --- a/config/rest/api/v1/auth/interceptions.go +++ /dev/null @@ -1,17 +0,0 @@ -package auth - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - LogIn.String(): { - rest.POST: auth.LogIn, - }, - LogOut.String(): { - rest.POST: auth.LogOut, - }, -} diff --git a/config/rest/api/v1/auth/map.go b/config/rest/api/v1/auth/map.go deleted file mode 100644 index 029c86c..0000000 --- a/config/rest/api/v1/auth/map.go +++ /dev/null @@ -1,27 +0,0 @@ -package auth - -import ( - accesstokens "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/access-tokens" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/permissions" - refreshtokens "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/refresh-tokens" - rolepermissions "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/role-permissions" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/roles" - userroles "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth/user-roles" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// ChildrenMaps is the map of the REST API endpoints of the auth service -var ChildrenMaps = map[string]*rest.Map{ - AccessTokens.String(): accesstokens.Map, - RefreshTokens.String(): refreshtokens.Map, - Permissions.String(): permissions.Map, - RolePermissions.String(): rolepermissions.Map, - Roles.String(): roles.Map, - UserRoles.String(): userroles.Map, -} - -// Map is the map of the REST API endpoints of the auth service -var Map = rest.NewMap( - &Interceptions, - &ChildrenMaps, -) diff --git a/config/rest/api/v1/auth/permissions/endpoints.go b/config/rest/api/v1/auth/permissions/endpoints.go index 8adca49..d76a66b 100644 --- a/config/rest/api/v1/auth/permissions/endpoints.go +++ b/config/rest/api/v1/auth/permissions/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service permissions REST endpoints +var Base = typesrest.NewEndpoint("permissions") + // Auth service permissions REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/auth/permissions/handlers.go b/config/rest/api/v1/auth/permissions/handlers.go new file mode 100644 index 0000000..bfede67 --- /dev/null +++ b/config/rest/api/v1/auth/permissions/handlers.go @@ -0,0 +1,14 @@ +package permissions + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service permissions endpoints handlers +var ( + GetPermissionsHandler = typesrest.NewHandler(Relative, grpcauth.GetPermissions) + AddPermissionHandler = typesrest.NewHandler(Relative, grpcauth.AddPermission) + GetPermissionHandler = typesrest.NewHandler(ByPermissionId, grpcauth.GetPermission) + RevokePermissionHandler = typesrest.NewHandler(ByPermissionId, grpcauth.RevokePermission) +) diff --git a/config/rest/api/v1/auth/permissions/interceptions.go b/config/rest/api/v1/auth/permissions/interceptions.go deleted file mode 100644 index f4fb197..0000000 --- a/config/rest/api/v1/auth/permissions/interceptions.go +++ /dev/null @@ -1,19 +0,0 @@ -package permissions - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service permissions gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.GET: auth.GetPermissions, - rest.POST: auth.AddPermission, - }, - ByPermissionId.String(): { - rest.GET: auth.GetPermission, - rest.DELETE: auth.RevokePermission, - }, -} diff --git a/config/rest/api/v1/auth/permissions/map.go b/config/rest/api/v1/auth/permissions/map.go deleted file mode 100644 index 52defb7..0000000 --- a/config/rest/api/v1/auth/permissions/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package permissions - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service permissions -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/auth/refresh-tokens/endpoints.go b/config/rest/api/v1/auth/refresh-tokens/endpoints.go index b106d35..b060320 100644 --- a/config/rest/api/v1/auth/refresh-tokens/endpoints.go +++ b/config/rest/api/v1/auth/refresh-tokens/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service refresh tokens REST endpoints +var Base = typesrest.NewEndpoint("refresh-tokens") + // Auth service refresh tokens REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/auth/refresh-tokens/handlers.go b/config/rest/api/v1/auth/refresh-tokens/handlers.go new file mode 100644 index 0000000..d90e203 --- /dev/null +++ b/config/rest/api/v1/auth/refresh-tokens/handlers.go @@ -0,0 +1,16 @@ +package refresh_tokens + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service refresh tokens endpoints handlers +var ( + RefreshTokenHandler = typesrest.NewHandler(Relative, grpcauth.RefreshToken) + GetRefreshTokensInformationHandler = typesrest.NewHandler(Relative, grpcauth.GetRefreshTokensInformation) + RevokeRefreshTokensHandler = typesrest.NewHandler(Relative, grpcauth.RevokeRefreshTokens) + GetRefreshTokenInformationHandler = typesrest.NewHandler(ByJwtId, grpcauth.GetRefreshTokenInformation) + RevokeRefreshTokenHandler = typesrest.NewHandler(ByJwtId, grpcauth.RevokeRefreshToken) + IsRefreshTokenValidHandler = typesrest.NewHandler(ValidByJwtId, grpcauth.IsRefreshTokenValid) +) diff --git a/config/rest/api/v1/auth/refresh-tokens/interceptions.go b/config/rest/api/v1/auth/refresh-tokens/interceptions.go deleted file mode 100644 index ad26780..0000000 --- a/config/rest/api/v1/auth/refresh-tokens/interceptions.go +++ /dev/null @@ -1,23 +0,0 @@ -package refresh_tokens - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service refresh tokens gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.POST: auth.RefreshToken, - rest.GET: auth.GetRefreshTokensInformation, - rest.DELETE: auth.RevokeRefreshTokens, - }, - ByJwtId.String(): { - rest.GET: auth.GetRefreshTokenInformation, - rest.DELETE: auth.RevokeRefreshToken, - }, - ValidByJwtId.String(): { - rest.GET: auth.IsRefreshTokenValid, - }, -} diff --git a/config/rest/api/v1/auth/refresh-tokens/map.go b/config/rest/api/v1/auth/refresh-tokens/map.go deleted file mode 100644 index def0375..0000000 --- a/config/rest/api/v1/auth/refresh-tokens/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package refresh_tokens - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service refresh tokens -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/auth/role-permissions/endpoints.go b/config/rest/api/v1/auth/role-permissions/endpoints.go index 6e6ae46..d9839b1 100644 --- a/config/rest/api/v1/auth/role-permissions/endpoints.go +++ b/config/rest/api/v1/auth/role-permissions/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service role permissions REST endpoints +var Base = typesrest.NewEndpoint("role-permissions") + // Auth service role permissions REST endpoints var ( ByRoleId = typesrest.NewEndpoint( diff --git a/config/rest/api/v1/auth/role-permissions/handlers.go b/config/rest/api/v1/auth/role-permissions/handlers.go new file mode 100644 index 0000000..9a63e19 --- /dev/null +++ b/config/rest/api/v1/auth/role-permissions/handlers.go @@ -0,0 +1,11 @@ +package role_permissions + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service role permissions endpoints handlers +var ( + RevokeRolePermissionHandler = typesrest.NewHandler(ByRoleId, grpcauth.RevokeRolePermission) +) diff --git a/config/rest/api/v1/auth/role-permissions/interceptions.go b/config/rest/api/v1/auth/role-permissions/interceptions.go deleted file mode 100644 index 2ffa862..0000000 --- a/config/rest/api/v1/auth/role-permissions/interceptions.go +++ /dev/null @@ -1,14 +0,0 @@ -package role_permissions - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service refresh tokens gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - ByRoleId.String(): { - rest.DELETE: auth.RevokeRolePermission, - }, -} diff --git a/config/rest/api/v1/auth/role-permissions/map.go b/config/rest/api/v1/auth/role-permissions/map.go deleted file mode 100644 index 33cc60c..0000000 --- a/config/rest/api/v1/auth/role-permissions/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package role_permissions - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service role permissions -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/auth/roles/endpoints.go b/config/rest/api/v1/auth/roles/endpoints.go index 6886a2e..cd77695 100644 --- a/config/rest/api/v1/auth/roles/endpoints.go +++ b/config/rest/api/v1/auth/roles/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service roles REST endpoints +var Base = typesrest.NewEndpoint("roles") + // Auth service roles REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/auth/roles/handlers.go b/config/rest/api/v1/auth/roles/handlers.go new file mode 100644 index 0000000..5dd688c --- /dev/null +++ b/config/rest/api/v1/auth/roles/handlers.go @@ -0,0 +1,15 @@ +package roles + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service roles endpoints handlers +var ( + AddRoleHandler = typesrest.NewHandler(Relative, grpcauth.AddRole) + GetRolesHandler = typesrest.NewHandler(Relative, grpcauth.GetRoles) + AddRolePermissionHandler = typesrest.NewHandler(ByRoleId, grpcauth.AddRolePermission) + GetRolePermissionsHandler = typesrest.NewHandler(ByRoleId, grpcauth.GetRolePermissions) + RevokeRoleHandler = typesrest.NewHandler(ByRoleId, grpcauth.RevokeRole) +) diff --git a/config/rest/api/v1/auth/roles/interceptions.go b/config/rest/api/v1/auth/roles/interceptions.go deleted file mode 100644 index a94ddd9..0000000 --- a/config/rest/api/v1/auth/roles/interceptions.go +++ /dev/null @@ -1,20 +0,0 @@ -package roles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service roles gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.POST: auth.AddRole, - rest.GET: auth.GetRoles, - }, - ByRoleId.String(): { - rest.POST: auth.AddRolePermission, - rest.GET: auth.GetRolePermissions, - rest.DELETE: auth.RevokeRole, - }, -} diff --git a/config/rest/api/v1/auth/roles/map.go b/config/rest/api/v1/auth/roles/map.go deleted file mode 100644 index f7505bf..0000000 --- a/config/rest/api/v1/auth/roles/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package roles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service roles -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/auth/user-roles/endpoints.go b/config/rest/api/v1/auth/user-roles/endpoints.go index 10170bc..71ca477 100644 --- a/config/rest/api/v1/auth/user-roles/endpoints.go +++ b/config/rest/api/v1/auth/user-roles/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the auth service user roles REST endpoints +var Base = typesrest.NewEndpoint("user-roles") + // Auth service user roles REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/auth/user-roles/handlers.go b/config/rest/api/v1/auth/user-roles/handlers.go new file mode 100644 index 0000000..3746f5e --- /dev/null +++ b/config/rest/api/v1/auth/user-roles/handlers.go @@ -0,0 +1,13 @@ +package user_roles + +import ( + grpcauth "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Auth service user roles endpoints handlers +var ( + AddUserRoleHandler = typesrest.NewHandler(Relative, grpcauth.AddUserRole) + RevokeUserRoleHandler = typesrest.NewHandler(Relative, grpcauth.RevokeUserRole) + GetUserRolesHandler = typesrest.NewHandler(ByUserId, grpcauth.GetUserRoles) +) diff --git a/config/rest/api/v1/auth/user-roles/interceptions.go b/config/rest/api/v1/auth/user-roles/interceptions.go deleted file mode 100644 index 133a375..0000000 --- a/config/rest/api/v1/auth/user-roles/interceptions.go +++ /dev/null @@ -1,18 +0,0 @@ -package user_roles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the auth service refresh tokens gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.POST: auth.AddUserRole, - rest.DELETE: auth.RevokeUserRole, - }, - ByUserId.String(): { - rest.GET: auth.GetUserRoles, - }, -} diff --git a/config/rest/api/v1/auth/user-roles/map.go b/config/rest/api/v1/auth/user-roles/map.go deleted file mode 100644 index 64b2f47..0000000 --- a/config/rest/api/v1/auth/user-roles/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package user_roles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the auth service user roles -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/children.go b/config/rest/api/v1/children.go deleted file mode 100644 index d62a4a7..0000000 --- a/config/rest/api/v1/children.go +++ /dev/null @@ -1,11 +0,0 @@ -package v1 - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// API Gateway router version 1 children REST endpoints -var ( - Auth = rest.NewEndpoint("auth") - Users = rest.NewEndpoint("users") -) diff --git a/config/rest/api/v1/endpoints.go b/config/rest/api/v1/endpoints.go new file mode 100644 index 0000000..4b3a013 --- /dev/null +++ b/config/rest/api/v1/endpoints.go @@ -0,0 +1,8 @@ +package v1 + +import ( + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Base is the base endpoint for the API version 1 REST endpoints +var Base = typesrest.NewEndpoint("v1") diff --git a/config/rest/api/v1/map.go b/config/rest/api/v1/map.go deleted file mode 100644 index e0afbaa..0000000 --- a/config/rest/api/v1/map.go +++ /dev/null @@ -1,19 +0,0 @@ -package v1 - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/auth" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/users" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// ChildrenMaps is the map of the REST API endpoints of the API Gateway router version 1 -var ChildrenMaps = map[string]*rest.Map{ - Auth.String(): auth.Map, - Users.String(): users.Map, -} - -// Map is the map of the REST API endpoints of the API Gateway router version 1 -var Map = rest.NewMap( - nil, - &ChildrenMaps, -) diff --git a/config/rest/api/v1/users/children.go b/config/rest/api/v1/users/children.go deleted file mode 100644 index fb189df..0000000 --- a/config/rest/api/v1/users/children.go +++ /dev/null @@ -1,13 +0,0 @@ -package users - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// User service children REST endpoints -var ( - Emails = rest.NewEndpoint("emails") - PhoneNumbers = rest.NewEndpoint("phone-numbers") - Profiles = rest.NewEndpoint("profiles") - Usernames = rest.NewEndpoint("usernames") -) diff --git a/config/rest/api/v1/users/emails/endpoints.go b/config/rest/api/v1/users/emails/endpoints.go index 7d44315..5028c67 100644 --- a/config/rest/api/v1/users/emails/endpoints.go +++ b/config/rest/api/v1/users/emails/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the user service emails REST endpoints +var Base = typesrest.NewEndpoint("emails") + // User service emails REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/users/emails/handlers.go b/config/rest/api/v1/users/emails/handlers.go new file mode 100644 index 0000000..d54895f --- /dev/null +++ b/config/rest/api/v1/users/emails/handlers.go @@ -0,0 +1,17 @@ +package emails + +import ( + grpcuser "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Users service emails endpoints handlers +var ( + GetActiveEmailsHandler = typesrest.NewHandler(Relative, grpcuser.GetActiveEmails) + AddEmailHandler = typesrest.NewHandler(Relative, grpcuser.AddEmail) + GetPrimaryEmailHandler = typesrest.NewHandler(Primary, grpcuser.GetPrimaryEmail) + ChangePrimaryEmailHandler = typesrest.NewHandler(Primary, grpcuser.ChangePrimaryEmail) + DeleteEmailHandler = typesrest.NewHandler(ByEmail, grpcuser.DeleteEmail) + SendVerificationEmailHandler = typesrest.NewHandler(SendVerification, grpcuser.SendVerificationEmail) + VerifyEmailHandler = typesrest.NewHandler(VerifyByToken, grpcuser.VerifyEmail) +) diff --git a/config/rest/api/v1/users/emails/interceptions.go b/config/rest/api/v1/users/emails/interceptions.go deleted file mode 100644 index 492bd82..0000000 --- a/config/rest/api/v1/users/emails/interceptions.go +++ /dev/null @@ -1,28 +0,0 @@ -package emails - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the user service emails gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.GET: user.GetActiveEmails, - rest.POST: user.AddEmail, - }, - Primary.String(): { - rest.GET: user.GetPrimaryEmail, - rest.PUT: user.ChangePrimaryEmail, - }, - ByEmail.String(): { - rest.DELETE: user.DeleteEmail, - }, - SendVerification.String(): { - rest.POST: user.SendVerificationEmail, - }, - VerifyByToken.String(): { - rest.POST: user.VerifyEmail, - }, -} diff --git a/config/rest/api/v1/users/emails/map.go b/config/rest/api/v1/users/emails/map.go deleted file mode 100644 index a401d4a..0000000 --- a/config/rest/api/v1/users/emails/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package emails - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the user service emails -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/users/endpoints.go b/config/rest/api/v1/users/endpoints.go index ae890f1..58d86f2 100644 --- a/config/rest/api/v1/users/endpoints.go +++ b/config/rest/api/v1/users/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the user service REST endpoints +var Base = typesrest.NewEndpoint("users") + // Users service REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/users/handlers.go b/config/rest/api/v1/users/handlers.go new file mode 100644 index 0000000..2a9ead2 --- /dev/null +++ b/config/rest/api/v1/users/handlers.go @@ -0,0 +1,18 @@ +package users + +import ( + configusers "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" + "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Users service endpoints handlers +var ( + UpdateUserHandler = rest.NewHandler(Relative, configusers.UpdateUser) + SignUpHandler = rest.NewHandler(SignUp, configusers.SignUp) + GetUserIdByUsernameHandler = rest.NewHandler(UserIdByUsername, configusers.GetUserIdByUsername) + ChangePasswordHandler = rest.NewHandler(Password, configusers.ChangePassword) + ChangeUsernameHandler = rest.NewHandler(Username, configusers.ChangeUsername) + ForgotPasswordHandler = rest.NewHandler(ForgotPassword, configusers.ForgotPassword) + PostResetPasswordHandler = rest.NewHandler(ResetPasswordByToken, configusers.ResetPassword) + DeleteAccountHandler = rest.NewHandler(DeleteAccount, configusers.DeleteUser) +) diff --git a/config/rest/api/v1/users/interceptions.go b/config/rest/api/v1/users/interceptions.go deleted file mode 100644 index 0d2d338..0000000 --- a/config/rest/api/v1/users/interceptions.go +++ /dev/null @@ -1,35 +0,0 @@ -package users - -import ( - configusers "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the user service gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.PATCH: configusers.UpdateUser, - }, - SignUp.String(): { - rest.POST: configusers.SignUp, - }, - UserIdByUsername.String(): { - rest.GET: configusers.GetUserIdByUsername, - }, - Password.String(): { - rest.PUT: configusers.ChangePassword, - }, - Username.String(): { - rest.PUT: configusers.ChangeUsername, - }, - ForgotPassword.String(): { - rest.POST: configusers.ForgotPassword, - }, - ResetPasswordByToken.String(): { - rest.POST: configusers.ResetPassword, - }, - DeleteAccount.String(): { - rest.DELETE: configusers.DeleteUser, - }, -} diff --git a/config/rest/api/v1/users/map.go b/config/rest/api/v1/users/map.go deleted file mode 100644 index 2027c99..0000000 --- a/config/rest/api/v1/users/map.go +++ /dev/null @@ -1,23 +0,0 @@ -package users - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/users/emails" - phonenumbers "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/users/phone-numbers" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/users/profiles" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api/v1/users/usernames" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// ChildrenMaps is the map of the REST API endpoints of the auth service -var ChildrenMaps = map[string]*rest.Map{ - Emails.String(): emails.Map, - PhoneNumbers.String(): phonenumbers.Map, - Profiles.String(): profiles.Map, - Usernames.String(): usernames.Map, -} - -// Map is the map of the REST API endpoints of the auth service -var Map = rest.NewMap( - &Interceptions, - &ChildrenMaps, -) diff --git a/config/rest/api/v1/users/phone-numbers/endpoints.go b/config/rest/api/v1/users/phone-numbers/endpoints.go index 921eb55..1dba426 100644 --- a/config/rest/api/v1/users/phone-numbers/endpoints.go +++ b/config/rest/api/v1/users/phone-numbers/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the user service phone numbers REST endpoints +var Base = typesrest.NewEndpoint("phone-numbers") + // User service phone numbers REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/users/phone-numbers/handlers.go b/config/rest/api/v1/users/phone-numbers/handlers.go new file mode 100644 index 0000000..6da70ed --- /dev/null +++ b/config/rest/api/v1/users/phone-numbers/handlers.go @@ -0,0 +1,14 @@ +package phone_numbers + +import ( + grpcuser "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Users service phone numbers endpoints handlers +var ( + ChangePhoneNumberHandler = typesrest.NewHandler(Relative, grpcuser.ChangePhoneNumber) + GetPhoneNumberHandler = typesrest.NewHandler(Relative, grpcuser.GetPhoneNumber) + SendVerificationSMSHandler = typesrest.NewHandler(SendVerification, grpcuser.SendVerificationSMS) + VerifyPhoneNumberHandler = typesrest.NewHandler(VerifyByToken, grpcuser.VerifyPhoneNumber) +) diff --git a/config/rest/api/v1/users/phone-numbers/interceptions.go b/config/rest/api/v1/users/phone-numbers/interceptions.go deleted file mode 100644 index 76d8954..0000000 --- a/config/rest/api/v1/users/phone-numbers/interceptions.go +++ /dev/null @@ -1,21 +0,0 @@ -package phone_numbers - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the user service phone numbers gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.PUT: user.ChangePhoneNumber, - rest.GET: user.GetPhoneNumber, - }, - SendVerification.String(): { - rest.POST: user.SendVerificationSMS, - }, - VerifyByToken.String(): { - rest.POST: user.VerifyPhoneNumber, - }, -} diff --git a/config/rest/api/v1/users/phone-numbers/map.go b/config/rest/api/v1/users/phone-numbers/map.go deleted file mode 100644 index a4fd666..0000000 --- a/config/rest/api/v1/users/phone-numbers/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package phone_numbers - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the user service phone numbers -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/users/profiles/endpoints.go b/config/rest/api/v1/users/profiles/endpoints.go index 5093a31..df6447d 100644 --- a/config/rest/api/v1/users/profiles/endpoints.go +++ b/config/rest/api/v1/users/profiles/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the user service profiles REST endpoints +var Base = typesrest.NewEndpoint("profiles") + // User service profiles REST endpoints var ( Relative = typesrest.NewEndpoint("") diff --git a/config/rest/api/v1/users/profiles/handlers.go b/config/rest/api/v1/users/profiles/handlers.go new file mode 100644 index 0000000..558788c --- /dev/null +++ b/config/rest/api/v1/users/profiles/handlers.go @@ -0,0 +1,12 @@ +package profiles + +import ( + grpcuser "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Users service profiles endpoints handlers +var ( + GetMyProfileHandler = typesrest.NewHandler(Relative, grpcuser.GetMyProfile) + GetProfileHandler = typesrest.NewHandler(ByUsername, grpcuser.GetProfile) +) diff --git a/config/rest/api/v1/users/profiles/interceptions.go b/config/rest/api/v1/users/profiles/interceptions.go deleted file mode 100644 index 00ee9a5..0000000 --- a/config/rest/api/v1/users/profiles/interceptions.go +++ /dev/null @@ -1,17 +0,0 @@ -package profiles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the user service profiles gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - Relative.String(): { - rest.GET: user.GetMyProfile, - }, - ByUsername.String(): { - rest.GET: user.GetProfile, - }, -} diff --git a/config/rest/api/v1/users/profiles/map.go b/config/rest/api/v1/users/profiles/map.go deleted file mode 100644 index 452bc5a..0000000 --- a/config/rest/api/v1/users/profiles/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package profiles - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the user service profiles -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/api/v1/users/usernames/endpoints.go b/config/rest/api/v1/users/usernames/endpoints.go index a0bd68c..22e4946 100644 --- a/config/rest/api/v1/users/usernames/endpoints.go +++ b/config/rest/api/v1/users/usernames/endpoints.go @@ -4,6 +4,9 @@ import ( typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" ) +// Base is the base endpoint for the user service usernames REST endpoints +var Base = typesrest.NewEndpoint("usernames") + // User service usernames REST endpoints var ( ByUserId = typesrest.NewEndpoint( diff --git a/config/rest/api/v1/users/usernames/handlers.go b/config/rest/api/v1/users/usernames/handlers.go new file mode 100644 index 0000000..7e753a3 --- /dev/null +++ b/config/rest/api/v1/users/usernames/handlers.go @@ -0,0 +1,12 @@ +package usernames + +import ( + grpcuser "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" + typesrest "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" +) + +// Users service usernames endpoints handlers +var ( + GetUsernameByUserIdHandler = typesrest.NewHandler(ByUserId, grpcuser.GetUsernameByUserId) + UsernameExistsHandler = typesrest.NewHandler(ExistsByUsername, grpcuser.UsernameExists) +) diff --git a/config/rest/api/v1/users/usernames/interceptions.go b/config/rest/api/v1/users/usernames/interceptions.go deleted file mode 100644 index e5ee530..0000000 --- a/config/rest/api/v1/users/usernames/interceptions.go +++ /dev/null @@ -1,17 +0,0 @@ -package usernames - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/grpc/user" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Interceptions is the map of the REST API endpoints to the user service usernames gRPC methods -var Interceptions = map[string]map[rest.Method]grpc.Method{ - ByUserId.String(): { - rest.GET: user.GetUsernameByUserId, - }, - ExistsByUsername.String(): { - rest.GET: user.UsernameExists, - }, -} diff --git a/config/rest/api/v1/users/usernames/map.go b/config/rest/api/v1/users/usernames/map.go deleted file mode 100644 index 3142df4..0000000 --- a/config/rest/api/v1/users/usernames/map.go +++ /dev/null @@ -1,11 +0,0 @@ -package usernames - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// Map is the map of the REST API endpoints of the user service usernames -var Map = rest.NewMap( - &Interceptions, - nil, -) diff --git a/config/rest/children.go b/config/rest/children.go deleted file mode 100644 index 2fb6a08..0000000 --- a/config/rest/children.go +++ /dev/null @@ -1,10 +0,0 @@ -package rest - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// API Gateway router children REST endpoints -var ( - Api = rest.NewEndpoint("api") -) diff --git a/config/rest/map.go b/config/rest/map.go deleted file mode 100644 index 29614b5..0000000 --- a/config/rest/map.go +++ /dev/null @@ -1,17 +0,0 @@ -package rest - -import ( - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/config/rest/api" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/rest" -) - -// ChildrenMaps is the map of the REST API endpoints of the API Gateway router -var ChildrenMaps = map[string]*rest.Map{ - Api.String(): api.Map, -} - -// Map is the map of the REST API endpoints of the API Gateway router -var Map = rest.NewMap( - nil, - &ChildrenMaps, -) diff --git a/go.mod b/go.mod index d52fc3e..624c3a6 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,36 @@ module github.com/pixel-plaza-dev/uru-databases-2-protobuf-common go 1.23.2 require ( + github.com/gin-gonic/gin v1.10.0 google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.35.1 ) require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a8432dc..e9aede0 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,77 @@ +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= @@ -12,3 +82,10 @@ google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/types/rest/errors.go b/types/rest/errors.go deleted file mode 100644 index d1b536d..0000000 --- a/types/rest/errors.go +++ /dev/null @@ -1,5 +0,0 @@ -package rest - -var ( - MissingEndpointInterception = "missing endpoint interception: %v [%v]" -) diff --git a/types/rest/handlers.go b/types/rest/handlers.go new file mode 100644 index 0000000..1125216 --- /dev/null +++ b/types/rest/handlers.go @@ -0,0 +1,24 @@ +package rest + +import ( + "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" +) + +type ( + // Handler is a handler for a REST endpoint + Handler struct { + Endpoint *Endpoint + GRPCMethod grpc.Method + } +) + +// NewHandler creates a new handler +func NewHandler( + endpoint *Endpoint, + grpcMethod grpc.Method, +) *Handler { + return &Handler{ + Endpoint: endpoint, + GRPCMethod: grpcMethod, + } +} diff --git a/types/rest/map.go b/types/rest/map.go deleted file mode 100644 index 1744a66..0000000 --- a/types/rest/map.go +++ /dev/null @@ -1,81 +0,0 @@ -package rest - -import ( - "fmt" - "github.com/pixel-plaza-dev/uru-databases-2-protobuf-common/types/grpc" - "strings" -) - -type ( - // Mapper is the interface for the REST map - Mapper interface { - Traverse(debug bool, relativeURI string, restMethod Method) (*grpc.Method, error) - } - - // Map struct for the REST endpoints - Map struct { - Interceptions *map[string]map[Method]grpc.Method - ChildrenMaps *map[string]*Map - } -) - -// NewMap creates a new REST map -func NewMap(interceptions *map[string]map[Method]grpc.Method, childrenMaps *map[string]*Map) *Map { - return &Map{ - Interceptions: interceptions, - ChildrenMaps: childrenMaps, - } -} - -// Traverse traverses the REST map -func (m *Map) Traverse(debug bool, relativeURI string, restMethod Method) (*grpc.Method, error) { - // Check if the whole relative URI is in the interceptions map - if m.Interceptions != nil { - if methodMap, ok := (*m.Interceptions)[relativeURI]; ok { - if grpcMethod, ok := methodMap[restMethod]; ok { - return &grpcMethod, nil - } - } - } - - // Get the index of the possible URI - var possibleBaseUri, possibleUri string - possibleUriIndex := strings.Index(relativeURI[1:], "/") - if possibleUriIndex != -1 { - possibleUriIndex++ - } - - // Check if the URI is an endpoint or a URI with a parameter - if possibleUriIndex == -1 { - possibleUri = "/" - } else { - possibleBaseUri = relativeURI[:possibleUriIndex] - possibleUri = relativeURI[possibleUriIndex:] - } - - // Check if debug is enabled - if debug { - // Print the possible base URI and URI - fmt.Printf("Possible base URI: %s\n", possibleBaseUri) - fmt.Printf("Possible URI: %s\n", possibleUri) - } - - if m.Interceptions != nil { - // Check if the possible URI is in the interceptions map - if methodMap, ok := (*m.Interceptions)[possibleUri]; ok { - if grpcMethod, ok := methodMap[restMethod]; ok { - return &grpcMethod, nil - } - } - } - - if m.ChildrenMaps != nil { - // Check if the possible base URI is in the children maps - // If it is, traverse the child map - if childMap, ok := (*m.ChildrenMaps)[possibleBaseUri]; ok { - return childMap.Traverse(debug, possibleUri, restMethod) - } - } - - return nil, fmt.Errorf(MissingEndpointInterception, relativeURI, restMethod) -}