-
Notifications
You must be signed in to change notification settings - Fork 0
π Profile Search #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c8fe5aa
4cfbf8d
a07c48b
a3bffe3
a7196fa
99593bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.mycom.socket.go_socket.controller; | ||
|
|
||
| import com.mycom.socket.auth.security.MemberDetails; | ||
| import com.mycom.socket.go_socket.dto.response.ProfileResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/profile") | ||
| public class ProfileController { | ||
|
|
||
| @GetMapping | ||
| public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) { | ||
| return ProfileResponse.of(memberDetails.getMember()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.mycom.socket.go_socket.dto.response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.mycom.socket.go_socket.entity.Member; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public record ProfileResponse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| String email, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| String nickname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| String intro | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static ProfileResponse of(Member member) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new ProfileResponse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| member.getEmail(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| member.getNickname(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| member.getIntro() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion ν©ν 리 λ©μλμ μ ν¨μ± κ²μ¬μ λ¬Έμνκ° νμν©λλ€.
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€: + /**
+ * Member μν°ν°λ‘λΆν° ProfileResponseλ₯Ό μμ±ν©λλ€.
+ *
+ * @param member νλ‘ν μ 보λ₯Ό κ°μ Έμ¬ νμ μν°ν° (nullμ΄ μλμ΄μΌ ν¨)
+ * @return μμ±λ ProfileResponse κ°μ²΄
+ * @throws IllegalArgumentException memberκ° nullμΈ κ²½μ°
+ */
public static ProfileResponse of(Member member) {
+ if (member == null) {
+ throw new IllegalArgumentException("Member must not be null");
+ }
+
return new ProfileResponse(
member.getEmail(),
member.getNickname(),
member.getIntro()
);
}π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.mycom.socket.go_socket.service; | ||
|
|
||
| import com.mycom.socket.go_socket.repository.MemberRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class MemberService { | ||
|
|
||
| private final MemberRepository memberRepository; | ||
| } | ||
|
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μλΉμ€ ν΄λμ€μ νμν λ©μλ ꡬνμ΄ λλ½λμμ΅λλ€. νμ¬
λ€μκ³Ό κ°μ λ©μλ ꡬνμ μ μλ립λλ€: @Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberService {
private final MemberRepository memberRepository;
+
+ public Member getMemberByEmail(String email) {
+ return memberRepository.findByEmail(email)
+ .orElseThrow(() -> new EntityNotFoundException("νμμ μ°Ύμ μ μμ΅λλ€."));
+ }
+
+ public boolean existsByEmail(String email) {
+ return memberRepository.existsByEmail(email);
+ }
}
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ spring: | |
| jpa: | ||
| show-sql: true | ||
| hibernate: | ||
| ddl-auto: create | ||
| ddl-auto: update | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
컨νΈλ‘€λ¬μ μμΈ μ²λ¦¬μ API λ¬Έμνκ° νμν©λλ€.
λ€μ μ¬νλ€μ΄ λλ½λμ΄ μμ΅λλ€:
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€: