core/internal/adapter/internal/bunmodel/opponents_defeated.go

49 lines
1.1 KiB
Go

package bunmodel
import (
"fmt"
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
)
type OpponentsDefeated struct {
RankAtt int `bun:"rank_att"`
ScoreAtt int `bun:"score_att"`
RankDef int `bun:"rank_def"`
ScoreDef int `bun:"score_def"`
RankSup int `bun:"rank_sup"`
ScoreSup int `bun:"score_sup"`
RankTotal int `bun:"rank_total"`
ScoreTotal int `bun:"score_total"`
}
func NewOpponentsDefeated(od domain.OpponentsDefeated) OpponentsDefeated {
return OpponentsDefeated{
RankAtt: od.RankAtt(),
ScoreAtt: od.ScoreAtt(),
RankDef: od.RankDef(),
ScoreDef: od.ScoreDef(),
RankSup: od.RankSup(),
ScoreSup: od.ScoreSup(),
RankTotal: od.RankTotal(),
ScoreTotal: od.ScoreTotal(),
}
}
func (od OpponentsDefeated) ToDomain() (domain.OpponentsDefeated, error) {
converted, err := domain.NewOpponentsDefeated(
od.RankAtt,
od.ScoreAtt,
od.RankDef,
od.ScoreDef,
od.RankSup,
od.ScoreSup,
od.RankTotal,
od.ScoreTotal,
)
if err != nil {
return domain.OpponentsDefeated{}, fmt.Errorf("couldn't construct domain.OpponentsDefeated: %w", err)
}
return converted, nil
}