* Add message write handler

* Add stub documentation for new required functions
This commit is contained in:
Donaldson 2021-12-30 12:17:17 -08:00
parent ff07ef3b60
commit 7fc2eec35f
2 changed files with 38 additions and 5 deletions

View File

@ -53,11 +53,32 @@ type ThemeProvider interface {
// StateProvider defines what's required to provide MOTH state.
type StateProvider interface {
Messages() string
PointsLog() award.List
TeamName(teamID string) (string, error)
SetTeamName(teamID, teamName string) error
AwardPoints(teamID string, cat string, points int) error
Messages() string // GET /admin/state/messages
SetMessages(string) error // POST /admin/state/messages
PointsLog() award.List // GET /admin/state/points
AwardPoints(teamID string, cat string, points int) error // POST /admin/state/points
// AwardPoints(teamID string, cat string, points int, when int64) error // POST /admin/state/points
// Points(teamID string, cat string, points int) bool // Check if point entry exists // HEAD /admin/state/points/<teamID>/<cat>/<points>
// Points(teamID string, cat string, points int, when int64) bool // Check if point entry exists // HEAD /admin/state/points/<teamID>/<cat>/<points>/<when>
// RemovePoints(teamID string, cat string, points int) error // DELETE /admin/state/points/<teamID>/<cat>/<points>
// RemovePoints(teamID string, cat string, points int, when int64) error // DELETE /admin/state/points/<teamID>/<cat>/<points>/<when>
// SetPoints(award.List) error // PUT /admin/state/points
// TeamIDs() []string // GET /admin/state/team_ids
// SetTeamIDs([] string) error // PUT /admin/state/team_ids
// AddTeamID(teamID string) error // POST /admin/state/team_ids/<teamID>
// RemoveTeamID(teamID string) error // DELETE /admin/state/team_ids/<teamID>
// TeamID(teamID string) bool // HEAD /admin/state/team_ids/<teamID>
// TeamNames() (map[string]string, error) // GET /admin/state/teams
// SetTeamNames(map[string]string) error // PUT /admin/state/teams
TeamName(teamID string) (string, error) // GET /admin/state/teams/id/<teamID>
// TeamIDFromName(teamName string) (string, error) // GET /admin/state/teams/name/<teamName>
SetTeamName(teamID, teamName string) error // POST /admin/state/teams/id/<teamID>/<teamName>
// DeleteTeamName(teamID string) error // DELETE /admin/state/teams/id/<teamID>, /admin/state/teams/name/<teamName>
LogEvent(event, participantID, teamID, cat string, points int, extra ...string)
Maintainer
}

View File

@ -191,6 +191,18 @@ func (s *State) Messages() string {
return s.messages
}
// SetMessages sets the current message
func (s *State) SetMessages(message string) error {
s.lock.Lock()
defer s.lock.Unlock()
err := afero.WriteFile(s, "messages.html", []byte(message), 0600)
s.refreshNow <- true
return err
}
// AwardPoints gives points to teamID in category.
// This doesn't attempt to ensure the teamID has been registered.
// It first checks to make sure these are not duplicate points.