Merge pull request 'UserList and GroupList for XML' (#28) from gitea-24 into main

Reviewed-on: #28
This commit is contained in:
Thomas Williams 2025-12-09 04:23:12 +13:00
commit 192da1a74f
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package routing
import (
"encoding/xml"
"log"
"net/http"
"slices"
@ -143,6 +144,11 @@ func GroupPost(app *lishwist.Session, session *response.Session, h http.Header,
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 {
admin := app.Admin()
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.Data("", groups)
return response.Data("", GroupList{Groups: groups})
}

View File

@ -1,6 +1,7 @@
package routing
import (
"encoding/xml"
lishwist "lishwist/core"
"lishwist/http/response"
"net/http"
@ -8,6 +9,11 @@ import (
"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 {
admin := app.Admin()
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.Data("", users)
return response.Data("", UserList{Users: users})
}
func User(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response {