Add Support for Activities , Initial Support for Completion Window and points

This commit is contained in:
Mo Tarbin 2024-12-28 18:59:08 -05:00
parent cd29da9168
commit 27a47a0c1f
5 changed files with 90 additions and 15 deletions

View file

@ -53,6 +53,7 @@ type ChoreReq struct {
Labels []string `json:"labels"`
LabelsV2 *[]LabelReq `json:"labelsV2"`
ThingTrigger *ThingTrigger `json:"thingTrigger"`
Points *int `json:"points"`
}
type Handler struct {
choreRepo *chRepo.ChoreRepository
@ -85,7 +86,13 @@ func (h *Handler) getChores(c *gin.Context) {
})
return
}
chores, err := h.choreRepo.GetChores(c, u.CircleID, u.ID)
includeArchived := false
if c.Query("includeArchived") == "true" {
includeArchived = true
}
chores, err := h.choreRepo.GetChores(c, u.CircleID, u.ID, includeArchived)
if err != nil {
c.JSON(500, gin.H{
"error": "Error getting chores",
@ -271,6 +278,7 @@ func (h *Handler) createChore(c *gin.Context) {
CreatedBy: currentUser.ID,
CreatedAt: time.Now().UTC(),
CircleID: currentUser.CircleID,
Points: choreReq.Points,
}
id, err := h.choreRepo.CreateChore(c, createdChore)
createdChore.ID = id
@ -530,6 +538,7 @@ func (h *Handler) editChore(c *gin.Context) {
UpdatedBy: currentUser.ID,
CreatedBy: oldChore.CreatedBy,
CreatedAt: oldChore.CreatedAt,
Points: choreReq.Points,
}
if err := h.choreRepo.UpsertChore(c, updatedChore); err != nil {
c.JSON(500, gin.H{
@ -1197,6 +1206,45 @@ func (h *Handler) updatePriority(c *gin.Context) {
})
}
func (h *Handler) getChoresHistory(c *gin.Context) {
currentUser, ok := auth.CurrentUser(c)
if !ok {
c.JSON(500, gin.H{
"error": "Error getting current user",
})
return
}
durationRaw := c.Query("limit")
if durationRaw == "" {
durationRaw = "7"
}
duration, err := strconv.Atoi(durationRaw)
if err != nil {
c.JSON(400, gin.H{
"error": "Invalid duration",
})
return
}
includeCircleRaw := c.Query("all")
includeCircle := false
if includeCircleRaw == "true" {
includeCircle = true
}
choreHistories, err := h.choreRepo.GetChoresHistoryByUserID(c, currentUser.ID, currentUser.CircleID, duration, includeCircle)
if err != nil {
c.JSON(500, gin.H{
"error": "Error getting chore history",
})
return
}
c.JSON(200, gin.H{
"res": choreHistories,
})
}
func (h *Handler) DeleteHistory(c *gin.Context) {
currentUser, ok := auth.CurrentUser(c)
@ -1336,7 +1384,7 @@ func Routes(router *gin.Engine, h *Handler, auth *jwt.GinJWTMiddleware) {
{
choresRoutes.GET("/", h.getChores)
choresRoutes.GET("/archived", h.getArchivedChores)
choresRoutes.GET("/history", h.getChoresHistory)
choresRoutes.PUT("/", h.editChore)
choresRoutes.PUT("/:id/priority", h.updatePriority)
choresRoutes.POST("/", h.createChore)