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.

39 lines
874 B
Go

// Package models provides ...
package models
import (
"gorm.io/datatypes"
"gorm.io/gorm"
)
type Card struct {
gorm.Model
UserID uint
User User
Front string `json:"front" binding:"required"`
Back string `json:"back" binding:"required"`
Hint string `json:"hint"`
CardDeckID uint `json:"deck_id" binding:"required"`
CardDeck CardDeck
PhaseID uint
Phase Phase
NextTest datatypes.Date
}
type CardDto struct {
ID uint `json:"id"`
Front string `json:"front" binding:"required"`
Back string `json:"back" binding:"required"`
Hint string `json:"hint"`
CardDeckID uint `json:"deck_id" binding:"required"`
}
func (c Card) ToDto() CardDto {
return CardDto{c.ID, c.Front, c.Back, c.Hint, c.CardDeckID}
}
func (c *Card) BeforeCreate(tx *gorm.DB) (err error) {
c.PhaseID = phaseOneID
return
}