@@ -53,6 +53,8 @@ type ChoreReq struct {
5353 Labels []string `json:"labels"`
5454 LabelsV2 * []LabelReq `json:"labelsV2"`
5555 ThingTrigger * ThingTrigger `json:"thingTrigger"`
56+ Points * int `json:"points"`
57+ CompletionWindow * int `json:"completionWindow"`
5658}
5759type Handler struct {
5860 choreRepo * chRepo.ChoreRepository
@@ -85,7 +87,13 @@ func (h *Handler) getChores(c *gin.Context) {
8587 })
8688 return
8789 }
88- chores , err := h .choreRepo .GetChores (c , u .CircleID , u .ID )
90+ includeArchived := false
91+
92+ if c .Query ("includeArchived" ) == "true" {
93+ includeArchived = true
94+ }
95+
96+ chores , err := h .choreRepo .GetChores (c , u .CircleID , u .ID , includeArchived )
8997 if err != nil {
9098 c .JSON (500 , gin.H {
9199 "error" : "Error getting chores" ,
@@ -271,6 +279,8 @@ func (h *Handler) createChore(c *gin.Context) {
271279 CreatedBy : currentUser .ID ,
272280 CreatedAt : time .Now ().UTC (),
273281 CircleID : currentUser .CircleID ,
282+ Points : choreReq .Points ,
283+ CompletionWindow : choreReq .CompletionWindow ,
274284 }
275285 id , err := h .choreRepo .CreateChore (c , createdChore )
276286 createdChore .ID = id
@@ -530,6 +540,8 @@ func (h *Handler) editChore(c *gin.Context) {
530540 UpdatedBy : currentUser .ID ,
531541 CreatedBy : oldChore .CreatedBy ,
532542 CreatedAt : oldChore .CreatedAt ,
543+ Points : choreReq .Points ,
544+ CompletionWindow : choreReq .CompletionWindow ,
533545 }
534546 if err := h .choreRepo .UpsertChore (c , updatedChore ); err != nil {
535547 c .JSON (500 , gin.H {
@@ -954,6 +966,16 @@ func (h *Handler) completeChore(c *gin.Context) {
954966 })
955967 return
956968 }
969+ // confirm that the chore in completion window:
970+ if chore .CompletionWindow != nil {
971+ if completedDate .After (chore .NextDueDate .Add (time .Hour * time .Duration (* chore .CompletionWindow ))) {
972+ c .JSON (400 , gin.H {
973+ "error" : "Chore is out of completion window" ,
974+ })
975+ return
976+ }
977+ }
978+
957979 var nextDueDate * time.Time
958980 if chore .FrequencyType == "adaptive" {
959981 history , err := h .choreRepo .GetChoreHistoryWithLimit (c , chore .ID , 5 )
@@ -1197,6 +1219,45 @@ func (h *Handler) updatePriority(c *gin.Context) {
11971219 })
11981220}
11991221
1222+ func (h * Handler ) getChoresHistory (c * gin.Context ) {
1223+
1224+ currentUser , ok := auth .CurrentUser (c )
1225+ if ! ok {
1226+ c .JSON (500 , gin.H {
1227+ "error" : "Error getting current user" ,
1228+ })
1229+ return
1230+ }
1231+ durationRaw := c .Query ("limit" )
1232+ if durationRaw == "" {
1233+ durationRaw = "7"
1234+ }
1235+
1236+ duration , err := strconv .Atoi (durationRaw )
1237+ if err != nil {
1238+ c .JSON (400 , gin.H {
1239+ "error" : "Invalid duration" ,
1240+ })
1241+ return
1242+ }
1243+ includeCircleRaw := c .Query ("members" )
1244+ includeCircle := false
1245+ if includeCircleRaw == "true" {
1246+ includeCircle = true
1247+ }
1248+
1249+ choreHistories , err := h .choreRepo .GetChoresHistoryByUserID (c , currentUser .ID , currentUser .CircleID , duration , includeCircle )
1250+ if err != nil {
1251+ c .JSON (500 , gin.H {
1252+ "error" : "Error getting chore history" ,
1253+ })
1254+ return
1255+ }
1256+ c .JSON (200 , gin.H {
1257+ "res" : choreHistories ,
1258+ })
1259+ }
1260+
12001261func (h * Handler ) DeleteHistory (c * gin.Context ) {
12011262
12021263 currentUser , ok := auth .CurrentUser (c )
@@ -1361,7 +1422,7 @@ func Routes(router *gin.Engine, h *Handler, auth *jwt.GinJWTMiddleware) {
13611422 {
13621423 choresRoutes .GET ("/" , h .getChores )
13631424 choresRoutes .GET ("/archived" , h .getArchivedChores )
1364-
1425+ choresRoutes . GET ( "/history" , h . getChoresHistory )
13651426 choresRoutes .PUT ("/" , h .editChore )
13661427 choresRoutes .PUT ("/:id/priority" , h .updatePriority )
13671428 choresRoutes .POST ("/" , h .createChore )
0 commit comments