This commit is contained in:
+20
@@ -85,6 +85,16 @@ func Goal(g *gin.RouterGroup, db database.Database) {
|
||||
}
|
||||
goal.GroupID = group.ID
|
||||
|
||||
if goal.ItemID != nil {
|
||||
item, err := l.FindItem(c.Request.Context(), *goal.ItemID)
|
||||
if err != nil {
|
||||
return nil, slerrors.BadRequest("Item could not be found.")
|
||||
}
|
||||
if item.GroupID != goal.GroupID {
|
||||
return nil, slerrors.BadRequest("Item is not in group.")
|
||||
}
|
||||
}
|
||||
|
||||
err = db.Goals().Insert(c.Request.Context(), goal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -117,6 +127,16 @@ func Goal(g *gin.RouterGroup, db database.Database) {
|
||||
return nil, slerrors.BadRequest("Start time must be before end time.")
|
||||
}
|
||||
|
||||
if goal.ItemID != nil && update.ItemID != nil {
|
||||
item, err := l.FindItem(c.Request.Context(), *goal.ItemID)
|
||||
if err != nil {
|
||||
return nil, slerrors.BadRequest("Item could not be found.")
|
||||
}
|
||||
if item.GroupID != goal.GroupID {
|
||||
return nil, slerrors.BadRequest("Item is not in group.")
|
||||
}
|
||||
}
|
||||
|
||||
err = db.Goals().Update(c.Request.Context(), goal.Goal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+27
@@ -66,6 +66,19 @@ func Log(g *gin.RouterGroup, db database.Database) {
|
||||
} else {
|
||||
log.LoggedTime = log.LoggedTime.UTC()
|
||||
}
|
||||
if log.ItemAmount < 0 {
|
||||
return nil, slerrors.BadRequest("Invalid item amount (min: 0).")
|
||||
}
|
||||
if log.SecondaryItemAmount < 0 {
|
||||
return nil, slerrors.BadRequest("Invalid secondary item amount (min: 0).")
|
||||
}
|
||||
|
||||
if log.SecondaryItemID != nil {
|
||||
_, err := l.FindItem(c.Request.Context(), *log.SecondaryItemID)
|
||||
if err != nil {
|
||||
return nil, slerrors.BadRequest("Item could not be found.")
|
||||
}
|
||||
}
|
||||
|
||||
err = db.Logs().Insert(c.Request.Context(), log)
|
||||
if err != nil {
|
||||
@@ -91,6 +104,20 @@ func Log(g *gin.RouterGroup, db database.Database) {
|
||||
}
|
||||
|
||||
log.Update(update)
|
||||
|
||||
if log.SecondaryItemID != nil && update.SecondaryItemID != nil {
|
||||
_, err := l.FindItem(c.Request.Context(), *log.SecondaryItemID)
|
||||
if err != nil {
|
||||
return nil, slerrors.BadRequest("Item could not be found.")
|
||||
}
|
||||
}
|
||||
if log.ItemAmount < 0 {
|
||||
return nil, slerrors.BadRequest("Invalid item amount (min: 0).")
|
||||
}
|
||||
if log.SecondaryItemAmount < 0 {
|
||||
return nil, slerrors.BadRequest("Invalid secondary item amount (min: 0).")
|
||||
}
|
||||
|
||||
err = db.Logs().Update(c.Request.Context(), log.Log)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user