Add endpoint to update priority
This commit is contained in:
parent
09043b0841
commit
9f50772dbe
3 changed files with 64 additions and 0 deletions
|
@ -1017,6 +1017,65 @@ func (h *Handler) ModifyHistory(c *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) updatePriority(c *gin.Context) {
|
||||||
|
type PriorityReq struct {
|
||||||
|
Priority *int `json:"priority" binding:"required,gt=-1"`
|
||||||
|
}
|
||||||
|
|
||||||
|
currrentUser, ok := auth.CurrentUser(c)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(500, gin.H{
|
||||||
|
"error": "Error getting current user",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var priorityReq PriorityReq
|
||||||
|
if err := c.ShouldBindJSON(&priorityReq); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
c.JSON(400, gin.H{
|
||||||
|
"error": "Invalid request",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rawID := c.Param("id")
|
||||||
|
id, err := strconv.Atoi(rawID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, gin.H{
|
||||||
|
"error": "Invalid ID",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
chore, err := h.choreRepo.GetChore(c, id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(500, gin.H{
|
||||||
|
"error": "Error getting chore",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if currrentUser.ID != chore.CreatedBy {
|
||||||
|
c.JSON(403, gin.H{
|
||||||
|
"error": "You are not allowed to update this chore",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
chore.Priority = *priorityReq.Priority
|
||||||
|
if err := h.choreRepo.UpsertChore(c, chore); err != nil {
|
||||||
|
c.JSON(500, gin.H{
|
||||||
|
"error": "Error updating priority",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"res": chore,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) DeleteHistory(c *gin.Context) {
|
func (h *Handler) DeleteHistory(c *gin.Context) {
|
||||||
|
|
||||||
currentUser, ok := auth.CurrentUser(c)
|
currentUser, ok := auth.CurrentUser(c)
|
||||||
|
@ -1181,6 +1240,7 @@ func Routes(router *gin.Engine, h *Handler, auth *jwt.GinJWTMiddleware) {
|
||||||
{
|
{
|
||||||
choresRoutes.GET("/", h.getChores)
|
choresRoutes.GET("/", h.getChores)
|
||||||
choresRoutes.PUT("/", h.editChore)
|
choresRoutes.PUT("/", h.editChore)
|
||||||
|
choresRoutes.PUT("/:id/priority", h.updatePriority)
|
||||||
choresRoutes.POST("/", h.createChore)
|
choresRoutes.POST("/", h.createChore)
|
||||||
choresRoutes.GET("/:id", h.getChore)
|
choresRoutes.GET("/:id", h.getChore)
|
||||||
choresRoutes.GET("/:id/details", h.GetChoreDetail)
|
choresRoutes.GET("/:id/details", h.GetChoreDetail)
|
||||||
|
|
|
@ -43,6 +43,8 @@ type Chore struct {
|
||||||
CreatedBy int `json:"createdBy" gorm:"column:created_by"` // Who created the chore
|
CreatedBy int `json:"createdBy" gorm:"column:created_by"` // Who created the chore
|
||||||
UpdatedBy int `json:"updatedBy" gorm:"column:updated_by"` // Who last updated the chore
|
UpdatedBy int `json:"updatedBy" gorm:"column:updated_by"` // Who last updated the chore
|
||||||
ThingChore *tModel.ThingChore `json:"thingChore" gorm:"foreignkey:chore_id;references:id;<-:false"` // ThingChore relationship
|
ThingChore *tModel.ThingChore `json:"thingChore" gorm:"foreignkey:chore_id;references:id;<-:false"` // ThingChore relationship
|
||||||
|
Status int `json:"status" gorm:"column:status"`
|
||||||
|
Priority int `json:"priority" gorm:"column:priority"`
|
||||||
}
|
}
|
||||||
type ChoreAssignees struct {
|
type ChoreAssignees struct {
|
||||||
ID int `json:"-" gorm:"primary_key"`
|
ID int `json:"-" gorm:"primary_key"`
|
||||||
|
@ -100,6 +102,7 @@ type ChoreDetail struct {
|
||||||
LastCompletedDate *time.Time `json:"lastCompletedDate" gorm:"column:last_completed_date"`
|
LastCompletedDate *time.Time `json:"lastCompletedDate" gorm:"column:last_completed_date"`
|
||||||
LastCompletedBy *int `json:"lastCompletedBy" gorm:"column:last_completed_by"`
|
LastCompletedBy *int `json:"lastCompletedBy" gorm:"column:last_completed_by"`
|
||||||
TotalCompletedCount int `json:"totalCompletedCount" gorm:"column:total_completed"`
|
TotalCompletedCount int `json:"totalCompletedCount" gorm:"column:total_completed"`
|
||||||
|
Priority int `json:"priority" gorm:"column:priority"`
|
||||||
Notes *string `json:"notes" gorm:"column:notes"`
|
Notes *string `json:"notes" gorm:"column:notes"`
|
||||||
CreatedBy int `json:"createdBy" gorm:"column:created_by"`
|
CreatedBy int `json:"createdBy" gorm:"column:created_by"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,6 +249,7 @@ func (r *ChoreRepository) GetChoreDetailByID(c context.Context, choreID int, cir
|
||||||
chores.next_due_date,
|
chores.next_due_date,
|
||||||
chores.assigned_to,
|
chores.assigned_to,
|
||||||
chores.created_by,
|
chores.created_by,
|
||||||
|
chores.priority,
|
||||||
recent_history.last_completed_date,
|
recent_history.last_completed_date,
|
||||||
recent_history.notes,
|
recent_history.notes,
|
||||||
recent_history.last_assigned_to as last_completed_by,
|
recent_history.last_assigned_to as last_completed_by,
|
||||||
|
|
Loading…
Add table
Reference in a new issue