Files
portal/services/cardService.go
2026-06-25 11:26:20 +02:00

48 lines
1.4 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, groupId int32) (*openapi.Card, error) {
apiClient := internal.GetApiClient(c)
resp, r, err := apiClient.CardAPI.AddCardApiV1CardsGroupIdPost(context.Background(), groupId).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) 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
}