Files
Datarush/internal/competition/domain/competition.go
T

74 lines
2.0 KiB
Go

package domain
import (
"fmt"
"time"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
)
type CompetitionState string
const (
CompetitionStateUnspecified CompetitionState = "UNSPECIFIED"
CompetitionStateDraft CompetitionState = "DRAFT"
CompetitionStateNotStarted CompetitionState = "NOT_STARTED"
CompetitionStateStarted CompetitionState = "STARTED"
CompetitionStateFinished CompetitionState = "FINISHED"
CompetitionStateArchived CompetitionState = "ARCHIVED"
)
type ParticipationType string
const (
ParticipationTypeUnspecified ParticipationType = "UNSPECIFIED"
ParticipationTypeIndividual ParticipationType = "INDIVIDUAL"
ParticipationTypeTeam ParticipationType = "TEAM"
)
type CompetitionType string
const (
CompetitionTypeUnspecified CompetitionType = "UNSPECIFIED"
CompetitionTypeEducative CompetitionType = "EDUCATIVE"
CompetitionTypeCompetitive CompetitionType = "COMPETITIVE"
)
type Competition struct {
ID uuid.UUID
State CompetitionState
Title string
Description string
ImageURL *string
StartTime time.Time
EndTime time.Time
Type CompetitionType
ParticipationType ParticipationType
CreatedAt time.Time
UpdatedAt time.Time
}
func NewCompetition(id uuid.UUID, state CompetitionState, title string, description string, imageURL *string, startTime time.Time, endTime time.Time, tpe CompetitionType, participationType ParticipationType, createdAt time.Time, updatedAt time.Time) *Competition {
return &Competition{
ID: id,
State: state,
Title: title,
Description: description,
ImageURL: imageURL,
StartTime: startTime,
EndTime: endTime,
Type: tpe,
ParticipationType: participationType,
CreatedAt: createdAt,
UpdatedAt: updatedAt,
}
}
func (c *Competition) Validate() error {
validate := validator.New()
return fmt.Errorf("%w: %w", ErrInvalidCompetitionData, validate.Struct(c))
}