-
Notifications
You must be signed in to change notification settings - Fork 0
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
회원관리 기능, 로그인, 로그아웃 기능 개발 #5
Conversation
- 회원 가입 - 회원 정보 조회 - 회원 정보 수정 - build.gradle 의존성 추가
-로그인 -로그아웃 -세션 정보 확인
app/build.gradle
Outdated
|
||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
compileOnly 'org.projectlombok:lombok' |
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.
로그인, 로그아웃, 회원 관리 기능 코드에 대하여 아래와 같은 작업을 수행했습니다. - 필요 없는 import문 정리 - 주석 수정 - 사용 되지 않는 코드 삭제 - 반복되는 코드 리팩토링
- 회원 가입 시 learning에 여러 언어를 넣었는데도 [] 였던 버그 해결
public String login(@Valid @ModelAttribute LoginForm loginForm, BindingResult bindingResult, HttpServletRequest request) { | ||
|
||
if(bindingResult.hasErrors()) { | ||
return "not ok"; |
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.
} | ||
|
||
HttpSession session = request.getSession(); | ||
session.setAttribute(SessionConst.LOGIN_MEMBER, member); |
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.
scale out 했을때(서버가 2대가 됐을 때)는 어떻게 동작하는 것인가요?
public class LoginController { | ||
private final MemberRepository memberRepository; | ||
@PostMapping("/login") | ||
public String login(@Valid @ModelAttribute LoginForm loginForm, BindingResult bindingResult, HttpServletRequest request) { |
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.
@RequestBody을 받지 않은 이유는 Form타입으로 받는 것이 더 좋다고 판단했습니다.
@RestController | ||
@RequiredArgsConstructor | ||
public class LoginController { | ||
private final MemberRepository memberRepository; |
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.
MemberService를 통해서 MemeberRepository접근하는 것이 더 좋아보이긴 하네요.
Member member = new Member(memberForm); | ||
memberRepository.save(member); | ||
return "ok"; |
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.
Member member = new Member(memberForm); | |
memberRepository.save(member); | |
return "ok"; | |
return new Member(memberForm); |
// 사용자 프로필 조회 | ||
@GetMapping("/{user_id}") | ||
public Member findMember(@PathVariable(value = "user_id") Long user_id){ | ||
return memberRepository.findById(user_id); |
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.
return memberRepository.findById(user_id); | |
return new Member(1, ....); |
|
||
// 사용자 프로필 조회 | ||
@GetMapping("/{user_id}") | ||
public Member findMember(@PathVariable(value = "user_id") Long user_id){ |
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.
public Member findMember(@PathVariable(value = "user_id") Long user_id){ | |
public Member findMember(@PathVariable(value = "user_id") Long userId){ |
@Slf4j | ||
@Repository | ||
public class MemberRepository { | ||
private static Map<Long, Member> store = new HashMap<>(); |
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.
이 부분과 관련된 얘기는 다음주에 해보죠.
private Integer point; | ||
private Integer credibility; | ||
|
||
private static long sequence = 0L; |
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.
데이터 동시성 이슈가 있을 수 있겠네요.
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.
@@ -0,0 +1,52 @@ | |||
package org.example.domain.member.dto; |
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.
이 객체는 Entity에 더 가까운 것 같습니다.
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.
이 테스트는 지워도 괜찮을 것 같습니다.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(MemberController.class) |
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.
@WebMvcTest(MemberController.class) | ||
class MemberControllerTest { | ||
@Autowired | ||
private MockMvc mockMvc; |
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.
TestRestTemplate
.param("nationality", memberForm.getNationality()) | ||
.param("native_lang", memberForm.getNative_lang()) | ||
.param("introduction", memberForm.getIntroduction())) | ||
.andExpect(status().isOk()); |
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.
값이 제대로 나오는지에 대한 테스트도 필요할 것 같아요.
lombok plugin을 추가했습니다.
자동으로 생성된 AppTest.java는 현재 필요하지 않아 삭제했습니다.
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
회원 관리 기능
로그인, 로그아웃
테스트