Compare commits
No commits in common. "85f8972d5e3ac3ed069b7b0c48ded169916310d4" and "88981b81411a7bc72dd5f393ab53085c2200a980" have entirely different histories.
85f8972d5e
...
88981b8141
|
@ -54,7 +54,6 @@ func main() {
|
|||
{
|
||||
cardsRoutes.POST("/add", handlers.CardAdd)
|
||||
cardsRoutes.GET("/:id", handlers.CardGetId)
|
||||
cardsRoutes.GET("/all", handlers.CardGetAll)
|
||||
cardsRoutes.PUT("/edit/:id", handlers.CardPutId)
|
||||
cardsRoutes.DELETE("/delete/:id", handlers.CardDeleteId)
|
||||
}
|
||||
|
|
|
@ -6,16 +6,6 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbCard {
|
||||
return types.DbCard{
|
||||
ID: inp.ID,
|
||||
Name: inp.Name,
|
||||
Balance: inp.Balance,
|
||||
HaveCreditLine: inp.HaveCreditLine,
|
||||
CreditLine: inp.CreditLine,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary Get card by id
|
||||
// @Description Get card by id
|
||||
// @Tags card
|
||||
|
@ -30,37 +20,15 @@ var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbC
|
|||
// @Security ApiKeyAuth
|
||||
// @Router /card/:id [get]
|
||||
func CardGetId(c *gin.Context) {
|
||||
GetHandler(cardTransform)(c)
|
||||
}
|
||||
|
||||
// @Summary Get all cards for user
|
||||
// @Description Get all cards for user
|
||||
// @Tags card
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "Bearer token"
|
||||
// @Success 200 {object} []types.DbCard
|
||||
// @Failure 401 {object} types.ErrorResponse
|
||||
// @Failure 500 {object} types.ErrorResponse
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /card/all [get]
|
||||
func CardGetAll(c *gin.Context) {
|
||||
userID, err := GetUserID(c)
|
||||
if err != nil {
|
||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||
return
|
||||
GetHandler(func(inp *db.Card) types.DbCard {
|
||||
return types.DbCard{
|
||||
ID: inp.ID,
|
||||
Name: inp.Name,
|
||||
Balance: inp.Balance,
|
||||
HaveCreditLine: inp.HaveCreditLine,
|
||||
CreditLine: inp.CreditLine,
|
||||
}
|
||||
dbc := db.Connect()
|
||||
var entities []*db.Card
|
||||
if err := dbc.Find(&entities, db.Card{UserID: userID}).Error; err != nil {
|
||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ret []types.DbCard
|
||||
for _, entity := range entities {
|
||||
ret = append(ret, cardTransform(entity))
|
||||
}
|
||||
c.JSON(200, ret)
|
||||
})(c)
|
||||
}
|
||||
|
||||
// @Summary Get card by id
|
||||
|
|
|
@ -130,7 +130,7 @@ func IncomeAdd(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
msg := types.Message{
|
||||
Info: fmt.Sprintf("Income with id %d was successfully created!", dbIncome.ID),
|
||||
Message: fmt.Sprintf("Income with id %d was successfully created!", dbIncome.ID),
|
||||
}
|
||||
c.JSON(200, msg)
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@ import (
|
|||
// @Success 200 {object} types.Message
|
||||
// @Router /ping [get]
|
||||
func PingGet(c *gin.Context) {
|
||||
c.JSON(200, types.Message{Info: "Pong!"})
|
||||
c.JSON(200, types.Message{Message: "Pong!"})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package handlers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
||||
|
@ -59,7 +58,6 @@ func CreateHandler[T db.UserIdentifiable, R any](entity T, applyChanges func(src
|
|||
|
||||
var updates R
|
||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||
log.Printf("err is %v\n", err)
|
||||
c.JSON(400, types.ErrorResponse{Message: "Invalid request"})
|
||||
return
|
||||
}
|
||||
|
@ -72,7 +70,7 @@ func CreateHandler[T db.UserIdentifiable, R any](entity T, applyChanges func(src
|
|||
return
|
||||
}
|
||||
|
||||
c.JSON(200, types.Message{Info: fmt.Sprintf("Entity created with ID %d", entity.GetID())})
|
||||
c.JSON(200, types.Message{Message: fmt.Sprintf("Entity created with ID %d", entity.GetID())})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,6 +166,6 @@ func DeleteHandler[T db.UserIdentifiable]() gin.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
c.JSON(200, types.Message{Info: fmt.Sprintf("Entity with ID %d deleted", entity.GetID())})
|
||||
c.JSON(200, types.Message{Message: fmt.Sprintf("Entity with ID %d deleted", entity.GetID())})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type Account struct {
|
|||
}
|
||||
|
||||
type Message struct {
|
||||
Info string `json:"info" example:"Success!"`
|
||||
Message string `json:"message" example:"Success!"`
|
||||
}
|
||||
|
||||
type ErrorResponse struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user