Started to work the shortcodes
This commit is contained in:
31
backend/api/get_shortcode.go
Normal file
31
backend/api/get_shortcode.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"fr.latosa-escrima/api/core"
|
||||
)
|
||||
|
||||
func HandleGetShortcode(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)
|
||||
}
|
||||
Reference in New Issue
Block a user