fix(api): return correct struct in /auth/discord/callback

This commit is contained in:
Sam 2022-06-17 15:18:44 +02:00
parent ecd049088a
commit ad2c527e0e
2 changed files with 31 additions and 3 deletions

View file

@ -4,11 +4,13 @@ import (
"net/http"
"os"
"codeberg.org/u1f320/pronouns.cc/backend/db"
"codeberg.org/u1f320/pronouns.cc/backend/log"
"codeberg.org/u1f320/pronouns.cc/backend/server"
"emperror.dev/errors"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/rs/xid"
)
type Server struct {
@ -17,6 +19,31 @@ type Server struct {
RequireInvite bool
}
type userResponse struct {
ID xid.ID `json:"id"`
Username string `json:"username"`
DisplayName *string `json:"display_name"`
Bio *string `json:"bio"`
AvatarURL *string `json:"avatar_url"`
Links []string `json:"links"`
Discord *string `json:"discord"`
DiscordUsername *string `json:"discord_username"`
}
func dbUserToUserResponse(u db.User) *userResponse {
return &userResponse{
ID: u.ID,
Username: u.Username,
DisplayName: u.DisplayName,
Bio: u.Bio,
AvatarURL: u.AvatarURL,
Links: u.Links,
Discord: u.Discord,
DiscordUsername: u.DiscordUsername,
}
}
func Mount(srv *server.Server, r chi.Router) {
s := &Server{
Server: srv,