Files
portal/services/cardService.go
2026-08-08 16:21:55 +02:00

64 lines
2.0 KiB
Go

package services
import (
"context"
"fmt"
"git.dynamicdiscord.de/malobeo/portal/internal"
"git.dynamicdiscord.de/malobeo/portal/openapi"
"github.com/gin-gonic/gin"
"os"
)
var (
Cards CardService = CardService{}
)
type CardService struct{}
// return jwt tokenstring on success
func (u *CardService) Create(c *gin.Context, name string, groupId int32) (*openapi.Card, error) {
apiClient := internal.GetApiClient(c)
cardCreate := *openapi.NewCardCreate(name, groupId) // CardCreate |
resp, r, err := apiClient.CardAPI.AddCardApiV1CardsPost(context.Background()).CardCreate(cardCreate).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CardAPI.CreateCardCardsPost``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return nil, err
}
// response from `LoginForAccessTokenTokenPost`: Token
fmt.Fprintf(os.Stdout, "Response from `CardAPI.CreateCardCardsPost`: %v\n", resp)
return resp, nil
}
func (u *CardService) Delete(c *gin.Context) error {
apiClient := internal.GetApiClient(c)
resp, r, err := apiClient.CardAPI.DelCardApiV1CardsDelete(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CardAPI.DelCardApiV1CardsDelete``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return err
}
// response from `LoginForAccessTokenTokenPost`: Token
fmt.Fprintf(os.Stdout, "Response from `CardAPI.CreateCardCardsPost`: %v\n", resp)
return nil
}
func (u *CardService) GetCardsByGroup(c *gin.Context, groupId int32) ([]openapi.Card, error) {
apiClient := internal.GetApiClient(c)
resp, r, err := apiClient.CardAPI.GetCardsApiV1CardsGroupIdGet(context.Background(), groupId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CardAPI.GetCardsCardsGet``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return nil, err
}
// response from `LoginForAccessTokenTokenPost`: Token
fmt.Fprintf(os.Stdout, "Response from `CardAPI.GetCardsCardsGet`: %v\n", resp)
return resp, nil
}