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.POST("/add", handlers.CardAdd)
|
||||||
cardsRoutes.GET("/:id", handlers.CardGetId)
|
cardsRoutes.GET("/:id", handlers.CardGetId)
|
||||||
cardsRoutes.GET("/all", handlers.CardGetAll)
|
|
||||||
cardsRoutes.PUT("/edit/:id", handlers.CardPutId)
|
cardsRoutes.PUT("/edit/:id", handlers.CardPutId)
|
||||||
cardsRoutes.DELETE("/delete/:id", handlers.CardDeleteId)
|
cardsRoutes.DELETE("/delete/:id", handlers.CardDeleteId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"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
|
// @Summary Get card by id
|
||||||
// @Description Get card by id
|
// @Description Get card by id
|
||||||
// @Tags card
|
// @Tags card
|
||||||
|
@ -30,37 +20,15 @@ var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbC
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Router /card/:id [get]
|
// @Router /card/:id [get]
|
||||||
func CardGetId(c *gin.Context) {
|
func CardGetId(c *gin.Context) {
|
||||||
GetHandler(cardTransform)(c)
|
GetHandler(func(inp *db.Card) types.DbCard {
|
||||||
}
|
return types.DbCard{
|
||||||
|
ID: inp.ID,
|
||||||
// @Summary Get all cards for user
|
Name: inp.Name,
|
||||||
// @Description Get all cards for user
|
Balance: inp.Balance,
|
||||||
// @Tags card
|
HaveCreditLine: inp.HaveCreditLine,
|
||||||
// @Produce json
|
CreditLine: inp.CreditLine,
|
||||||
// @Param Authorization header string true "Bearer token"
|
}
|
||||||
// @Success 200 {object} []types.DbCard
|
})(c)
|
||||||
// @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
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Get card by id
|
// @Summary Get card by id
|
||||||
|
|
|
@ -130,7 +130,7 @@ func IncomeAdd(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msg := types.Message{
|
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)
|
c.JSON(200, msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,5 +13,5 @@ import (
|
||||||
// @Success 200 {object} types.Message
|
// @Success 200 {object} types.Message
|
||||||
// @Router /ping [get]
|
// @Router /ping [get]
|
||||||
func PingGet(c *gin.Context) {
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
"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
|
var updates R
|
||||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||||
log.Printf("err is %v\n", err)
|
|
||||||
c.JSON(400, types.ErrorResponse{Message: "Invalid request"})
|
c.JSON(400, types.ErrorResponse{Message: "Invalid request"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +70,7 @@ func CreateHandler[T db.UserIdentifiable, R any](entity T, applyChanges func(src
|
||||||
return
|
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
|
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 {
|
type Message struct {
|
||||||
Info string `json:"info" example:"Success!"`
|
Message string `json:"message" example:"Success!"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user