Reorganization of backend + new routes

This commit is contained in:
cdricms
2025-01-29 18:09:41 +01:00
parent 7c66353e63
commit 8110172a38
67 changed files with 1124 additions and 400 deletions

View File

@@ -4,13 +4,14 @@ import (
"context"
"net/http"
core "fr.latosa-escrima/api/core"
core "fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleDelete(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("shortcode")
_, err := core.DB.NewDelete().
Model((*core.Shortcode)(nil)).
Model((*models.Shortcode)(nil)).
Where("code = ?", code).
Exec(context.Background())
if err != nil {

View File

@@ -5,11 +5,12 @@ import (
"encoding/json"
"net/http"
"fr.latosa-escrima/api/core"
"fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleNew(w http.ResponseWriter, r *http.Request) {
var shortcode core.Shortcode
var shortcode models.Shortcode
err := json.NewDecoder(r.Body).Decode(&shortcode)
if err != nil {
core.JSONError{

View File

@@ -4,12 +4,13 @@ import (
"context"
"net/http"
"fr.latosa-escrima/api/core"
"fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleShortcode(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("shortcode")
var shortcode core.Shortcode
var shortcode models.Shortcode
err := core.DB.NewSelect().
Model(&shortcode).
Where("code = ?", code).

View File

@@ -4,11 +4,12 @@ import (
"context"
"net/http"
"fr.latosa-escrima/api/core"
"fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
var shortcodes []core.Shortcode
var shortcodes []models.Shortcode
err := core.DB.NewSelect().Model(&shortcodes).Scan(context.Background())
if err != nil {
core.JSONError{

View File

@@ -8,16 +8,17 @@ import (
"reflect"
"strings"
core "fr.latosa-escrima/api/core"
core "fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
"github.com/google/uuid"
)
type UpdateShortcodeArgs struct {
ID *int64 `json:"id,omitempty"`
Code *string `json:"code,omitempty"` // The shortcode value
Type *core.ShortcodeType `bun:"shortcode_type" json:"type,omitempty"`
Value *string `json:"value,omitempty"`
MediaID *uuid.UUID `json:"media_id,omitempty"` // Nullable reference to another table's ID
ID *int64 `json:"id,omitempty"`
Code *string `json:"code,omitempty"` // The shortcode value
Type *models.ShortcodeType `bun:"shortcode_type" json:"type,omitempty"`
Value *string `json:"value,omitempty"`
MediaID *uuid.UUID `json:"media_id,omitempty"` // Nullable reference to another table's ID
}
func HandleUpdate(w http.ResponseWriter, r *http.Request) {
@@ -31,7 +32,7 @@ func HandleUpdate(w http.ResponseWriter, r *http.Request) {
return
}
var shortcode core.Shortcode
var shortcode models.Shortcode
updateQuery := core.DB.NewUpdate().Model(&shortcode)
val := reflect.ValueOf(updateArgs)
typ := reflect.TypeOf(updateArgs)