Skip to content

Commit fcbcd8c

Browse files
authored
feat: 받은 제안 목록 조회 기능 개발 (#341)
1 parent 04c85cc commit fcbcd8c

File tree

6 files changed

+70
-13
lines changed

6 files changed

+70
-13
lines changed

api/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import com.sponus.sponusbe.domain.organization.dto.response.PageResponse;
1717
import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest;
1818
import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse;
19-
import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse;
19+
import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse;
20+
import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse;
2021
import com.sponus.sponusbe.domain.propose.service.ProposeQueryService;
2122
import com.sponus.sponusbe.domain.propose.service.ProposeService;
2223

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

4445
@GetMapping("/send")
45-
public ApiResponse<PageResponse<ProposeGetResponse>> getSendPropose(
46+
public ApiResponse<PageResponse<SendProposeGetResponse>> getSendPropose(
4647
@AuthOrganization Organization authOrganization,
4748
@ModelAttribute @Valid PageCondition pageCondition
4849
) {
4950
return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization, pageCondition));
5051
}
52+
53+
@GetMapping("/receive")
54+
public ApiResponse<PageResponse<ReceiveProposeGetResponse>> getReceivedPropose(
55+
@AuthOrganization Organization authOrganization,
56+
@ModelAttribute @Valid PageCondition pageCondition
57+
) {
58+
return ApiResponse.onSuccess(proposequeryService.getReceivedPropose(authOrganization, pageCondition));
59+
}
5160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.sponus.sponusbe.domain.propose.dto.response;
2+
3+
import java.time.LocalDate;
4+
5+
import com.sponus.coredomain.domain.propose.Propose;
6+
import com.sponus.coredomain.domain.propose.ProposeStatus;
7+
8+
import lombok.Builder;
9+
10+
@Builder
11+
public record ReceiveProposeGetResponse(
12+
Long id,
13+
Long organizationId,
14+
Long target,
15+
String organizationName,
16+
String organizationImageUrl,
17+
ProposeStatus status,
18+
LocalDate createdAt
19+
) {
20+
21+
public static ReceiveProposeGetResponse from(Propose propose) {
22+
return ReceiveProposeGetResponse.builder()
23+
.id(propose.getId())
24+
.organizationId(propose.getOrganization().getId())
25+
.target(propose.getTarget().getId())
26+
.organizationName(propose.getOrganization().getName())
27+
.organizationImageUrl(propose.getOrganization().getImageUrl())
28+
.status(propose.getStatus())
29+
.createdAt(propose.getCreatedAt().toLocalDate())
30+
.build();
31+
}
32+
}

api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.java api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/SendProposeGetResponse.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import lombok.Builder;
99

1010
@Builder
11-
public record ProposeGetResponse(
11+
public record SendProposeGetResponse(
1212
Long id,
1313
Long organizationId,
1414
Long target,
@@ -18,8 +18,8 @@ public record ProposeGetResponse(
1818
LocalDate createdAt
1919
) {
2020

21-
public static ProposeGetResponse from(Propose propose) {
22-
return ProposeGetResponse.builder()
21+
public static SendProposeGetResponse from(Propose propose) {
22+
return SendProposeGetResponse.builder()
2323
.id(propose.getId())
2424
.organizationId(propose.getOrganization().getId())
2525
.target(propose.getTarget().getId())

api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import com.sponus.coredomain.domain.propose.repository.ProposeRepository;
1313
import com.sponus.sponusbe.domain.organization.dto.request.PageCondition;
1414
import com.sponus.sponusbe.domain.organization.dto.response.PageResponse;
15-
import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse;
15+
import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse;
16+
import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse;
1617

1718
import lombok.RequiredArgsConstructor;
1819

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

2425
private final ProposeRepository proposeRepository;
2526

26-
public PageResponse<ProposeGetResponse> getSendPropose(Organization organization, PageCondition pageCondition) {
27+
public PageResponse<SendProposeGetResponse> getSendPropose(Organization organization, PageCondition pageCondition) {
2728
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
28-
List<ProposeGetResponse> organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc(
29+
List<SendProposeGetResponse> organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc(
2930
organization, pageable)
3031
.stream()
31-
.map(ProposeGetResponse::from)
32+
.map(SendProposeGetResponse::from)
3233
.toList();
3334

3435
return PageResponse.of(
3536
PageableExecutionUtils.getPage(organizations, pageable,
3637
() -> proposeRepository.countByOrganization(organization)));
3738
}
39+
40+
public PageResponse<ReceiveProposeGetResponse> getReceivedPropose(Organization organization,
41+
PageCondition pageCondition) {
42+
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
43+
List<ReceiveProposeGetResponse> receivedProposes = proposeRepository.findByTargetOrderByCreatedAtDesc(
44+
organization, pageable)
45+
.stream()
46+
.map(ReceiveProposeGetResponse::from)
47+
.toList();
48+
49+
return PageResponse.of(
50+
PageableExecutionUtils.getPage(receivedProposes, pageable,
51+
() -> proposeRepository.countByTarget(organization)));
52+
}
3853
}

api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre
3838

3939
if (organization.getImageUrl() == null || organization.getImageUrl().isEmpty())
4040
throw new ProposeException(ProposeErrorCode.PROFILE_NOT_COMPLETED);
41-
42-
if (proposeRepository.existsByOrganization(target))
43-
throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR);
44-
41+
4542
final Long count = proposeRepository.countProposesByOrganizationToday(organization,
4643
LocalDateTime.now().toLocalDate().atStartOfDay());
4744

core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeRepository.java

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ Long countProposesByOrganizationToday(@Param("organization") Organization organi
2424
Page<Propose> findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable);
2525

2626
Long countByOrganization(Organization organization);
27+
28+
Page<Propose> findByTargetOrderByCreatedAtDesc(Organization target, Pageable pageable);
29+
30+
Long countByTarget(Organization target);
2731
}

0 commit comments

Comments
 (0)