Skip to content

Members backend CRUD functions#43

Open
Allimonae wants to merge 13 commits into
mainfrom
user-profile
Open

Members backend CRUD functions#43
Allimonae wants to merge 13 commits into
mainfrom
user-profile

Conversation

@Allimonae

Copy link
Copy Markdown
Contributor

Note: Submitting this PR to see if I'm on track. Have yet to finish MemberSqlRepo.java, MemberController.java, and local testing

Files created:

1. Member.java
(src/main/java/org/patinanetwork/patchats/common/db/models/member/Member.java)

  • Defines member entity that maps to members db

2. MemberRepo.java (src/main/java/org/patinanetwork/patchats/common/db/repos/member/MemberRepo.java)

  • Defines required methods for MemberSqlRepo

3. MemberSqlRepo.java (src/main/java/org/patinanetwork/patchats/common/db/repos/member/MemberSqlRepo.java)

  • Implements MemberRepo
  • Empty for now, will complete later

4. MemberService.java (src/main/java/org/patinanetwork/patchats/api/member/MemberService.java)

  • Handles validation logic and entity construction
  • Helper functions to convert CreateMemberRequest and UpdateMemberRequest to member object

5. MemberController.java
(src/main/java/org/patinanetwork/patchats/api/member/MemberController.java)

  • Exposes CRUD endpoints under api/members
  • Not complete

5. MemberDto.java, CreateMemberRequest.java, UpdateMemberRequest.java (src/main/java/org/patinanetwork/patchats/common/dto/member/CreateMemberRequest.java, src/main/java/org/patinanetwork/patchats/common/dto/member/UpdateMemberRequest.java, src/main/java/org/patinanetwork/patchats/common/dto/member/MemberDto.java)

  • Defines what member fields are sent from the frontend
  • Currently reflects public UI, will split off PublicMemberDto and AdminMemberDto
  • CreateMemberRequest and UpdateMemberRequest defines and validates request body for createMember and updateMember

6. UserProfile.page.tsx (js/src/features/user-profile/UserProfile.page.tsx)

  • Just the title for now

Files changed:

1. V0001__Create_members_table.sql (db/migration/V0001__Create_members_table.sql)

  • Naming convention changes
  • introduction and active not null

2. SignUpForm.tsx, user-profile/api/schemas.ts, user-profile/types.ts
(js/src/features/sign-up/components/SignUpForm.tsx, js/src/features/user-profile/api/schemas.ts, js/src/features/user-profile/types.ts)

  • Changed SignUpForm naming convention to UserProfile
  • Updated imports since sign-up and user-profile uses shared types/schemas

3. signUpFormConfig.ts
(js/src/features/sign-up/components/signUpFormConfig.ts)

  • Removed talking points as this is now a text field

@Allimonae Allimonae requested a review from a team as a code owner July 6, 2026 19:30
@graphite-app graphite-app Bot requested review from Arshadul-Monir and arklian July 6, 2026 19:35
Comment on lines +59 to +60
Member updatedMember = memberRepo.updateMember(member);
return MemberDto.from(updatedMember);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch: memberRepo.updateMember() returns Optional<Member> (as defined in MemberRepo interface line 40), but the code tries to assign it directly to Member updatedMember. This will cause a compilation error.

Fix:

Member updatedMember = memberRepo.updateMember(member)
    .orElseThrow(() -> new ResponseStatusException(
        HttpStatus.INTERNAL_SERVER_ERROR, 
        "Failed to update member"));
return MemberDto.from(updatedMember);
Suggested change
Member updatedMember = memberRepo.updateMember(member);
return MemberDto.from(updatedMember);
Member updatedMember = memberRepo.updateMember(member)
.orElseThrow(() -> new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR,
"Failed to update member"));
return MemberDto.from(updatedMember);

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@graphite-app

graphite-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

Graphite Automations

"Request reviewers once CI passes" took an action on this PR • (07/06/26)

2 reviewers were added to this PR based on Henry Chen's automation.

… updatedMember throws error if member not found
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

email TEXT UNIQUE NOT NULL,
linked_url TEXT,
bio TEXT,
linked_in_url TEXT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These modifications should be made in a follow up migration file, not in this existing one. The documentation talks about this (as these will only run once).

You can use ALTER TABLE ... RENAME COLUMN ... to accomplish this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, got feedback from henry that changes to migration should be in its own PR

Comment thread js/src/features/sign-up/components/signUpFormConfig.ts

public MemberDto createMember(CreateMemberRequest request) {
if (memberRepo.getMemberByEmail(request.email()).isPresent()) {
throw new ResponseStatusException(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we want to have an abstraction of logic between the MemberService and the controller.

MemberService should not necessarily know about what HTTP behavior/code we're going to emit for each case. That's what the controller is for. Any idea for a better way we could handle this kind of error?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are using 404's multiple times, here is a useful guide, I've used this before and it's pretty cool what Spring can do: https://dev.to/realnamehidden1_61/how-do-you-map-different-exceptions-to-different-http-status-codes-in-spring-boot-2j83


public MemberDto updateMember(UpdateMemberRequest request, UUID id) {
if (memberRepo.getMemberById(id).isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Member with ID " + id + " does not exist");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above. (For HTTP codes)

throw new ResponseStatusException(
HttpStatus.CONFLICT, "Member with email " + request.email() + " already exists");
}
Member member = Member.builder()

@spiffyy99 spiffyy99 Jul 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to just use the existing member object from the repo? We already check if it exists above.

If we're creating a whole new member object, we might be losing information from the old object. (We can't assume that the update request has all the same data as the member object, there may be some stuff we don't want to update :))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to highlight the member builder in updateMember? If so, i'll work on making the updateMember support partial updates rather than full updates, and not have to build a member for every update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants