HEAVY: migrate accounts and logs to service/repo architecture

This commit is contained in:
ari melody 2026-07-31 02:43:45 +01:00
parent 5c255fb34b
commit 49e14b5bc5
Signed by: ari
GPG key ID: CF99829C92678188
37 changed files with 1019 additions and 687 deletions

View file

@ -1,17 +1,18 @@
package api
import (
"context"
"fmt"
"net/http"
"os"
"strings"
"context"
"fmt"
"net/http"
"os"
"strings"
"arimelody-web/controller"
"arimelody-web/model"
"arimelody-web/controller"
"arimelody-web/model"
"arimelody-web/model/app"
)
func Handler(app *model.AppState) http.Handler {
func Handler(app *app.AppState) http.Handler {
mux := http.NewServeMux()
// TODO: generate API keys on the frontend
@ -166,7 +167,7 @@ func requireAccount(next http.Handler) http.Handler {
})
}
func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
func getSession(app *app.AppState, r *http.Request) (*model.Session, error) {
var token string
// check cookies first
@ -184,7 +185,7 @@ func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
if token == "" { return nil, nil }
// fetch existing session
session, err := controller.GetSession(app.DB, token)
session, err := controller.GetSession(app, token)
if err != nil && !strings.Contains(err.Error(), "no rows") {
return nil, fmt.Errorf("Failed to retrieve session: %v\n", err)