scaffolding for new seasons

This commit is contained in:
2026-02-02 19:12:14 +11:00
parent 5b4fe91c55
commit 67bf84c3a6
21 changed files with 520 additions and 41 deletions

View File

@@ -15,7 +15,7 @@ import (
"git.haelnorr.com/h/oslstats/internal/store"
)
func setupHttpServer(
func setupHTTPServer(
staticFS *fs.FS,
cfg *config.Config,
logger *hlog.Logger,

View File

@@ -72,6 +72,16 @@ func addRoutes(
Method: hws.MethodPOST,
Handler: handlers.SeasonsList(s, conn),
},
{
Path: "/seasons/new",
Methods: []hws.Method{hws.MethodGET, hws.MethodPOST},
Handler: handlers.NewSeason(s, conn),
},
{
Path: "/seasons/{season_short_name}",
Method: hws.MethodGET,
Handler: handlers.SeasonPage(s, conn),
},
}
htmxRoutes := []hws.Route{
@@ -80,6 +90,16 @@ func addRoutes(
Method: hws.MethodPOST,
Handler: handlers.IsUsernameUnique(s, conn, cfg, store),
},
{
Path: "/htmx/isseasonnameunique",
Method: hws.MethodPOST,
Handler: handlers.IsSeasonNameUnique(s, conn),
},
{
Path: "/htmx/isseasonshortnameunique",
Method: hws.MethodPOST,
Handler: handlers.IsSeasonShortNameUnique(s, conn),
},
}
wsRoutes := []hws.Route{

View File

@@ -29,7 +29,6 @@ func run(ctx context.Context, logger *hlog.Logger, cfg *config.Config) error {
if err != nil {
return errors.Wrap(err, "setupDBConn")
}
defer closedb()
// Setup embedded files
logger.Debug().Msg("Getting embedded files")
@@ -50,7 +49,7 @@ func run(ctx context.Context, logger *hlog.Logger, cfg *config.Config) error {
}
logger.Debug().Msg("Setting up HTTP server")
httpServer, err := setupHttpServer(&staticFS, cfg, logger, bun, store, discordAPI)
httpServer, err := setupHTTPServer(&staticFS, cfg, logger, bun, store, discordAPI)
if err != nil {
return errors.Wrap(err, "setupHttpServer")
}
@@ -72,7 +71,11 @@ func run(ctx context.Context, logger *hlog.Logger, cfg *config.Config) error {
logger.Info().Msg("Shut down requested, waiting 60 seconds...")
err := httpServer.Shutdown(shutdownCtx)
if err != nil {
logger.Error().Err(err).Str("stacktrace", fmt.Sprintf("%+v", errors.Wrap(err, "httpServer.Shutdown"))).Msg("Graceful shutdown failed")
logger.Error().Err(err).Str("stacktrace", fmt.Sprintf("%+v", errors.Wrap(err, "httpServer.Shutdown"))).Msg("Error during HTTP server shutdown")
}
err = closedb()
if err != nil {
logger.Error().Err(err).Str("stacktrace", fmt.Sprintf("%+v", errors.Wrap(err, "closedb"))).Msg("Error during database close")
}
})
wg.Wait()