Add Discord event announcement functionality to backend
This commit introduces a new Discord event announcer to the backend, allowing for event announcements via Discord. It includes the addition of new environment variables for Discord configuration in `.env.example` and `compose.yaml`. The `main.go` file has been updated to initialize the announcer, and a new `discord` package has been created, containing the announcer logic and tests. Additionally, the service layer has been modified to support bracket draft management, enhancing the overall event workflow. Integration tests have been updated to ensure proper functionality of the new features.
This commit is contained in:
@@ -30,6 +30,9 @@ type Store interface {
|
||||
SaveRoster(context.Context, domain.RosterDraft, int) (domain.RosterDraft, error)
|
||||
GetRoster(context.Context, string) (domain.RosterDraft, error)
|
||||
ResetRoster(context.Context, string) error
|
||||
SaveBracketDraft(context.Context, domain.BracketDraft, int) (domain.BracketDraft, error)
|
||||
GetBracketDraft(context.Context, string) (domain.BracketDraft, error)
|
||||
DeleteBracketDraft(context.Context, string) error
|
||||
StartScrim(context.Context, domain.Event, int, []domain.Series, *domain.Tournament) error
|
||||
DeleteEvent(context.Context, string) error
|
||||
UpsertRSVP(context.Context, domain.RSVP) (domain.RSVP, error)
|
||||
@@ -55,14 +58,26 @@ type Store interface {
|
||||
|
||||
type Publisher interface{ Publish(topic string, value any) }
|
||||
|
||||
type Service struct {
|
||||
Store Store
|
||||
Bus Publisher
|
||||
Now func() time.Time
|
||||
type EventAnnouncer interface {
|
||||
AnnounceEventCreated(context.Context, domain.Event) error
|
||||
}
|
||||
|
||||
func New(store Store, bus Publisher) *Service {
|
||||
return &Service{Store: store, Bus: bus, Now: func() time.Time { return time.Now().UTC() }}
|
||||
type Service struct {
|
||||
Store Store
|
||||
Bus Publisher
|
||||
EventAnnouncer EventAnnouncer
|
||||
AnnouncementTimeout time.Duration
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
func New(store Store, bus Publisher, eventAnnouncer EventAnnouncer) *Service {
|
||||
return &Service{
|
||||
Store: store,
|
||||
Bus: bus,
|
||||
EventAnnouncer: eventAnnouncer,
|
||||
AnnouncementTimeout: 3 * time.Second,
|
||||
Now: func() time.Time { return time.Now().UTC() },
|
||||
}
|
||||
}
|
||||
|
||||
func NewID() string {
|
||||
@@ -160,6 +175,11 @@ func (s *Service) CreateEvent(ctx context.Context, actor domain.Account, event d
|
||||
out, err := s.Store.CreateEvent(ctx, event)
|
||||
if err == nil {
|
||||
s.Bus.Publish("events", out)
|
||||
if s.EventAnnouncer != nil {
|
||||
announcementCtx, cancel := context.WithTimeout(ctx, s.AnnouncementTimeout)
|
||||
_ = s.EventAnnouncer.AnnounceEventCreated(announcementCtx, out)
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user