mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-11-25 17:21:27 +00:00
Move away from dbmate, use PolySchema
This commit is contained in:
1 parent
52399c42f1
commit
2a14f3f84c
99 files changed
+1583
-1691
No files matched your search
@@ -2,32 +2,17 @@ package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
c "npm/internal/api/context"
|
||||
h "npm/internal/api/http"
|
||||
"npm/internal/api/middleware"
|
||||
"npm/internal/entity/accesslist"
|
||||
)
|
||||
|
||||
// GetAccessLists will return a list of Access Lists
|
||||
// Route: GET /access-lists
|
||||
func GetAccessLists() func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
pageInfo, err := getPageInfoFromRequest(r)
|
||||
if err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
items, err := accesslist.List(pageInfo, middleware.GetFiltersFromContext(r))
|
||||
if err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
} else {
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, items)
|
||||
}
|
||||
}
|
||||
return listHandler(accesslist.List)
|
||||
}
|
||||
|
||||
// GetAccessList will return a single access list
|
||||
@@ -54,25 +39,7 @@ func GetAccessList() func(http.ResponseWriter, *http.Request) {
|
||||
// Route: POST /access-lists
|
||||
func CreateAccessList() func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
bodyBytes, _ := r.Context().Value(c.BodyCtxKey).([]byte)
|
||||
|
||||
var newItem accesslist.Model
|
||||
err := json.Unmarshal(bodyBytes, &newItem)
|
||||
if err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, h.ErrInvalidPayload.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Get userID from token
|
||||
userID, _ := r.Context().Value(c.UserIDCtxKey).(uint)
|
||||
newItem.UserID = userID
|
||||
|
||||
if err = newItem.Save(); err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, fmt.Sprintf("Unable to save Access List: %s", err.Error()), nil)
|
||||
return
|
||||
}
|
||||
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, newItem)
|
||||
createUserOwned(w, r, &accesslist.Model{}, "Access List")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user