Skip to content

Commit

Permalink
[FEAT] Member URL FIX + MemberController Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjoo-lab committed Nov 27, 2023
1 parent 134128d commit ad89f24
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.twtw.backend.domain.member.dto.response.DuplicateNicknameResponse;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.member.dto.response.SearchMemberResponse;
import com.twtw.backend.domain.member.service.MemberService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
Expand All @@ -24,8 +22,8 @@ public ResponseEntity<DuplicateNicknameResponse> duplicateNickname(@PathVariable
return ResponseEntity.ok(memberService.duplicateNickname(name));
}

@GetMapping("/{nickname}")
public ResponseEntity<MemberResponse> searchMemberByNickname(@PathVariable String nickname){
@GetMapping()
public ResponseEntity<SearchMemberResponse> searchMemberByNickname(@RequestParam(name = "nickname") String nickname){
return ResponseEntity.ok(memberService.getMemberByNickname(nickname));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.twtw.backend.domain.member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class SearchMemberResponse {
private Boolean find;
private MemberResponse memberResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.twtw.backend.domain.member.dto.response.DuplicateNicknameResponse;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.member.dto.response.SearchMemberResponse;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.mapper.MemberMapper;
import com.twtw.backend.domain.member.repository.MemberRepository;
Expand Down Expand Up @@ -40,10 +41,16 @@ public Member getMemberById(UUID id) {
}


public MemberResponse getMemberByNickname(String nickname){
Member member = memberRepository.findByNickname(nickname).orElseThrow(EntityNotFoundException::new);
public SearchMemberResponse getMemberByNickname(String nickname){
Optional<Member> member = memberRepository.findByNickname(nickname);

return memberMapper.toMemberResponse(member);
if(member.isPresent()){
Member findMember = member.get();

return new SearchMemberResponse(true,memberMapper.toMemberResponse(findMember));
}

return new SearchMemberResponse(false,null);
}

public MemberResponse getResponseByMember(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.twtw.backend.domain.member.dto.response.DuplicateNicknameResponse;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.member.dto.response.SearchMemberResponse;
import com.twtw.backend.domain.member.service.MemberService;
import com.twtw.backend.support.docs.RestDocsTest;

Expand Down Expand Up @@ -63,12 +64,18 @@ void searchMemberByNickname() throws Exception{
UUID.randomUUID(),
expectedNickname
);
given(memberService.getMemberByNickname(expectedNickname)).willReturn(memberResponse);

final SearchMemberResponse response = new SearchMemberResponse(
true,
memberResponse
);
given(memberService.getMemberByNickname(expectedNickname)).willReturn(response);

// when
final ResultActions perform =
mockMvc.perform(
get("/member/{nickname}",expectedNickname)
get("/member")
.param("nickname",expectedNickname)
.contentType(MediaType.APPLICATION_JSON)
.header(
"Authorization",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.twtw.backend.domain.member.dto.response.DuplicateNicknameResponse;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.member.dto.response.SearchMemberResponse;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.repository.MemberRepository;
import com.twtw.backend.fixture.member.MemberEntityFixture;
Expand Down Expand Up @@ -63,9 +64,9 @@ void searchMemberByNickname(){
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());

// when
final MemberResponse response = memberService.getMemberByNickname(member.getNickname());
final SearchMemberResponse response = memberService.getMemberByNickname(member.getNickname());

// then
assertThat(response.getId()).isEqualTo(member.getId());
assertThat(response.getMemberResponse().getId()).isEqualTo(member.getId());
}
}

0 comments on commit ad89f24

Please sign in to comment.