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: 보낸 제안 목록 조회 기능 개발 #340

Merged
merged 2 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 @@ -2,26 +2,21 @@

import static com.sponus.sponusbe.global.enums.ApiPath.*;

import java.io.IOException;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sponus.coredomain.domain.common.ApiResponse;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
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.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.service.ProposeQueryService;
import com.sponus.sponusbe.domain.propose.service.ProposeService;

Expand All @@ -36,12 +31,21 @@
public class ProposeController {

private final ProposeService proposeService;
private final ProposeQueryService proposequeryService;

@PostMapping()
public ApiResponse<ProposeCreateResponse> createPropose(
@AuthOrganization Organization authOrganization,
@RequestBody @Valid ProposeCreateRequest request
){
) {
return ApiResponse.onSuccess(proposeService.createPropose(authOrganization, request));
}

@GetMapping("/send")
public ApiResponse<PageResponse<ProposeGetResponse>> getSendPropose(
@AuthOrganization Organization authOrganization,
@ModelAttribute @Valid PageCondition pageCondition
) {
return ApiResponse.onSuccess(proposequeryService.getSendPropose(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 ProposeGetResponse(
Long id,
Long organizationId,
Long target,
String targetName,
String targetImageUrl,
ProposeStatus status,
LocalDate createdAt
) {

public static ProposeGetResponse from(Propose propose) {
return ProposeGetResponse.builder()
.id(propose.getId())
.organizationId(propose.getOrganization().getId())
.target(propose.getTarget().getId())
.targetName(propose.getTarget().getName())
.targetImageUrl(propose.getTarget().getImageUrl())
.status(propose.getStatus())
.createdAt(propose.getCreatedAt().toLocalDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
package com.sponus.sponusbe.domain.propose.service;

import java.util.List;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.coredomain.domain.organization.Organization;
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 lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class ProposeQueryService {

private final ProposeRepository proposeRepository;

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

return PageResponse.of(
PageableExecutionUtils.getPage(organizations, pageable,
() -> proposeRepository.countByOrganization(organization)));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.sponus.sponusbe.domain.propose.service;

import java.lang.annotation.Target;
import java.time.LocalDateTime;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.coredomain.domain.bookmark.Bookmark;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.repository.OrganizationRepository;
import com.sponus.coredomain.domain.propose.Propose;
import com.sponus.coredomain.domain.propose.repository.ProposeRepository;
import com.sponus.coreinfrafirebase.FirebaseService;
import com.sponus.coreinfras3.S3Service;
import com.sponus.sponusbe.domain.bookmark.dto.response.BookmarkToggleResponse;
import com.sponus.sponusbe.domain.bookmark.exception.BookmarkErrorCode;
import com.sponus.sponusbe.domain.bookmark.exception.BookmarkException;
import com.sponus.sponusbe.domain.organization.exception.OrganizationErrorCode;
import com.sponus.sponusbe.domain.organization.exception.OrganizationException;
import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.sponus.coredomain.domain.propose;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.sponus.coredomain.domain.common.BaseEntity;
import com.sponus.coredomain.domain.organization.Organization;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
Expand All @@ -26,6 +32,8 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Entity
@DynamicUpdate
@DynamicInsert
@Table(name = "propose")
public class Propose extends BaseEntity {

Expand All @@ -41,4 +49,9 @@ public class Propose extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@JoinColumn(name = "target_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization target;

@Enumerated(EnumType.STRING)
@ColumnDefault("'WAITING'")
@Column(name = "propose_status")
private ProposeStatus status;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.sponus.coredomain.domain.propose;

public enum ProposeStatus {
// 제안을 보낸 측: PENDING
// 제안을 받은 측: VIEWED, ACCEPTED, REJECTED, SUSPENDED, PAID
PENDING, VIEWED, ACCEPTED, REJECTED, SUSPENDED, PAID, COMPLETED;
ACCEPTED, REJECTED, WAITING;

public static ProposeStatus of(String input) {
return ProposeStatus.valueOf(input.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.sponus.coredomain.domain.propose.repository;

import java.time.LocalDateTime;
import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -17,5 +18,10 @@ public interface ProposeRepository extends JpaRepository<Propose, Long> {
// Optional<Propose> findByOrganization(Organization organization);

@Query("SELECT COUNT(p) FROM Propose p WHERE p.organization = :organization AND p.createdAt >= :startOfDay")
Long countProposesByOrganizationToday(@Param("organization") Organization organization, @Param("startOfDay") LocalDateTime startOfDay);
Long countProposesByOrganizationToday(@Param("organization") Organization organization,
@Param("startOfDay") LocalDateTime startOfDay);

Page<Propose> findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable);

Long countByOrganization(Organization organization);
}
Loading