Skip to content

Commit

Permalink
fix: fix miss for member domain
Browse files Browse the repository at this point in the history
  • Loading branch information
stoneHee99 committed Dec 20, 2023
1 parent 72a0ee6 commit 89aac97
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import kr.co.yigil.auth.Auth;
import kr.co.yigil.auth.domain.Accessor;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
Expand All @@ -16,11 +18,12 @@ public class LoginArgumentResolver implements HandlerMethodArgumentResolver {

@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().equals(Accessor.class);
return parameter.withContainingClass(Long.class)
.hasParameterAnnotation(Auth.class);
}

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
public Object resolveArgument(@NotNull MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
HttpSession session = request.getSession(false);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/kr/co/yigil/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Member {
private MemberStatus status;

@Enumerated(value = EnumType.STRING)
private SocialLoginType type;
private SocialLoginType socialLoginType;

@CreatedDate
@Column(updatable = false)
Expand All @@ -63,7 +63,7 @@ public Member(final String email, final String socialLoginId, final String nickn
this.nickname = nickname;
this.profileImageUrl = profileImageUrl;
this.status = MemberStatus.ACTIVE;
this.type = SocialLoginType.valueOf(socialLoginTypeString.toUpperCase());
this.socialLoginType = SocialLoginType.valueOf(socialLoginTypeString.toUpperCase());
this.joinedAt = LocalDateTime.now();
this.modifiedAt = LocalDateTime.now();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kr.co.yigil.member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MemberDeleteResponse {
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import kr.co.yigil.auth.domain.Accessor;
import kr.co.yigil.member.application.MemberService;
import kr.co.yigil.member.dto.request.MemberUpdateRequest;
import kr.co.yigil.member.dto.response.MemberDeleteResponse;
import kr.co.yigil.member.dto.response.MemberInfoResponse;
import kr.co.yigil.member.dto.response.MemberUpdateResponse;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -29,13 +30,24 @@ public ResponseEntity<MemberInfoResponse> getMyInfo(@Auth final Accessor accesso
return ResponseEntity.ok().body(response);
}

@PutMapping("/api/v1/member")
@MemberOnly
public ResponseEntity<MemberUpdateResponse> updateMyInfo(@Auth final Accessor accessor, @RequestBody
MemberUpdateRequest request) {
final MemberUpdateResponse response = memberService.updateMemberInfo(accessor.getMemberId(), request);
return ResponseEntity.ok().body(response);
}

@DeleteMapping("/api/v1/member")
@MemberOnly
public ResponseEntity<MemberDeleteResponse> withdrawService(@Auth final Accessor accessor) {
return ResponseEntity.ok().body(new MemberDeleteResponse());
}

// @PutMapping("/api/v1/member")
// public ResponseEntity<MemberUpdateResponse> updateMyInfo(
// @PathVariable("member_id") final Long memberId,
// @RequestBody MemberUpdateRequest request
// ) {
// MemberUpdateResponse response = memberService.updateMemberInfo(memberId, request);
// return ResponseEntity.ok(response);
// }

@GetMapping("/api/v1/member/{member_id}")
public ResponseEntity<MemberInfoResponse> getMemberInfo(@PathVariable("member_id") final Long memberId) {
MemberInfoResponse response = memberService.getMemberInfo(memberId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package kr.co.yigil.member.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import kr.co.yigil.global.exception.BadRequestException;
import kr.co.yigil.member.domain.Member;
import kr.co.yigil.member.domain.repository.MemberRepository;
import kr.co.yigil.member.dto.response.MemberInfoResponse;
Expand Down Expand Up @@ -34,7 +36,7 @@ public void setUp() {
MockitoAnnotations.openMocks(this);
}

@DisplayName("유효한 사용자ID가 주어졌을 때 사용자 정보가 잘 반환되는 지")
@DisplayName("유효한 사용자ID가 주어졌을 때 사용자 정보가 잘 반환되는지")
@Test
void whenGetMemberInfo_thenReturnsMemberInfoResponse_withValidMemberInfo() {
Long memberId = 1L;
Expand All @@ -50,4 +52,14 @@ void whenGetMemberInfo_thenReturnsMemberInfoResponse_withValidMemberInfo() {
assertThat(response.getNickname()).isEqualTo("stone");
assertThat(response.getProfileImageUrl()).isEqualTo("profile.jpg");
}

@DisplayName("잘못된 사용자ID가 주어졌을 때 예외가 잘 발생하는지")
@Test
void whenGetMemberInfo_thenThrowsException_withInvalidMemberInfo() {
Long invalidMemberId = 2L;

when(memberRepository.findById(invalidMemberId)).thenReturn(Optional.empty());

assertThrows(BadRequestException.class, () -> memberService.getMemberInfo(invalidMemberId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ void whenGetMyInfo_thenReturns200AndMemberInfoResponse() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}

@DisplayName("사용자 정보를 조회할 때 200 응답과 response가 잘 반환되는지")
@Test
void whenGetMemberInfo_thenReturns200AndMemberInfoResponse() throws Exception {
MemberInfoResponse mockResponse = new MemberInfoResponse();
Long memberId = 1L;

given(memberService.getMemberInfo(memberId)).willReturn(mockResponse);

mockMvc.perform(get("/api/v1/member/1")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}

0 comments on commit 89aac97

Please sign in to comment.