Add /all endpoint and handler for income

This commit is contained in:
qowevisa 2024-11-19 10:12:04 +02:00
parent 9f7d93ed19
commit 83f69a2135
2 changed files with 31 additions and 0 deletions

View File

@ -77,6 +77,7 @@ func main() {
{ {
incomeRoutes.POST("/add", handlers.IncomeAdd) incomeRoutes.POST("/add", handlers.IncomeAdd)
incomeRoutes.GET("/:id", handlers.IncomeGetId) incomeRoutes.GET("/:id", handlers.IncomeGetId)
incomeRoutes.GET("/all", handlers.IncomeGetAll)
incomeRoutes.PUT("/edit/:id", handlers.IncomePutId) incomeRoutes.PUT("/edit/:id", handlers.IncomePutId)
incomeRoutes.DELETE("/delete/:id", handlers.IncomeDeleteId) incomeRoutes.DELETE("/delete/:id", handlers.IncomeDeleteId)
} }

View File

@ -33,6 +33,36 @@ func IncomeGetId(c *gin.Context) {
GetHandler(incomeTransform)(c) 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 // @Summary Add income
// @Description Add income // @Description Add income
// @Tags income // @Tags income