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

feat: 포트폴리오 조회 기능 수정 #368

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -18,6 +22,7 @@

import com.sponus.coredomain.domain.common.ApiResponse;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.portfolio.repository.conditions.PortfolioSearchParam;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.portfolio.dto.PortfolioCreateRequest;
import com.sponus.sponusbe.domain.portfolio.dto.PortfolioCreateResponse;
Expand Down Expand Up @@ -49,9 +54,10 @@ public ApiResponse<PortfolioCreateResponse> createPortfolio(
return ApiResponse.onSuccess(response);
}

@GetMapping("/{portfolioId}")
public ApiResponse<PortfolioGetResponse> getPortfolio(@PathVariable Long portfolioId) {
PortfolioGetResponse response = portfolioService.getPortfolio(portfolioId);
@GetMapping
public ApiResponse<Page<PortfolioGetResponse>> getPortfolios(@PageableDefault() Pageable pageable, @ModelAttribute
PortfolioSearchParam portfolioSearchParam) {
Page<PortfolioGetResponse> response = portfolioService.getPortfolios(portfolioSearchParam, pageable);
return ApiResponse.onSuccess(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
package com.sponus.sponusbe.domain.portfolio.dto;

import java.time.LocalDate;
import java.util.List;

import com.sponus.coredomain.domain.portfolio.Portfolio;

public record PortfolioGetResponse(
Long portfolioId,
Long clubId,
LocalDate startDate,
LocalDate endDate,
String description,
List<PortfolioImageGetResponse> portfolioImageGetResponses
) {
public static PortfolioGetResponse toDto(Portfolio portfolio,
Copy link
Collaborator

Choose a reason for hiding this comment

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

from으로 고쳐주세용 🙌

List<PortfolioImageGetResponse> portfolioImageGetResponses) {
return new PortfolioGetResponse(
portfolio.getId(),
portfolio.getClub().getId(),
portfolio.getStartDate(),
portfolio.getEndDate(),
portfolio.getDescription(),
portfolioImageGetResponses
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -17,7 +19,9 @@
import com.sponus.coredomain.domain.organization.repository.ClubRepository;
import com.sponus.coredomain.domain.portfolio.Portfolio;
import com.sponus.coredomain.domain.portfolio.PortfolioImage;
import com.sponus.coredomain.domain.portfolio.repository.PortfolioCustomRepository;
import com.sponus.coredomain.domain.portfolio.repository.PortfolioRepository;
import com.sponus.coredomain.domain.portfolio.repository.conditions.PortfolioSearchParam;
import com.sponus.coreinfras3.S3Service;
import com.sponus.sponusbe.domain.organization.exception.OrganizationException;
import com.sponus.sponusbe.domain.portfolio.dto.PortfolioCreateRequest;
Expand All @@ -37,6 +41,7 @@
@Service
public class PortfolioService {
private final PortfolioRepository portfolioRepository;
private final PortfolioCustomRepository portfolioCustomRepository;
private final ClubRepository clubRepository;
private final S3Service s3Service;

Expand Down Expand Up @@ -94,15 +99,14 @@ public PortfolioCreateResponse createPortfolio(
);
}

public PortfolioGetResponse getPortfolio(long portfolioId) {
Portfolio portfolio = portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new PortfolioException(PORTFOLIO_NOT_FOUND));

List<PortfolioImageGetResponse> portfolioImageGetResponses = portfolio.getPortfolioImages().stream()
.map(image -> new PortfolioImageGetResponse(image.getId(), image.getUrl(), image.getOrder()))
.toList();

return new PortfolioGetResponse(portfolioId, portfolioImageGetResponses);
public Page<PortfolioGetResponse> getPortfolios(PortfolioSearchParam portfolioSearchParam, Pageable pageable) {
Page<Portfolio> queryResult = portfolioCustomRepository.findAllByConditions(portfolioSearchParam, pageable);
return queryResult.map(portfolio -> {
List<PortfolioImageGetResponse> portfolioImageGetResponses = portfolio.getPortfolioImages().stream()
.map(image -> new PortfolioImageGetResponse(image.getId(), image.getUrl(), image.getOrder()))
.toList();
return PortfolioGetResponse.toDto(portfolio, portfolioImageGetResponses);
});
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Portfolio {

@Setter
@Builder.Default
@OneToMany(cascade = {CascadeType.ALL})
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
private List<PortfolioImage> portfolioImages = new ArrayList<>();

public void addPortfolioImage(PortfolioImage portfolioImage) {
Expand Down
Loading