59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package services
|
|
|
|
import (
|
|
"net/http"
|
|
"wm-backend/global"
|
|
"wm-backend/internal/models"
|
|
"wm-backend/internal/models/requests"
|
|
"wm-backend/internal/models/responses"
|
|
"wm-backend/internal/repositories"
|
|
"wm-backend/pkg/helper"
|
|
"wm-backend/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RoleCreate(c *gin.Context) error {
|
|
requestBody := requests.CreateRoleRequest{}
|
|
if helper.IsShouldBindJSON(c, &requestBody) {
|
|
return nil
|
|
}
|
|
roleModel := &models.Role{
|
|
Name: requestBody.Name,
|
|
Description: requestBody.Description,
|
|
CreatedBy: "",
|
|
}
|
|
role, err := repositories.CreateRole(c.Request.Context(), global.Queries, *roleModel)
|
|
if err != nil {
|
|
|
|
response.InternalServerError(c, http.StatusInternalServerError, "Failed to create role")
|
|
return nil
|
|
}
|
|
// if isUniqueViolation(err) {
|
|
// response.BadRequest(c, "Role name already exists")
|
|
// } else {
|
|
// response.InternalServerError(c, "Failed to create role")
|
|
// }
|
|
// Return success response with the created role
|
|
response.Created(c, "Role created successfully", &responses.BodyRoleResponse{
|
|
ID: role.ID,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func RoleList(c *gin.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func RoleGetByID(c *gin.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func RoleUpdate(c *gin.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func RoleDelete(c *gin.Context) error {
|
|
return nil
|
|
}
|