Skip to content
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

Merged
merged 8 commits into from
Dec 15, 2024

Conversation

KanuBang
Copy link
Collaborator

회원 관리 기능

  • 회원 가입
  • 회원 프로필 조회
  • 회원 프로필 수정

로그인, 로그아웃

  • 로그인
  • 로그아웃
  • 세션 조회

테스트

  • 회원 관리 기능 테스트
  • 로그인, 로그아웃 테스트

- 회원 가입
- 회원 정보 조회
- 회원 정보 수정
- build.gradle 의존성 추가
-로그인
-로그아웃
-세션 정보 확인
@KanuBang KanuBang requested a review from f-lab-lyan December 10, 2024 04:20
@f-lab-lyan
Copy link
Collaborator

image

이 커밋은 다른 PR에서 처리된 것이 아닌가요?

app/build.gradle Outdated

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
Copy link
Collaborator

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";
Copy link
Collaborator

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);
Copy link
Collaborator

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) {
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

MemberService를 통해서 MemeberRepository접근하는 것이 더 좋아보이긴 하네요.

Comment on lines +23 to +25
Member member = new Member(memberForm);
memberRepository.save(member);
return "ok";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return memberRepository.findById(user_id);
return new Member(1, ....);


// 사용자 프로필 조회
@GetMapping("/{user_id}")
public Member findMember(@PathVariable(value = "user_id") Long user_id){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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<>();
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

데이터 동시성 이슈가 있을 수 있겠네요.

Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 객체는 Entity에 더 가까운 것 같습니다.

Copy link
Collaborator

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)
Copy link
Collaborator

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;
Copy link
Collaborator

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());
Copy link
Collaborator

Choose a reason for hiding this comment

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

값이 제대로 나오는지에 대한 테스트도 필요할 것 같아요.

lombok plugin을 추가했습니다.
자동으로 생성된 AppTest.java는 현재 필요하지 않아 삭제했습니다.
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@KanuBang KanuBang merged commit 5b3fecb into main Dec 15, 2024
1 of 2 checks passed
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