diff --git a/internal/plugin/api/handler.go b/internal/plugin/api/handler.go index 8b34f07..7c10fee 100644 --- a/internal/plugin/api/handler.go +++ b/internal/plugin/api/handler.go @@ -23,16 +23,16 @@ func newErrorDTO(err error) errorDTO { } } -// @Summary Get a player -// @Description Get a player for an edition by username -// @Tags Player -// @Produce json -// @Param edition path string true "Minecraft edition" Enums(java, bedrock) -// @Param username path string true "Player username" -// @Success 200 {object} api.getPlayerHandler.respDTO -// @Failure 400 {object} api.errorDTO -// @Failure 404 -// @Router /{edition}/players/{username} [get] +// @Summary Get a player +// @Description Get a player for an edition by username +// @Tags Player +// @Produce json +// @Param edition path string true "Minecraft edition" Enums(java, bedrock) +// @Param username path string true "Player username" +// @Success 200 +// @Failure 400 {object} api.errorDTO +// @Failure 404 +// @Router /{edition}/players/{username} [get] func getPlayerHandler(api infrared.API) http.HandlerFunc { type respDTO struct { Username infrared.Username `json:"username" example:"H4v34ch1n"` @@ -76,16 +76,16 @@ func getPlayerHandler(api infrared.API) http.HandlerFunc { } } -// @Summary Query players per edition -// @Description Query players per edition and filter them by username via regular expression -// @Tags Player -// @Produce json -// @Param edition path string true "Minecraft edition" Enums(java, bedrock) -// @Param usernameRegex query string false "A regular expression to query usernames" -// @Success 200 {array} api.getPlayersHandler.respDTOItem -// @Failure 400 {object} api.errorDTO -// @Failure 422 {object} api.errorDTO -// @Router /{edition}/players [get] +// @Summary Query players per edition +// @Description Query players per edition and filter them by username via regular expression +// @Tags Player +// @Produce json +// @Param edition path string true "Minecraft edition" Enums(java, bedrock) +// @Param usernameRegex query string false "A regular expression to query usernames" +// @Success 200 +// @Failure 400 {object} api.errorDTO +// @Failure 422 {object} api.errorDTO +// @Router /{edition}/players [get] func getPlayersHandler(api infrared.API) http.HandlerFunc { type reqDTOQuery struct { UsernameRegex string `schema:"usernameRegex"` @@ -136,16 +136,16 @@ func getPlayersHandler(api infrared.API) http.HandlerFunc { } } -// @Summary Disconnect a player -// @Description Disconnect a player by edition via username -// @Tags Player -// @Produce json -// @Param edition path string true "Minecraft edition" Enums(java, bedrock) -// @Param username path string true "Player username" -// @Success 204 -// @Failure 400 {object} api.errorDTO -// @Failure 404 -// @Router /{edition}/players/{username} [delete] +// @Summary Disconnect a player +// @Description Disconnect a player by edition via username +// @Tags Player +// @Produce json +// @Param edition path string true "Minecraft edition" Enums(java, bedrock) +// @Param username path string true "Player username" +// @Success 204 +// @Failure 400 {object} api.errorDTO +// @Failure 404 +// @Router /{edition}/players/{username} [delete] func deletePlayerHandler(api infrared.API) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { editionString := chi.URLParam(r, "edition") @@ -168,15 +168,15 @@ func deletePlayerHandler(api infrared.API) http.HandlerFunc { } } -// @Summary Get a config -// @Description Get a config via ID -// @Tags Config -// @Produce json -// @Param configId path string true "Config ID" -// @Success 200 {string} string "See the documentation or configs folder for more info on this complex struct" -// @Failure 400 {object} api.errorDTO -// @Failure 500 {object} api.errorDTO -// @Router /configs/{configId} [get] +// @Summary Get a config +// @Description Get a config via ID +// @Tags Config +// @Produce json +// @Param configId path string true "Config ID" +// @Success 200 {string} string "See the documentation or configs folder for more info on this complex struct" +// @Failure 400 {object} api.errorDTO +// @Failure 500 {object} api.errorDTO +// @Router /configs/{configId} [get] func getConfig(cfg config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { configID := chi.URLParam(r, "configID") @@ -198,13 +198,13 @@ func getConfig(cfg config.Config) http.HandlerFunc { } } -// @Summary Get all configs -// @Description Get all configs from all providers -// @Tags Config -// @Produce json -// @Success 200 {object} api.getConfigs.respDTO -// @Failure 500 {object} api.errorDTO -// @Router /configs [get] +// @Summary Get all configs +// @Description Get all configs from all providers +// @Tags Config +// @Produce json +// @Success 200 +// @Failure 500 {object} api.errorDTO +// @Router /configs [get] func getConfigs(cfg config.Config) http.HandlerFunc { type respDTO struct { File map[string]map[string]any `json:"file,omitempty"` @@ -231,17 +231,17 @@ func getConfigs(cfg config.Config) http.HandlerFunc { } } -// @Summary Create/Update a config -// @Description Create/Update a config via ID -// @Tags Config -// @Accept json -// @Produce json -// @Param request body map[string]any true "Config" -// @Param configId path string true "Config ID" -// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct" -// @Failure 400 {object} api.errorDTO -// @Failure 500 {object} api.errorDTO -// @Router /configs/{configId} [put] +// @Summary Create/Update a config +// @Description Create/Update a config via ID +// @Tags Config +// @Accept json +// @Produce json +// @Param request body map[string]any true "Config" +// @Param configId path string true "Config ID" +// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct" +// @Failure 400 {object} api.errorDTO +// @Failure 500 {object} api.errorDTO +// @Router /configs/{configId} [put] func putConfig() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { configID := chi.URLParam(r, "configID") @@ -270,15 +270,15 @@ func putConfig() http.HandlerFunc { } } -// @Summary Delete a config -// @Description Delete a config via ID -// @Tags Config -// @Produce json -// @Param configId path string true "Config ID" -// @Success 204 -// @Failure 400 {object} api.errorDTO -// @Failure 500 {object} api.errorDTO -// @Router /configs/{configId} [delete] +// @Summary Delete a config +// @Description Delete a config via ID +// @Tags Config +// @Produce json +// @Param configId path string true "Config ID" +// @Success 204 +// @Failure 400 {object} api.errorDTO +// @Failure 500 {object} api.errorDTO +// @Router /configs/{configId} [delete] func deleteConfig() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { configID := chi.URLParam(r, "configID") @@ -299,13 +299,13 @@ func deleteConfig() http.HandlerFunc { } } -// @Summary Reloads Infrared -// @Description Reads all configs and reloads Infrared -// @Tags Config -// @Produce json -// @Success 200 {string} string "See the documentation or configs folder for more info on this complex struct" -// @Failure 500 {object} api.errorDTO -// @Router /configs/reload [post] +// @Summary Reloads Infrared +// @Description Reads all configs and reloads Infrared +// @Tags Config +// @Produce json +// @Success 200 {string} string "See the documentation or configs folder for more info on this complex struct" +// @Failure 500 {object} api.errorDTO +// @Router /configs/reload [post] func reloadConfigs(cfg config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cfg, err := cfg.Reload()