Skip to content

Commit 0c1ee0a

Browse files
committed
Enhance member profiles and related components
- Create separate MemberProfile struct for more user information (#51) - Update Member struct to reflect changes in the member table (#51) - Modify db queries to work with the new member_profile table (#51) - Update GetMember query to join member and member_profile tables (#51) - Change UpdateMemberByEmail to UpdateMemberProfileByID (#51) - Adjust logic in EditMemberProfile to use UpdateMemberProfileByID (#51) - Add new fields to edit profile template (pronouns, bio, etc) (#51) - Update member.html template to display new profile information (#51) - Modify createOrReturnID function to add a member_profile entry (#51) - Remove unused fields from member table (last_chat, last_search) - Add necessary indexes and foreign key constraints for member_profile - Update tests to accommodate changes in member profile handling Change-Id: I2174db3e70a75a69f83221a9391f99a6d456a09b Signed-off-by: Ian Meyer <[email protected]>
1 parent db4d594 commit 0c1ee0a

File tree

9 files changed

+433
-303
lines changed

9 files changed

+433
-303
lines changed

models.go

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

queries.sql.go

Lines changed: 62 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ func (s *DiscussService) CreateThreadPost(w http.ResponseWriter, r *http.Request
443443
}
444444

445445
func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Request) {
446+
s.logger.DebugContext(r.Context(), "entering EditMemberProfile")
447+
defer s.logger.DebugContext(r.Context(), "exiting EditMemberProfile")
448+
446449
if r.Method != http.MethodPost && r.Method != http.MethodGet {
447450
s.renderError(w, http.StatusMethodNotAllowed)
448451
return
@@ -492,10 +495,13 @@ func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Reques
492495
// Get the new photo URL from the form
493496
newPhotoURL := r.Form.Get("photo_url")
494497
newLocation := r.Form.Get("location")
498+
newPreferredName := r.Form.Get("preferred_name")
499+
newBio := r.Form.Get("bio")
500+
newPronouns := r.Form.Get("pronouns")
495501

496502
// Update the member's profile
497-
err = s.queries.UpdateMemberByEmail(r.Context(), UpdateMemberByEmailParams{
498-
Email: user.Email,
503+
err = s.queries.UpdateMemberProfileByID(r.Context(), UpdateMemberProfileByIDParams{
504+
MemberID: user.ID,
499505
PhotoUrl: pgtype.Text{
500506
String: parseHTMLStrict(newPhotoURL),
501507
Valid: true,
@@ -504,8 +510,21 @@ func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Reques
504510
String: parseHTMLStrict(newLocation),
505511
Valid: true,
506512
},
513+
PreferredName: pgtype.Text{
514+
String: parseHTMLStrict(newPreferredName),
515+
Valid: true,
516+
},
517+
Bio: pgtype.Text{
518+
String: parseHTMLStrict(newBio),
519+
Valid: true,
520+
},
521+
Pronouns: pgtype.Text{
522+
String: parseHTMLStrict(newPronouns),
523+
Valid: true,
524+
},
507525
})
508526
if err != nil {
527+
s.logger.ErrorContext(r.Context(), "UpdateMemberProfileByID", slog.String("error", err.Error()))
509528
s.renderError(w, http.StatusInternalServerError)
510529
return
511530
}

server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ func (m *MockQueries) ListThreads(ctx context.Context, arg ListThreadsParams) ([
14091409
}, nil
14101410
}
14111411

1412-
func (m *MockQueries) UpdateMemberByEmail(ctx context.Context, arg UpdateMemberByEmailParams) error {
1412+
func (m *MockQueries) UpdateMemberProfileByID(ctx context.Context, arg UpdateMemberProfileByIDParams) error {
14131413
// Mock implementation
14141414
return nil
14151415
}

sqlc/queries.sql

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,25 @@ SELECT id::bigint, is_admin::boolean FROM createOrReturnID($1);
2121
SELECT id FROM member WHERE email = $1;
2222

2323
-- name: GetMember :one
24-
SELECT email, location, id, date_joined, photo_url FROM member WHERE id = $1;
24+
SELECT
25+
m.email,
26+
mp.location,
27+
m.id,
28+
mp.bio,
29+
mp.timezone,
30+
mp.preferred_name,
31+
mp.proper_name,
32+
mp.pronouns,
33+
m.date_joined,
34+
mp.photo_url
35+
FROM
36+
member m
37+
LEFT JOIN
38+
member_profile mp
39+
ON
40+
m.id = mp.member_id
41+
WHERE
42+
m.id = $1;
2543

2644
-- name: ListThreads :many
2745
SELECT
@@ -146,11 +164,15 @@ FROM thread_post tp LEFT JOIN member m
146164
ON tp.member_id=m.id
147165
WHERE tp.id=$1 AND m.id=$2;
148166

149-
-- name: UpdateMemberByEmail :exec
150-
UPDATE member SET
167+
-- name: UpdateMemberProfileByID :exec
168+
UPDATE member_profile SET
151169
photo_url = $2,
152-
location = $3
153-
WHERE email = $1;
170+
location = $3,
171+
bio = $4,
172+
timezone = $5,
173+
preferred_name = $6,
174+
pronouns = $7
175+
WHERE member_id = $1;
154176

155177
-- name: UpdateThread :exec
156178
UPDATE thread SET

0 commit comments

Comments
 (0)