HEAVY: migrate accounts and logs to service/repo architecture
This commit is contained in:
parent
5c255fb34b
commit
49e14b5bc5
37 changed files with 1019 additions and 687 deletions
|
|
@ -1,21 +1,21 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/log"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
)
|
||||
|
||||
func ServeRelease(app *model.AppState, release *model.Release) http.Handler {
|
||||
func ServeRelease(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// only allow authorised users to view hidden releases
|
||||
privileged := false
|
||||
|
|
@ -127,7 +127,7 @@ func ServeRelease(app *model.AppState, release *model.Release) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func ServeCatalog(app *model.AppState) http.Handler {
|
||||
func ServeCatalog(app *app.AppState) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
releases, err := controller.GetAllReleases(app.DB, false, 0, true)
|
||||
if err != nil {
|
||||
|
|
@ -188,7 +188,7 @@ func ServeCatalog(app *model.AppState) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func CreateRelease(app *model.AppState) http.Handler {
|
||||
func CreateRelease(app *app.AppState) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ func CreateRelease(app *model.AppState) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Release \"%s\" created by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" created by \"%s\".", release.ID, session.Account.Username)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
|
@ -238,7 +238,7 @@ func CreateRelease(app *model.AppState) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func UpdateRelease(app *model.AppState, release *model.Release) http.Handler {
|
||||
func UpdateRelease(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -307,11 +307,11 @@ func UpdateRelease(app *model.AppState, release *model.Release) http.Handler {
|
|||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateReleaseTracks(app *model.AppState, release *model.Release) http.Handler {
|
||||
func UpdateReleaseTracks(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -336,11 +336,11 @@ func UpdateReleaseTracks(app *model.AppState, release *model.Release) http.Handl
|
|||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Tracklist for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Tracklist for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateReleaseCredits(app *model.AppState, release *model.Release) http.Handler {
|
||||
func UpdateReleaseCredits(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -381,11 +381,11 @@ func UpdateReleaseCredits(app *model.AppState, release *model.Release) http.Hand
|
|||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Credits for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Credits for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateReleaseLinks(app *model.AppState, release *model.Release) http.Handler {
|
||||
func UpdateReleaseLinks(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -410,11 +410,11 @@ func UpdateReleaseLinks(app *model.AppState, release *model.Release) http.Handle
|
|||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Links for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Links for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteRelease(app *model.AppState, release *model.Release) http.Handler {
|
||||
func DeleteRelease(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
|
|
@ -428,6 +428,6 @@ func DeleteRelease(app *model.AppState, release *model.Release) http.Handler {
|
|||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_MUSIC, "Release \"%s\" deleted by \"%s\".", release.ID, session.Account.Username)
|
||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" deleted by \"%s\".", release.ID, session.Account.Username)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue