mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
add api check uncheck assignment
This commit is contained in:
@@ -241,3 +241,21 @@ func (u *DailyChecklistController) GetAllTasks(c *fiber.Ctx) error {
|
||||
Data: result,
|
||||
})
|
||||
}
|
||||
|
||||
func (u *DailyChecklistController) UpdateAssignment(c *fiber.Ctx) error {
|
||||
req := new(validation.UpdateAssignment)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
if err := u.DailyChecklistService.UpdateAssignment(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Assignment updated successfully",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,16 +19,32 @@ func DailyChecklistRoutes(v1 fiber.Router, u user.UserService, s dailyChecklist.
|
||||
route.Post("/", ctrl.CreateOne)
|
||||
|
||||
// create task
|
||||
/*
|
||||
ketika add phase
|
||||
*/
|
||||
route.Post("/phase/:idDailyChecklist", ctrl.CreateDailyChecklistPhase)
|
||||
|
||||
// create assigment
|
||||
/*
|
||||
ketika add ABK
|
||||
*/
|
||||
route.Post("/assignment/:idDailyChecklist", ctrl.CreateAssignment)
|
||||
|
||||
// remove assignment
|
||||
/*
|
||||
ketika remove ABK
|
||||
*/
|
||||
route.Delete("/:idDailyChecklist/assignments/:idEmployee", ctrl.RemoveAssignment)
|
||||
|
||||
//get all tasks
|
||||
route.Get("/tasks", ctrl.GetAllTasks)
|
||||
|
||||
// update assignment
|
||||
/*
|
||||
ketika check dan uncheck tugas oleh ABK
|
||||
*/
|
||||
route.Post("/assignment", ctrl.UpdateAssignment)
|
||||
|
||||
route.Get("/:id", ctrl.GetOne)
|
||||
route.Patch("/:id", ctrl.UpdateOne)
|
||||
route.Delete("/:id", ctrl.DeleteOne)
|
||||
|
||||
@@ -29,6 +29,7 @@ type DailyChecklistService interface {
|
||||
AssignTasks(ctx *fiber.Ctx, id uint, req *validation.AssignTask) error
|
||||
RemoveAssignment(ctx *fiber.Ctx, id uint, employeeID uint) error
|
||||
GetTasks(ctx *fiber.Ctx, checklistID uint) ([]entity.DailyChecklistActivityTask, error)
|
||||
UpdateAssignment(ctx *fiber.Ctx, req *validation.UpdateAssignment) error
|
||||
}
|
||||
|
||||
type dailyChecklistService struct {
|
||||
@@ -296,6 +297,42 @@ func (s dailyChecklistService) GetTasks(c *fiber.Ctx, checklistID uint) ([]entit
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func (s dailyChecklistService) UpdateAssignment(c *fiber.Ctx, req *validation.UpdateAssignment) error {
|
||||
if err := s.Validate.Struct(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
task := new(entity.DailyChecklistActivityTask)
|
||||
if err := s.Repository.DB().WithContext(c.Context()).First(task, req.TaskID).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Task not found")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if req.EmployeeID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid employee id")
|
||||
}
|
||||
|
||||
updates := map[string]any{"updated_at": time.Now()}
|
||||
if req.Checked != nil {
|
||||
updates["checked"] = *req.Checked
|
||||
}
|
||||
if req.Note != nil {
|
||||
updates["note"] = *req.Note
|
||||
}
|
||||
|
||||
return s.Repository.DB().WithContext(c.Context()).Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "task_id"}, {Name: "employee_id"}},
|
||||
DoUpdates: clause.Assignments(updates),
|
||||
}).Create(&entity.DailyChecklistActivityTaskAssignment{
|
||||
TaskId: req.TaskID,
|
||||
EmployeeId: req.EmployeeID,
|
||||
Checked: req.Checked != nil && *req.Checked,
|
||||
Note: req.Note,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func parsePhaseIDs(raw string) ([]uint, error) {
|
||||
parts := strings.Split(raw, ",")
|
||||
result := make([]uint, 0, len(parts))
|
||||
|
||||
@@ -24,3 +24,10 @@ type AssignPhases struct {
|
||||
type AssignTask struct {
|
||||
EmployeeIDs string `json:"employee_ids" validate:"required"`
|
||||
}
|
||||
|
||||
type UpdateAssignment struct {
|
||||
TaskID uint `json:"task_id" validate:"required"`
|
||||
EmployeeID uint `json:"employee_id" validate:"required"`
|
||||
Checked *bool `json:"checked,omitempty"`
|
||||
Note *string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user