Add filtering expenses based on db.SettingsTypeFilter on statistics/type route handler
This commit is contained in:
parent
65fff95124
commit
32d3f1331c
|
@ -27,13 +27,22 @@ func StatisticsGetAllSpendingsForTypes(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dbc := db.Connect()
|
dbc := db.Connect()
|
||||||
|
var settingsTypeFilter []*db.SettingsTypeFilter
|
||||||
|
if err := dbc.Find(&settingsTypeFilter, db.SettingsTypeFilter{UserID: userID}).Error; err != nil {
|
||||||
|
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var filerTypeIDs []uint
|
||||||
|
for _, typeFilter := range settingsTypeFilter {
|
||||||
|
filerTypeIDs = append(filerTypeIDs, typeFilter.TypeID)
|
||||||
|
}
|
||||||
var userTypes []*db.Type
|
var userTypes []*db.Type
|
||||||
if err := dbc.Find(&userTypes, db.Type{UserID: userID}).Error; err != nil {
|
if err := dbc.Find(&userTypes, db.Type{UserID: userID}).Error; err != nil {
|
||||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var userExpenses []*db.Expense
|
var userExpenses []*db.Expense
|
||||||
if err := dbc.Preload("Card.Currency").Find(&userExpenses, db.Expense{UserID: userID}).Error; err != nil {
|
if err := dbc.Not(map[string]interface{}{"type_id": filerTypeIDs}).Preload("Card.Currency").Find(&userExpenses, db.Expense{UserID: userID}).Error; err != nil {
|
||||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user