Add /all endpoint and handler for income
This commit is contained in:
parent
9f7d93ed19
commit
83f69a2135
|
@ -77,6 +77,7 @@ func main() {
|
|||
{
|
||||
incomeRoutes.POST("/add", handlers.IncomeAdd)
|
||||
incomeRoutes.GET("/:id", handlers.IncomeGetId)
|
||||
incomeRoutes.GET("/all", handlers.IncomeGetAll)
|
||||
incomeRoutes.PUT("/edit/:id", handlers.IncomePutId)
|
||||
incomeRoutes.DELETE("/delete/:id", handlers.IncomeDeleteId)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,36 @@ func IncomeGetId(c *gin.Context) {
|
|||
GetHandler(incomeTransform)(c)
|
||||
}
|
||||
|
||||
// @Summary Get all incomes for user
|
||||
// @Description Get all incomes for user
|
||||
// @Tags type
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "Bearer token"
|
||||
// @Success 200 {object} []types.DbIncome
|
||||
// @Failure 401 {object} types.ErrorResponse
|
||||
// @Failure 500 {object} types.ErrorResponse
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /income/all [get]
|
||||
func IncomeGetAll(c *gin.Context) {
|
||||
userID, err := GetUserID(c)
|
||||
if err != nil {
|
||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
dbc := db.Connect()
|
||||
var entities []*db.Income
|
||||
if err := dbc.Find(&entities, db.Income{UserID: userID}).Error; err != nil {
|
||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ret []types.DbIncome
|
||||
for _, entity := range entities {
|
||||
ret = append(ret, incomeTransform(entity))
|
||||
}
|
||||
c.JSON(200, ret)
|
||||
}
|
||||
|
||||
// @Summary Add income
|
||||
// @Description Add income
|
||||
// @Tags income
|
||||
|
|
Loading…
Reference in New Issue
Block a user