add sessions to API.

This commit is contained in:
Miroslav Šedivý 2023-05-15 00:34:37 +02:00
parent 848556adbd
commit 8660c1a256
3 changed files with 33 additions and 0 deletions

View File

@ -45,6 +45,7 @@ func (api *ApiManagerCtx) Route(r types.Router) {
r.Post("/logout", api.Logout)
r.Get("/whoami", api.Whoami)
r.Get("/sessions", api.Sessions)
membersHandler := members.New(api.members)
r.Route("/members", membersHandler.Route)

View File

@ -81,3 +81,16 @@ func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) error {
State: session.State(),
})
}
func (api *ApiManagerCtx) Sessions(w http.ResponseWriter, r *http.Request) error {
sessions := []SessionDataPayload{}
for _, session := range api.sessions.List() {
sessions = append(sessions, SessionDataPayload{
ID: session.ID(),
Profile: session.Profile(),
State: session.State(),
})
}
return utils.HttpSuccess(w, sessions)
}

View File

@ -116,6 +116,25 @@ paths:
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
/api/sessions:
get:
tags:
- session
summary: get sessions
operationId: sessionsGet
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/SessionData'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
#
# room