diff --git a/backend/db/db.go b/backend/db/db.go index 7a15a62..a488b76 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -7,12 +7,9 @@ import ( "net/url" "os" - "codeberg.org/u1f320/pronouns.cc/backend/log" "emperror.dev/errors" "github.com/Masterminds/squirrel" "github.com/jackc/pgconn" - "github.com/jackc/pgx/v4" - "github.com/jackc/pgx/v4/log/zapadapter" "github.com/jackc/pgx/v4/pgxpool" "github.com/mediocregopher/radix/v4" "github.com/minio/minio-go/v7" @@ -38,15 +35,7 @@ type DB struct { } func New() (*DB, error) { - pgxCfg, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL")) - if err != nil { - return nil, errors.Wrap(err, "parsing config") - } - pgxCfg.ConnConfig.LogLevel = pgx.LogLevelDebug - pgxCfg.ConnConfig.Logger = zapadapter.NewLogger(log.Logger) - - pool, err := pgxpool.ConnectConfig(context.Background(), pgxCfg) - // pool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL")) + pool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL")) if err != nil { return nil, errors.Wrap(err, "creating postgres client") } diff --git a/backend/db/field.go b/backend/db/field.go index 4e5296f..e73577b 100644 --- a/backend/db/field.go +++ b/backend/db/field.go @@ -52,7 +52,7 @@ func (f Field) Validate() string { // UserFields returns the fields associated with the given user ID. func (db *DB) UserFields(ctx context.Context, id xid.ID) (fs []Field, err error) { - sql, args, err := sq.Select("*").From("user_fields").Where("user_id = ?", id).OrderBy("id").ToSql() + sql, args, err := sq.Select("id", "name", "entries").From("user_fields").Where("user_id = ?", id).OrderBy("id").ToSql() if err != nil { return fs, errors.Wrap(err, "building sql") } @@ -88,7 +88,7 @@ func (db *DB) SetUserFields(ctx context.Context, tx pgx.Tx, userID xid.ID, field // MemberFields returns the fields associated with the given member ID. func (db *DB) MemberFields(ctx context.Context, id xid.ID) (fs []Field, err error) { - sql, args, err := sq.Select("*").From("member_fields").Where("member_id = ?", id).OrderBy("id").ToSql() + sql, args, err := sq.Select("id", "name", "entries").From("member_fields").Where("member_id = ?", id).OrderBy("id").ToSql() if err != nil { return fs, errors.Wrap(err, "building sql") } diff --git a/backend/routes/auth/discord.go b/backend/routes/auth/discord.go index d0a9b78..38214f0 100644 --- a/backend/routes/auth/discord.go +++ b/backend/routes/auth/discord.go @@ -61,7 +61,7 @@ func (s *Server) discordCallback(w http.ResponseWriter, r *http.Request) error { } cfg := discordOAuthConfig - cfg.RedirectURL = decoded.CallbackDomain + "/login/discord" + cfg.RedirectURL = decoded.CallbackDomain + "/auth/login/discord" token, err := cfg.Exchange(r.Context(), decoded.Code) if err != nil { log.Errorf("exchanging oauth code: %v", err) diff --git a/backend/routes/auth/routes.go b/backend/routes/auth/routes.go index fcd0194..8b781a2 100644 --- a/backend/routes/auth/routes.go +++ b/backend/routes/auth/routes.go @@ -105,10 +105,10 @@ func (s *Server) oauthURLs(w http.ResponseWriter, r *http.Request) error { // copy Discord config and set redirect url discordCfg := discordOAuthConfig - discordCfg.RedirectURL = req.CallbackDomain + "/login/discord" + discordCfg.RedirectURL = req.CallbackDomain + "/auth/login/discord" render.JSON(w, r, oauthURLsResponse{ - Discord: discordCfg.AuthCodeURL(state), + Discord: discordCfg.AuthCodeURL(state) + "&prompt=none", }) return nil } diff --git a/backend/routes/user/get_user.go b/backend/routes/user/get_user.go index a8db049..ca3f699 100644 --- a/backend/routes/user/get_user.go +++ b/backend/routes/user/get_user.go @@ -35,7 +35,9 @@ type PartialMember struct { ID xid.ID `json:"id"` Name string `json:"name"` DisplayName *string `json:"display_name"` + Bio *string `json:"bio"` AvatarURLs []string `json:"avatar_urls"` + Links []string `json:"links"` Names []db.FieldEntry `json:"names"` Pronouns []db.PronounEntry `json:"pronouns"` } @@ -59,7 +61,9 @@ func dbUserToResponse(u db.User, fields []db.Field, members []db.Member) GetUser ID: members[i].ID, Name: members[i].Name, DisplayName: members[i].DisplayName, + Bio: members[i].Bio, AvatarURLs: db.NotNull(members[i].AvatarURLs), + Links: db.NotNull(members[i].Links), Names: db.NotNull(members[i].Names), Pronouns: db.NotNull(members[i].Pronouns), } diff --git a/backend/routes/user/patch_user.go b/backend/routes/user/patch_user.go index 2550b2e..2ad0ac6 100644 --- a/backend/routes/user/patch_user.go +++ b/backend/routes/user/patch_user.go @@ -23,7 +23,6 @@ type PatchUserRequest struct { } // patchUser parses a PatchUserRequest and updates the user with the given ID. -// TODO: could this be refactored to be less repetitive? names, pronouns, and fields are all validated in the same way func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error { ctx := r.Context() diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index 8e31b78..dc4c2b5 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -3,8 +3,8 @@ export interface User { name: string; display_name: string | null; bio: string | null; - avatar_urls: string[] | null; - links: string[] | null; + avatar_urls: string[]; + links: string[]; names: FieldEntry[]; pronouns: Pronoun[]; @@ -46,15 +46,16 @@ export interface PartialMember { id: string; name: string; display_name: string | null; - avatar_urls: string[] | null; + bio: string | null; + avatar_urls: string[]; + links: string[]; + names: FieldEntry[]; + pronouns: Pronoun[]; } export interface Member extends PartialMember { - bio: string | null; - links: string | null; - names: FieldEntry[]; - pronouns: Pronoun[]; fields: Field[]; + user: MemberPartialUser; } @@ -62,7 +63,7 @@ export interface MemberPartialUser { id: string; name: string; display_name: string | null; - avatar_urls: string[] | null; + avatar_urls: string[]; } export interface APIError { diff --git a/frontend/src/lib/components/FallbackImage.svelte b/frontend/src/lib/components/FallbackImage.svelte index 3370030..e5d3c52 100644 --- a/frontend/src/lib/components/FallbackImage.svelte +++ b/frontend/src/lib/components/FallbackImage.svelte @@ -1,6 +1,7 @@ -{#if urls} +{#if urls.length > 0} {:else} - + {/if} diff --git a/frontend/src/lib/components/FieldCard.svelte b/frontend/src/lib/components/FieldCard.svelte index 814c2d6..2dd270b 100644 --- a/frontend/src/lib/components/FieldCard.svelte +++ b/frontend/src/lib/components/FieldCard.svelte @@ -9,7 +9,7 @@
+
+ {member.display_name ?? member.name}
+
+ {#if pronouns}
+
+ {pronouns}
+ {/if}
+