Add Support to consume/redeem points
Support Creating task/chore via api Add initial Description for tasks
This commit is contained in:
parent
50b1357dfa
commit
ac733343da
11 changed files with 368 additions and 66 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
limiter "github.com/ulule/limiter/v3"
|
||||
|
||||
chModel "donetick.com/core/internal/chore/model"
|
||||
uRepo "donetick.com/core/internal/user/repo"
|
||||
)
|
||||
|
||||
|
@ -44,6 +45,46 @@ func (h *API) GetAllChores(c *gin.Context) {
|
|||
c.JSON(200, chores)
|
||||
}
|
||||
|
||||
func (h *API) CreateChore(c *gin.Context) {
|
||||
var choreRequest chModel.ChoreReq
|
||||
|
||||
apiToken := c.GetHeader("secretkey")
|
||||
if apiToken == "" {
|
||||
c.JSON(401, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
user, err := h.userRepo.GetUserByToken(c, apiToken)
|
||||
if err != nil {
|
||||
c.JSON(401, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.BindJSON(&choreRequest); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
chore := &chModel.Chore{
|
||||
CreatedBy: user.ID,
|
||||
CircleID: user.CircleID,
|
||||
Name: choreRequest.Name,
|
||||
IsRolling: choreRequest.IsRolling,
|
||||
FrequencyType: choreRequest.FrequencyType,
|
||||
Frequency: choreRequest.Frequency,
|
||||
AssignStrategy: choreRequest.AssignStrategy,
|
||||
AssignedTo: user.ID,
|
||||
Assignees: []chModel.ChoreAssignees{{UserID: user.ID}},
|
||||
Description: choreRequest.Description,
|
||||
}
|
||||
|
||||
_, err = h.choreRepo.CreateChore(c, chore)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(200, chore)
|
||||
|
||||
}
|
||||
|
||||
func APIs(cfg *config.Config, api *API, r *gin.Engine, auth *jwt.GinJWTMiddleware, limiter *limiter.Limiter) {
|
||||
|
||||
thingsAPI := r.Group("eapi/v1/chore")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue