UPDATE: get role content
All checks were successful
Build and Release / release (push) Successful in 1m31s
All checks were successful
Build and Release / release (push) Successful in 1m31s
This commit is contained in:
@@ -79,16 +79,19 @@ func (s *FiberServer) SetupServer(sqlPg sqlc.DBTX, sqlTile *sql.DB, redis cache.
|
||||
// service setup
|
||||
authService := services.NewAuthService(userRepo, roleRepo, tokenRepo, redis)
|
||||
userService := services.NewUserService(userRepo, roleRepo)
|
||||
roleService := services.NewRoleService(roleRepo)
|
||||
tileService := services.NewTileService(tileRepo)
|
||||
|
||||
// controller setup
|
||||
authController := controllers.NewAuthController(authService, oauth)
|
||||
userController := controllers.NewUserController(userService)
|
||||
tileController := controllers.NewTileController(tileService)
|
||||
roleController := controllers.NewRoleController(roleService)
|
||||
|
||||
// route setup
|
||||
routes.AuthRoutes(s.App, authController, userRepo)
|
||||
routes.UserRoutes(s.App, userController, userRepo)
|
||||
routes.RoleRoutes(s.App, roleController, userRepo)
|
||||
routes.TileRoutes(s.App, tileController)
|
||||
routes.NotFoundRoute(s.App)
|
||||
}
|
||||
|
||||
77
docs/docs.go
77
docs/docs.go
@@ -362,6 +362,83 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get a list of all roles in the system",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Roles"
|
||||
],
|
||||
"summary": "Get all roles",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get detailed information about a specific role",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Roles"
|
||||
],
|
||||
"summary": "Get role by ID",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Role ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/tiles/metadata": {
|
||||
"get": {
|
||||
"description": "Retrieve map metadata",
|
||||
|
||||
@@ -355,6 +355,83 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get a list of all roles in the system",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Roles"
|
||||
],
|
||||
"summary": "Get all roles",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get detailed information about a specific role",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Roles"
|
||||
],
|
||||
"summary": "Get role by ID",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Role ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/tiles/metadata": {
|
||||
"get": {
|
||||
"description": "Retrieve map metadata",
|
||||
|
||||
@@ -398,6 +398,54 @@ paths:
|
||||
summary: Verify a security token
|
||||
tags:
|
||||
- Auth
|
||||
/roles:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Get a list of all roles in the system
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/history-api_internal_dtos_response.CommonResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/history-api_internal_dtos_response.CommonResponse'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Get all roles
|
||||
tags:
|
||||
- Roles
|
||||
/roles/{id}:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Get detailed information about a specific role
|
||||
parameters:
|
||||
- description: Role ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/history-api_internal_dtos_response.CommonResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/history-api_internal_dtos_response.CommonResponse'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Get role by ID
|
||||
tags:
|
||||
- Roles
|
||||
/tiles/{z}/{x}/{y}:
|
||||
get:
|
||||
description: Fetch vector or raster map tile data by Z, X, Y coordinates
|
||||
|
||||
73
internal/controllers/roleController.go
Normal file
73
internal/controllers/roleController.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"history-api/internal/dtos/response"
|
||||
"history-api/internal/services"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type RoleController struct {
|
||||
service services.RoleService
|
||||
}
|
||||
|
||||
func NewRoleController(svc services.RoleService) *RoleController {
|
||||
return &RoleController{service: svc}
|
||||
}
|
||||
|
||||
// GetRoleById handles fetching a single role by ID.
|
||||
// @Summary Get role by ID
|
||||
// @Description Get detailed information about a specific role
|
||||
// @Tags Roles
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Role ID"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Router /roles/{id} [get]
|
||||
func (h *RoleController) GetRoleById(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
RoleId := c.Params("id")
|
||||
res, err := h.service.GetRoleByID(ctx, RoleId)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||
Status: true,
|
||||
Data: res,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// GetAllRole handles fetching all roles.
|
||||
// @Summary Get all roles
|
||||
// @Description Get a list of all roles in the system
|
||||
// @Tags Roles
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} response.CommonResponse
|
||||
// @Failure 500 {object} response.CommonResponse
|
||||
// @Router /roles [get]
|
||||
func (h *RoleController) GetAllRole(c fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
res, err := h.service.GetAllRole(ctx)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
|
||||
Status: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||
Status: true,
|
||||
Data: res,
|
||||
})
|
||||
}
|
||||
24
internal/routes/roleRoute.go
Normal file
24
internal/routes/roleRoute.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"history-api/internal/controllers"
|
||||
"history-api/internal/middlewares"
|
||||
"history-api/internal/repositories"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func RoleRoutes(app *fiber.App, controller *controllers.RoleController, userRepo repositories.UserRepository) {
|
||||
route := app.Group("/roles")
|
||||
route.Get(
|
||||
"/",
|
||||
middlewares.JwtAccess(userRepo),
|
||||
controller.GetAllRole,
|
||||
)
|
||||
|
||||
route.Get(
|
||||
"/:id",
|
||||
middlewares.JwtAccess(userRepo),
|
||||
controller.GetRoleById,
|
||||
)
|
||||
}
|
||||
51
internal/services/roleService.go
Normal file
51
internal/services/roleService.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"history-api/internal/dtos/response"
|
||||
"history-api/internal/models"
|
||||
"history-api/internal/repositories"
|
||||
"history-api/pkg/convert"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type RoleService interface {
|
||||
GetRoleByID(ctx context.Context, id string) (*response.RoleResponse, error)
|
||||
GetAllRole(ctx context.Context) ([]*response.RoleResponse, error)
|
||||
}
|
||||
|
||||
type roleService struct {
|
||||
roleRepo repositories.RoleRepository
|
||||
}
|
||||
|
||||
|
||||
func NewRoleService(
|
||||
roleRepo repositories.RoleRepository,
|
||||
) RoleService {
|
||||
return &roleService{
|
||||
roleRepo: roleRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *roleService) GetAllRole(ctx context.Context) ([]*response.RoleResponse, error) {
|
||||
roles, err := r.roleRepo.All(ctx)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
return models.RolesEntityToResponse(roles), nil
|
||||
}
|
||||
|
||||
func (r *roleService) GetRoleByID(ctx context.Context, id string) (*response.RoleResponse, error) {
|
||||
roleId, err := convert.StringToUUID(id)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
role, err := r.roleRepo.GetByID(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Role not found")
|
||||
}
|
||||
|
||||
return role.ToResponse(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user