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: 받은 제안 목록 조회 기능 개발 #341

Merged
merged 4 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -16,7 +16,8 @@
import com.sponus.sponusbe.domain.organization.dto.response.PageResponse;
import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse;
import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse;
import com.sponus.sponusbe.domain.propose.service.ProposeQueryService;
import com.sponus.sponusbe.domain.propose.service.ProposeService;

Expand All @@ -42,10 +43,18 @@ public ApiResponse<ProposeCreateResponse> createPropose(
}

@GetMapping("/send")
public ApiResponse<PageResponse<ProposeGetResponse>> getSendPropose(
public ApiResponse<PageResponse<SendProposeGetResponse>> getSendPropose(
@AuthOrganization Organization authOrganization,
@ModelAttribute @Valid PageCondition pageCondition
) {
return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization, pageCondition));
}

@GetMapping("/receive")
public ApiResponse<PageResponse<ReceiveProposeGetResponse>> getReceivedPropose(
@AuthOrganization Organization authOrganization,
@ModelAttribute @Valid PageCondition pageCondition
) {
return ApiResponse.onSuccess(proposequeryService.getReceivedPropose(authOrganization, pageCondition));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sponus.sponusbe.domain.propose.dto.response;

import java.time.LocalDate;

import com.sponus.coredomain.domain.propose.Propose;
import com.sponus.coredomain.domain.propose.ProposeStatus;

import lombok.Builder;

@Builder
public record ReceiveProposeGetResponse(
Long id,
Long organizationId,
Long target,
String organizationName,
String organizationImageUrl,
ProposeStatus status,
LocalDate createdAt
) {

public static ReceiveProposeGetResponse from(Propose propose) {
return ReceiveProposeGetResponse.builder()
.id(propose.getId())
.organizationId(propose.getOrganization().getId())
.target(propose.getTarget().getId())
.organizationName(propose.getOrganization().getName())
.organizationImageUrl(propose.getOrganization().getImageUrl())
.status(propose.getStatus())
.createdAt(propose.getCreatedAt().toLocalDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.Builder;

@Builder
public record ProposeGetResponse(
public record SendProposeGetResponse(
Long id,
Long organizationId,
Long target,
Expand All @@ -18,8 +18,8 @@ public record ProposeGetResponse(
LocalDate createdAt
) {

public static ProposeGetResponse from(Propose propose) {
return ProposeGetResponse.builder()
public static SendProposeGetResponse from(Propose propose) {
return SendProposeGetResponse.builder()
.id(propose.getId())
.organizationId(propose.getOrganization().getId())
.target(propose.getTarget().getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import com.sponus.coredomain.domain.propose.repository.ProposeRepository;
import com.sponus.sponusbe.domain.organization.dto.request.PageCondition;
import com.sponus.sponusbe.domain.organization.dto.response.PageResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse;
import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse;
import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse;

import lombok.RequiredArgsConstructor;

Expand All @@ -23,16 +24,30 @@ public class ProposeQueryService {

private final ProposeRepository proposeRepository;

public PageResponse<ProposeGetResponse> getSendPropose(Organization organization, PageCondition pageCondition) {
public PageResponse<SendProposeGetResponse> getSendPropose(Organization organization, PageCondition pageCondition) {
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
List<ProposeGetResponse> organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc(
List<SendProposeGetResponse> organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc(
organization, pageable)
.stream()
.map(ProposeGetResponse::from)
.map(SendProposeGetResponse::from)
.toList();

return PageResponse.of(
PageableExecutionUtils.getPage(organizations, pageable,
() -> proposeRepository.countByOrganization(organization)));
}

public PageResponse<ReceiveProposeGetResponse> getReceivedPropose(Organization organization,
PageCondition pageCondition) {
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
List<ReceiveProposeGetResponse> receivedProposes = proposeRepository.findByTargetOrderByCreatedAtDesc(
organization, pageable)
.stream()
.map(ReceiveProposeGetResponse::from)
.toList();

return PageResponse.of(
PageableExecutionUtils.getPage(receivedProposes, pageable,
() -> proposeRepository.countByTarget(organization)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre

if (organization.getImageUrl() == null || organization.getImageUrl().isEmpty())
throw new ProposeException(ProposeErrorCode.PROFILE_NOT_COMPLETED);

if (proposeRepository.existsByOrganization(target))
throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR);


final Long count = proposeRepository.countProposesByOrganizationToday(organization,
LocalDateTime.now().toLocalDate().atStartOfDay());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ Long countProposesByOrganizationToday(@Param("organization") Organization organi
Page<Propose> findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable);

Long countByOrganization(Organization organization);

Page<Propose> findByTargetOrderByCreatedAtDesc(Organization target, Pageable pageable);

Long countByTarget(Organization target);
}
Loading