Skip to content

Commit

Permalink
Enhance member profiles and related components
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
imeyer committed Oct 13, 2024
1 parent db4d594 commit 0c1ee0a
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 303 deletions.
16 changes: 12 additions & 4 deletions models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 62 additions & 18 deletions queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ func (s *DiscussService) CreateThreadPost(w http.ResponseWriter, r *http.Request
}

func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Request) {
s.logger.DebugContext(r.Context(), "entering EditMemberProfile")
defer s.logger.DebugContext(r.Context(), "exiting EditMemberProfile")

if r.Method != http.MethodPost && r.Method != http.MethodGet {
s.renderError(w, http.StatusMethodNotAllowed)
return
Expand Down Expand Up @@ -492,10 +495,13 @@ func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Reques
// Get the new photo URL from the form
newPhotoURL := r.Form.Get("photo_url")
newLocation := r.Form.Get("location")
newPreferredName := r.Form.Get("preferred_name")
newBio := r.Form.Get("bio")
newPronouns := r.Form.Get("pronouns")

// Update the member's profile
err = s.queries.UpdateMemberByEmail(r.Context(), UpdateMemberByEmailParams{
Email: user.Email,
err = s.queries.UpdateMemberProfileByID(r.Context(), UpdateMemberProfileByIDParams{
MemberID: user.ID,
PhotoUrl: pgtype.Text{
String: parseHTMLStrict(newPhotoURL),
Valid: true,
Expand All @@ -504,8 +510,21 @@ func (s *DiscussService) EditMemberProfile(w http.ResponseWriter, r *http.Reques
String: parseHTMLStrict(newLocation),
Valid: true,
},
PreferredName: pgtype.Text{
String: parseHTMLStrict(newPreferredName),
Valid: true,
},
Bio: pgtype.Text{
String: parseHTMLStrict(newBio),
Valid: true,
},
Pronouns: pgtype.Text{
String: parseHTMLStrict(newPronouns),
Valid: true,
},
})
if err != nil {
s.logger.ErrorContext(r.Context(), "UpdateMemberProfileByID", slog.String("error", err.Error()))
s.renderError(w, http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ func (m *MockQueries) ListThreads(ctx context.Context, arg ListThreadsParams) ([
}, nil
}

func (m *MockQueries) UpdateMemberByEmail(ctx context.Context, arg UpdateMemberByEmailParams) error {
func (m *MockQueries) UpdateMemberProfileByID(ctx context.Context, arg UpdateMemberProfileByIDParams) error {
// Mock implementation
return nil
}
Expand Down
32 changes: 27 additions & 5 deletions sqlc/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,25 @@ SELECT id::bigint, is_admin::boolean FROM createOrReturnID($1);
SELECT id FROM member WHERE email = $1;

-- name: GetMember :one
SELECT email, location, id, date_joined, photo_url FROM member WHERE id = $1;
SELECT
m.email,
mp.location,
m.id,
mp.bio,
mp.timezone,
mp.preferred_name,
mp.proper_name,
mp.pronouns,
m.date_joined,
mp.photo_url
FROM
member m
LEFT JOIN
member_profile mp
ON
m.id = mp.member_id
WHERE
m.id = $1;

-- name: ListThreads :many
SELECT
Expand Down Expand Up @@ -146,11 +164,15 @@ FROM thread_post tp LEFT JOIN member m
ON tp.member_id=m.id
WHERE tp.id=$1 AND m.id=$2;

-- name: UpdateMemberByEmail :exec
UPDATE member SET
-- name: UpdateMemberProfileByID :exec
UPDATE member_profile SET
photo_url = $2,
location = $3
WHERE email = $1;
location = $3,
bio = $4,
timezone = $5,
preferred_name = $6,
pronouns = $7
WHERE member_id = $1;

-- name: UpdateThread :exec
UPDATE thread SET
Expand Down
Loading

0 comments on commit 0c1ee0a

Please sign in to comment.