You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
684 B
Go
29 lines
684 B
Go
3 years ago
|
// Package models provides the data models and database connection
|
||
|
package models
|
||
|
|
||
|
import "gorm.io/gorm"
|
||
|
|
||
|
type CardDeck struct {
|
||
|
gorm.Model
|
||
|
UserID uint
|
||
|
User User
|
||
|
Title string `json:"title"`
|
||
|
Description string `json:"description"`
|
||
|
Cards []Card `json:"cards"`
|
||
|
}
|
||
|
|
||
|
type CardDeckDto struct {
|
||
|
ID uint `json:"id"`
|
||
|
Title string `json:"title"`
|
||
|
Description string `json:"description"`
|
||
|
Cards []CardDto `json:"cards"`
|
||
|
}
|
||
|
|
||
|
func (c CardDeck) ToDto() CardDeckDto {
|
||
|
dto := CardDeckDto{ID: c.ID, Title: c.Title, Description: c.Description}
|
||
|
for _, card := range c.Cards {
|
||
|
dto.Cards = append(dto.Cards, card.ToDto())
|
||
|
}
|
||
|
return dto
|
||
|
}
|