UserList and GroupList for XML

This commit is contained in:
Teajey 2025-12-09 00:20:54 +09:00
parent 7bd73b4ddc
commit 0d0aeffef1
Signed by: Teajey
GPG Key ID: 970E790FE834A713
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package routing package routing
import ( import (
"encoding/xml"
"log" "log"
"net/http" "net/http"
"slices" "slices"
@ -143,6 +144,11 @@ func GroupPost(app *lishwist.Session, session *response.Session, h http.Header,
return response.Data("", group) return response.Data("", group)
} }
type GroupList struct {
XMLName xml.Name `xml:"Groups" json:"-"`
Groups []lishwist.Group `xml:"Group"`
}
func Groups(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response { func Groups(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
admin := app.Admin() admin := app.Admin()
if admin == nil { if admin == nil {
@ -154,5 +160,5 @@ func Groups(app *lishwist.Session, session *response.Session, h http.Header, r *
return response.Error(http.StatusInternalServerError, "Failed to get groups: %s", err) return response.Error(http.StatusInternalServerError, "Failed to get groups: %s", err)
} }
return response.Data("", groups) return response.Data("", GroupList{Groups: groups})
} }

View File

@ -1,6 +1,7 @@
package routing package routing
import ( import (
"encoding/xml"
lishwist "lishwist/core" lishwist "lishwist/core"
"lishwist/http/response" "lishwist/http/response"
"net/http" "net/http"
@ -8,6 +9,11 @@ import (
"github.com/Teajey/rsvp" "github.com/Teajey/rsvp"
) )
type UserList struct {
XMLName xml.Name `xml:"Users" json:"-"`
Users []lishwist.User `xml:"User"`
}
func Users(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response { func Users(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {
admin := app.Admin() admin := app.Admin()
if admin == nil { if admin == nil {
@ -19,7 +25,7 @@ func Users(app *lishwist.Session, session *response.Session, h http.Header, r *h
return response.Error(http.StatusInternalServerError, "Failed to get users: %s", err) return response.Error(http.StatusInternalServerError, "Failed to get users: %s", err)
} }
return response.Data("", users) return response.Data("", UserList{Users: users})
} }
func User(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response { func User(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {