Update department etc
This commit is contained in:
@@ -286,7 +286,6 @@ func (h *LetterHandler) CreateDispositions(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Extract department ID from context
|
||||
appCtx := appcontext.FromGinContext(c.Request.Context())
|
||||
req.FromDepartment = appCtx.DepartmentID
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MasterService interface {
|
||||
@@ -31,7 +32,13 @@ type MasterService interface {
|
||||
DeleteDispositionAction(ctx context.Context, id uuid.UUID) error
|
||||
ListDispositionActions(ctx context.Context) (*contract.ListDispositionActionsResponse, error)
|
||||
|
||||
CreateDepartment(ctx context.Context, req *contract.CreateDepartmentRequest) (*contract.GetDepartmentResponse, error)
|
||||
GetDepartment(ctx context.Context, id uuid.UUID) (*contract.GetDepartmentResponse, error)
|
||||
UpdateDepartment(ctx context.Context, id uuid.UUID, req *contract.UpdateDepartmentRequest) (*contract.GetDepartmentResponse, error)
|
||||
DeleteDepartment(ctx context.Context, id uuid.UUID) error
|
||||
ListDepartments(ctx context.Context, req *contract.ListDepartmentsRequest) (*contract.ListDepartmentsResponse, error)
|
||||
GetOrganizationalChart(ctx context.Context, rootPath string) (*contract.OrganizationalChartResponse, error)
|
||||
GetOrganizationalChartByID(ctx context.Context, departmentID uuid.UUID) (*contract.OrganizationalChartResponse, error)
|
||||
}
|
||||
|
||||
type MasterHandler struct{ svc MasterService }
|
||||
@@ -260,15 +267,87 @@ func (h *MasterHandler) ListDispositionActions(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Departments
|
||||
func (h *MasterHandler) CreateDepartment(c *gin.Context) {
|
||||
var req contract.CreateDepartmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid body", Code: 400})
|
||||
return
|
||||
}
|
||||
resp, err := h.svc.CreateDepartment(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
func (h *MasterHandler) GetDepartment(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid id", Code: 400})
|
||||
return
|
||||
}
|
||||
resp, err := h.svc.GetDepartment(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
c.JSON(http.StatusNotFound, &contract.ErrorResponse{Error: "department not found", Code: 404})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
func (h *MasterHandler) UpdateDepartment(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid id", Code: 400})
|
||||
return
|
||||
}
|
||||
var req contract.UpdateDepartmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid body", Code: 400})
|
||||
return
|
||||
}
|
||||
resp, err := h.svc.UpdateDepartment(c.Request.Context(), id, &req)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
c.JSON(http.StatusNotFound, &contract.ErrorResponse{Error: "department not found", Code: 404})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
func (h *MasterHandler) DeleteDepartment(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid id", Code: 400})
|
||||
return
|
||||
}
|
||||
if err := h.svc.DeleteDepartment(c.Request.Context(), id); err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
c.JSON(http.StatusNotFound, &contract.ErrorResponse{Error: "department not found", Code: 404})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, &contract.SuccessResponse{Message: "department deleted successfully"})
|
||||
}
|
||||
|
||||
func (h *MasterHandler) ListDepartments(c *gin.Context) {
|
||||
var req contract.ListDepartmentsRequest
|
||||
|
||||
|
||||
// Parse query parameters
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid query parameters", Code: 400})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
resp, err := h.svc.ListDepartments(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
@@ -276,3 +355,34 @@ func (h *MasterHandler) ListDepartments(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
func (h *MasterHandler) GetOrganizationalChart(c *gin.Context) {
|
||||
// Get optional root path from query parameter
|
||||
rootPath := c.Query("root_path")
|
||||
|
||||
resp, err := h.svc.GetOrganizationalChart(c.Request.Context(), rootPath)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
func (h *MasterHandler) GetOrganizationalChartByID(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, &contract.ErrorResponse{Error: "invalid department id", Code: 400})
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := h.svc.GetOrganizationalChartByID(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
c.JSON(http.StatusNotFound, &contract.ErrorResponse{Error: "department not found", Code: 404})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, &contract.ErrorResponse{Error: err.Error(), Code: 500})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(resp))
|
||||
}
|
||||
|
||||
@@ -353,7 +353,8 @@ func (h *UserHandler) GetActiveUsersForMention(c *gin.Context) {
|
||||
}
|
||||
|
||||
logger.FromContext(c).Infof("UserHandler::GetActiveUsersForMention -> Successfully retrieved %d active users", len(users))
|
||||
c.JSON(http.StatusOK, response)
|
||||
|
||||
c.JSON(http.StatusOK, contract.BuildSuccessResponse(response))
|
||||
}
|
||||
|
||||
func (h *UserHandler) sendErrorResponse(c *gin.Context, message string, statusCode int) {
|
||||
|
||||
Reference in New Issue
Block a user