2022-10-23 06:35:00 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"gitea.dwysokinski.me/twhelp/dcbot/internal/domain"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Choice struct {
|
2023-07-03 06:23:32 +00:00
|
|
|
twhelpSvc TWHelpService
|
2022-10-23 06:35:00 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 06:23:32 +00:00
|
|
|
func NewChoice(twhelpSvc TWHelpService) *Choice {
|
|
|
|
return &Choice{twhelpSvc: twhelpSvc}
|
2022-10-23 06:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Choice) Versions(ctx context.Context) ([]domain.Choice, error) {
|
2023-07-03 06:23:32 +00:00
|
|
|
versions, err := c.twhelpSvc.ListVersions(ctx)
|
2022-10-23 06:35:00 +00:00
|
|
|
if err != nil {
|
2023-07-03 06:23:32 +00:00
|
|
|
return nil, err
|
2022-10-23 06:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
choices := make([]domain.Choice, 0, len(versions))
|
|
|
|
for _, v := range versions {
|
|
|
|
choices = append(choices, domain.Choice{
|
|
|
|
Name: v.Host,
|
|
|
|
Value: v.Code,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return choices, nil
|
|
|
|
}
|