2024-08-14 17:20:57 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-11-04 16:55:14 +01:00
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
2024-08-14 17:20:57 +02:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2024-11-18 18:38:44 +01:00
|
|
|
var incomeTransform func(inp *db.Income) types.DbIncome = func(inp *db.Income) types.DbIncome {
|
|
|
|
return types.DbIncome{
|
|
|
|
ID: inp.ID,
|
|
|
|
CardID: inp.CardID,
|
|
|
|
Comment: inp.Comment,
|
|
|
|
Value: inp.Value,
|
|
|
|
Date: inp.Date,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-14 17:20:57 +02:00
|
|
|
// @Summary Get income by id
|
|
|
|
// @Description Get income by id
|
|
|
|
// @Tags income
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param Authorization header string true "Bearer token"
|
|
|
|
// @Param income path int true "id"
|
|
|
|
// @Success 200 {object} types.DbIncome
|
|
|
|
// @Failure 400 {object} types.ErrorResponse
|
|
|
|
// @Failure 401 {object} types.ErrorResponse
|
|
|
|
// @Failure 500 {object} types.ErrorResponse
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /income/:id [get]
|
|
|
|
func IncomeGetId(c *gin.Context) {
|
2024-11-18 18:38:44 +01:00
|
|
|
GetHandler(incomeTransform)(c)
|
2024-08-14 17:20:57 +02:00
|
|
|
}
|
|
|
|
|
2024-11-16 10:45:47 +01:00
|
|
|
// @Summary Add income
|
|
|
|
// @Description Add income
|
2024-08-14 17:20:57 +02:00
|
|
|
// @Tags income
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param Authorization header string true "Bearer token"
|
|
|
|
// @Param income body types.DbIncome true "Income"
|
|
|
|
// @Success 200 {object} types.Message
|
|
|
|
// @Failure 400 {object} types.ErrorResponse
|
|
|
|
// @Failure 403 {object} types.ErrorResponse
|
|
|
|
// @Failure 500 {object} types.ErrorResponse
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /income/add [post]
|
|
|
|
func IncomeAdd(c *gin.Context) {
|
2024-11-18 18:38:44 +01:00
|
|
|
CreateHandler(
|
|
|
|
&db.Income{},
|
|
|
|
func(src types.DbIncome, dst *db.Income) {
|
|
|
|
dst.CardID = src.CardID
|
|
|
|
dst.Value = src.Value
|
|
|
|
dst.Comment = src.Comment
|
|
|
|
dst.Date = src.Date
|
|
|
|
},
|
2024-11-19 09:11:40 +01:00
|
|
|
)(c)
|
2024-08-14 17:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary Edit income by id
|
|
|
|
// @Description Edit income by id
|
|
|
|
// @Tags income
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param Authorization header string true "Bearer token"
|
|
|
|
// @Param incomeID path int true "id"
|
|
|
|
// @Param income body types.DbIncome true "Income"
|
|
|
|
// @Success 200 {object} types.DbIncome
|
|
|
|
// @Failure 400 {object} types.ErrorResponse
|
|
|
|
// @Failure 401 {object} types.ErrorResponse
|
|
|
|
// @Failure 500 {object} types.ErrorResponse
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /income/edit/:id [put]
|
|
|
|
func IncomePutId(c *gin.Context) {
|
2024-11-18 18:38:44 +01:00
|
|
|
UpdateHandler(
|
|
|
|
func(src types.DbIncome, dst *db.Income) {
|
|
|
|
dst.CardID = src.CardID
|
|
|
|
dst.Value = src.Value
|
|
|
|
dst.Comment = src.Comment
|
|
|
|
dst.Date = src.Date
|
|
|
|
},
|
|
|
|
incomeTransform,
|
|
|
|
)(c)
|
2024-08-14 17:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary Delete income by id
|
|
|
|
// @Description Delete income by id
|
|
|
|
// @Tags income
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param Authorization header string true "Bearer token"
|
|
|
|
// @Param incomeID path int true "id"
|
|
|
|
// @Success 200 {object} types.DbIncome
|
|
|
|
// @Failure 400 {object} types.ErrorResponse
|
|
|
|
// @Failure 401 {object} types.ErrorResponse
|
|
|
|
// @Failure 500 {object} types.ErrorResponse
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /income/delete/:id [delete]
|
|
|
|
func IncomeDeleteId(c *gin.Context) {
|
2024-11-18 18:38:44 +01:00
|
|
|
DeleteHandler[*db.Income]()(c)
|
2024-08-14 17:20:57 +02:00
|
|
|
}
|