|
|
@ -33,13 +33,17 @@ func Task(g *gin.RouterGroup, db database.Database) { |
|
|
|
})) |
|
|
|
|
|
|
|
g.POST("/", handler("task", func(c *gin.Context) (interface{}, error) { |
|
|
|
createdTime := time.Now() |
|
|
|
task := models.Task{} |
|
|
|
err := c.BindJSON(&task) |
|
|
|
if err != nil { |
|
|
|
return nil, slerrors.BadRequest("Invalid JSON") |
|
|
|
} |
|
|
|
if task.EndTime != nil && task.EndTime.Before(time.Now()) { |
|
|
|
return nil, slerrors.BadRequest("Project end time must be later than current time.") |
|
|
|
if task.EndTime != nil && task.EndTime.Before(createdTime) { |
|
|
|
return nil, slerrors.BadRequest("Task end time must be later than current time.") |
|
|
|
} |
|
|
|
if task.ItemAmount <= 0 { |
|
|
|
return nil, slerrors.BadRequest("Item amount cannot be zero or negative.") |
|
|
|
} |
|
|
|
|
|
|
|
project, err := l.FindProject(c.Request.Context(), task.ProjectID) |
|
|
@ -83,6 +87,13 @@ func Task(g *gin.RouterGroup, db database.Database) { |
|
|
|
} |
|
|
|
|
|
|
|
task.Update(update) |
|
|
|
if task.EndTime != nil && task.EndTime.Before(task.CreatedTime) { |
|
|
|
return nil, slerrors.BadRequest("Task end time must be later than it was created.") |
|
|
|
} |
|
|
|
if task.ItemAmount <= 0 { |
|
|
|
return nil, slerrors.BadRequest("Item amount cannot be zero or negative.") |
|
|
|
} |
|
|
|
|
|
|
|
err = db.Tasks().Update(c.Request.Context(), task.Task) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|