Skip to content

Commit

Permalink
Merge pull request #130 from FreakPeople/feature/#129
Browse files Browse the repository at this point in the history
feat: 나의 웹툰 조회 기능 구현
  • Loading branch information
Jeongjjuna authored Jul 13, 2024
2 parents 3a80026 + bc6401d commit 778e591
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.web.multipart.MultipartFile;
import yjh.devtoon.common.exception.DevtoonException;
import yjh.devtoon.common.exception.ErrorCode;
import yjh.devtoon.member.application.MemberService;
import yjh.devtoon.member.domain.MemberEntity;
import yjh.devtoon.webtoon.constant.ErrorMessage;
import yjh.devtoon.webtoon.domain.Genre;
import yjh.devtoon.webtoon.domain.WebtoonEntity;
Expand All @@ -22,6 +24,7 @@ public class WebtoonService {

private final WebtoonRepository webtoonRepository;
private final ImageRepository imageRepository;
private final MemberService memberService;

public WebtoonEntity retrieve(final Long id) {
return webtoonRepository.findById(id)
Expand Down Expand Up @@ -66,4 +69,9 @@ public Page<WebtoonEntity> retrieveAll(Pageable pageable) {
public Resource retrieveImage(final Long id, final String fileName) {
return imageRepository.get(fileName);
}

public Page<WebtoonEntity> retrieveAllMy(final Pageable pageable, final String myEmail) {
MemberEntity my = memberService.retrieveMyInfo(myEmail);
return webtoonRepository.findAllByWriterName(pageable, my.getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package yjh.devtoon.webtoon.infrastructure;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import yjh.devtoon.webtoon.domain.WebtoonEntity;
import java.util.Optional;

public interface WebtoonRepository extends JpaRepository<WebtoonEntity, Long> {
Optional<WebtoonEntity> findByTitle(String title);

Page<WebtoonEntity> findAllByWriterName(Pageable pageable, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -81,4 +82,19 @@ public ResponseEntity<ApiResponse> retrieveAll(Pageable pageable) {
return ResponseEntity.ok(ApiResponse.success(webtoonsResponse));
}

/**
* 인증한 회원이 게시한 웹툰 전체 조회
*/
@GetMapping("/my")
public ResponseEntity<ApiResponse> retrieveAllMy(
Pageable pageable,
Authentication authentication
) {
String myEmail = authentication.getName();

Page<WebtoonEntity> webtoons = webtoonService.retrieveAllMy(pageable, myEmail);
Page<WebtoonResponse> webtoonsResponse = webtoons.map(WebtoonResponse::from);
return ResponseEntity.ok(ApiResponse.success(webtoonsResponse));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import yjh.devtoon.member.domain.Authority;
import yjh.devtoon.member.domain.MemberEntity;
import yjh.devtoon.member.domain.MembershipStatus;
import yjh.devtoon.member.domain.Role;
import yjh.devtoon.member.infrastructure.MemberRepository;
import yjh.devtoon.webtoon.domain.Genre;
import yjh.devtoon.webtoon.domain.WebtoonEntity;
import yjh.devtoon.webtoon.dto.request.WebtoonCreateRequest;
Expand All @@ -36,6 +42,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

@DisplayName("통합 테스트 [Webtoon]")
Expand All @@ -46,6 +53,12 @@ public class WebtoonIntegrationTest {

private static final String NULL = null;

@Autowired
private MemberRepository memberRepository;

@Autowired
private PasswordEncoder passwordEncoder;

@Autowired
private ObjectMapper objectMapper;

Expand Down Expand Up @@ -349,4 +362,46 @@ void retrieveAllWebtoon_successfully() throws Exception {
}
}

@WithMockUser(username = "[email protected]", password = "password", authorities = {"MEMBER"})
@Nested
@DisplayName("나의 웹툰 전체 조회 테스트")
class WebtoonRetrieveAllMyTests {

@DisplayName("나의 웹툰 전체 조회 성공")
@Test
void retrieveAllWebtoon_successfully() throws Exception {
// given
MemberEntity member = MemberEntity.builder()
.name("카레곰")
.email("[email protected]")
.password(passwordEncoder.encode("password"))
.membershipStatus(MembershipStatus.GENERAL)
.authorities(Set.of(new Authority(Role.MEMBER)))
.build();
memberRepository.save(member);

WebtoonEntity webtoonEntity1 = WebtoonEntity.builder()
.title("쿠베라")
.writerName("카레곰")
.genre(Genre.HORROR)
.build();
webtoonRepository.save(webtoonEntity1);

WebtoonEntity webtoonEntity2 = WebtoonEntity.builder()
.title("기기괴괴")
.writerName("오성대")
.genre(Genre.HORROR)
.build();
webtoonRepository.save(webtoonEntity2);

// when
mockMvc.perform(get("/v1/webtoons/my")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.statusMessage").value("성공"))
.andExpect(jsonPath("$.data.content").isArray())
.andExpect(jsonPath("$.data.content[0].title").value("쿠베라"));
}
}

}

0 comments on commit 778e591

Please sign in to comment.