Files
latosa-escrima/backend/api/shortcodes/shortcode.go
cdricms 501ffaea17 Reorganized API + added db migrations
Read the README file for more informations
2025-01-28 17:41:05 +01:00

32 lines
602 B
Go

package shortcodes
import (
"context"
"net/http"
"fr.latosa-escrima/api/core"
)
func HandleShortcode(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("shortcode")
var shortcode core.Shortcode
err := core.DB.NewSelect().
Model(&shortcode).
Where("code = ?", code).
Limit(1).
Scan(context.Background())
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: "Shortcode found",
Data: shortcode,
}.Respond(w, http.StatusOK)
}