sharedutils/domain/domain.go

62 lines
1.5 KiB
Go
Raw Normal View History

2023-01-24 13:46:17 +00:00
package domain
import (
"errors"
2023-02-11 23:33:58 +00:00
"git.gregbrzezinski.com/Skirda/sharedutils/games/skirdagame"
"git.gregbrzezinski.com/Skirda/sharedutils/skirdasession"
2023-01-24 13:46:17 +00:00
)
type SkirdaDomain struct {
DomainId string
skirdagame.SkirdaGames
skirdasession.SkirdaSessions
}
func (domain SkirdaDomain) BuildDomain(newGames []skirdagame.SkirdaGame, newSessions []skirdasession.SkirdaSession) {
domain.AddGames(newGames)
domain.AddSessions(newSessions)
}
type Domains []SkirdaDomain
func (domains Domains) Set(newDomains []SkirdaDomain) {
domains = append([]SkirdaDomain{}, newDomains...)
}
func (domains Domains) FindGameByID(gameId string) (skirdagame.SkirdaGame, error) {
for _, domain := range domains {
game, _ := domain.FindGameByID(gameId)
if game.GetSkirdaGameId() == gameId {
return game, nil
}
}
return nil, errors.New("")
}
func (domains Domains) GetGames() skirdagame.SkirdaGames {
allGames := skirdagame.SkirdaGames{}
for _, domain := range domains {
allGames = append(allGames, domain.SkirdaGames...)
}
return allGames
}
func (domains Domains) GetSessions() skirdasession.SkirdaSessions {
plainSessions := skirdasession.SkirdaSessions{}
for _, domain := range domains {
plainSessions = append(plainSessions, domain.SkirdaSessions...)
}
return plainSessions
}
func (domains Domains) FindDomain(domainId string) (SkirdaDomain, error) {
for _, domain := range domains {
if domain.DomainId == domainId {
return domain, nil
}
}
return SkirdaDomain{}, errors.New("not any domain founded")
}