Skip to content

Commit

Permalink
Merge pull request #71 from PawWithU/feat/70-intermediary-get-applied…
Browse files Browse the repository at this point in the history
…-applications-api

[Feature] 이동봉사 중개 승인 대기중, 진행중 목록 조회 API 구현
  • Loading branch information
kyeong-hyeok authored Nov 15, 2023
2 parents 405a9e1 + aa34d0e commit 3452767
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.pawwithu.connectdog.domain.application.controller;

import com.pawwithu.connectdog.domain.application.dto.request.VolunteerApplyRequest;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationGetOneResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationWaitingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.*;
import com.pawwithu.connectdog.domain.application.service.ApplicationService;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -53,9 +51,9 @@ public ResponseEntity<Void> volunteerApply(@AuthenticationPrincipal UserDetails
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping( "/volunteers/applications/waiting")
public ResponseEntity<List<ApplicationWaitingResponse>> getWaitingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationWaitingResponse> response = applicationService.getWaitingApplications(loginUser.getUsername(), pageable);
public ResponseEntity<List<ApplicationVolunteerWaitingResponse>> getVolunteerWaitingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationVolunteerWaitingResponse> response = applicationService.getVolunteerWaitingApplications(loginUser.getUsername(), pageable);
return ResponseEntity.ok(response);
}

Expand All @@ -66,9 +64,9 @@ public ResponseEntity<List<ApplicationWaitingResponse>> getWaitingApplications(@
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping( "/volunteers/applications/progressing")
public ResponseEntity<List<ApplicationProgressingResponse>> getProgressingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationProgressingResponse> response = applicationService.getProgressingApplications(loginUser.getUsername(), pageable);
public ResponseEntity<List<ApplicationVolunteerProgressingResponse>> getVolunteerProgressingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationVolunteerProgressingResponse> response = applicationService.getVolunteerProgressingApplications(loginUser.getUsername(), pageable);
return ResponseEntity.ok(response);
}

Expand Down Expand Up @@ -124,4 +122,29 @@ public ResponseEntity<Void> cancelApplication(@AuthenticationPrincipal UserDetai
return ResponseEntity.noContent().build();
}

@Operation(summary = "봉사 관리 - 승인 대기중 목록 조회", description = "이동봉사 승인 대기중 목록을 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "이동봉사 승인 대기중 목록 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사 중개를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping( "/intermediaries/applications/waiting")
public ResponseEntity<List<ApplicationIntermediaryWaitingResponse>> getIntermediaryWaitingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationIntermediaryWaitingResponse> response = applicationService.getIntermediaryWaitingApplications(loginUser.getUsername(), pageable);
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 진행중 목록 조회", description = "이동봉사 진행중 목록을 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "이동봉사 진행중 목록 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사 중개를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping( "/intermediaries/applications/progressing")
public ResponseEntity<List<ApplicationIntermediaryProgressingResponse>> getIntermediaryProgressingApplications(@AuthenticationPrincipal UserDetails loginUser,
Pageable pageable) {
List<ApplicationIntermediaryProgressingResponse> response = applicationService.getIntermediaryProgressingApplications(loginUser.getUsername(), pageable);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pawwithu.connectdog.domain.application.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDate;

public record ApplicationIntermediaryProgressingResponse(Long postId, String mainImage, String dogName,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate startDate,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate endDate,
String departureLoc, String arrivalLoc,
String volunteerName,
Long applicationId) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pawwithu.connectdog.domain.application.dto.response;


import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDate;

public record ApplicationIntermediaryWaitingResponse(Long postId, String mainImage, String dogName,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate startDate,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate endDate,
String departureLoc, String arrivalLoc,
String volunteerName,
Long applicationId) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pawwithu.connectdog.domain.application.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDate;

public record ApplicationVolunteerProgressingResponse(Long postId, String mainImage, String departureLoc, String arrivalLoc,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate startDate,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate endDate,
String intermediaryName,
Boolean isKennel) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pawwithu.connectdog.domain.application.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDate;

public record ApplicationVolunteerWaitingResponse(Long postId, String mainImage, String departureLoc, String arrivalLoc,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate startDate,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate endDate,
String intermediaryName,
Boolean isKennel,
Long applicationId) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pawwithu.connectdog.domain.application.repository;

import com.pawwithu.connectdog.domain.application.dto.response.ApplicationProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationWaitingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationIntermediaryProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationIntermediaryWaitingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationVolunteerProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationVolunteerWaitingResponse;
import com.pawwithu.connectdog.domain.application.entity.Application;
import org.springframework.data.domain.Pageable;

Expand All @@ -10,8 +12,10 @@

public interface CustomApplicationRepository {

List<ApplicationWaitingResponse> getWaitingApplications(Long volunteerId, Pageable pageable);
List<ApplicationProgressingResponse> getProgressingApplications(Long volunteerId, Pageable pageable);
List<ApplicationVolunteerWaitingResponse> getVolunteerWaitingApplications(Long volunteerId, Pageable pageable);
List<ApplicationVolunteerProgressingResponse> getVolunteerProgressingApplications(Long volunteerId, Pageable pageable);
Optional<Application> findByIdAndVolunteerIdWithPost(Long applicationId, Long volunteerId);
Optional<Application> findByIdAndIntermediaryIdWithPost(Long applicationId, Long intermediaryId);
List<ApplicationIntermediaryWaitingResponse> getIntermediaryWaitingApplications(Long intermediaryId, Pageable pageable);
List<ApplicationIntermediaryProgressingResponse> getIntermediaryProgressingApplications(Long intermediaryId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pawwithu.connectdog.domain.application.repository.impl;

import com.pawwithu.connectdog.domain.application.dto.response.ApplicationProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationWaitingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationIntermediaryProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationIntermediaryWaitingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationVolunteerProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationVolunteerWaitingResponse;
import com.pawwithu.connectdog.domain.application.entity.Application;
import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus;
import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository;
Expand All @@ -16,9 +18,11 @@
import java.util.Optional;

import static com.pawwithu.connectdog.domain.application.entity.QApplication.application;
import static com.pawwithu.connectdog.domain.dog.entity.QDog.dog;
import static com.pawwithu.connectdog.domain.intermediary.entity.QIntermediary.intermediary;
import static com.pawwithu.connectdog.domain.post.entity.QPost.post;
import static com.pawwithu.connectdog.domain.post.entity.QPostImage.postImage;
import static com.pawwithu.connectdog.domain.volunteer.entity.QVolunteer.volunteer;

@Repository
@RequiredArgsConstructor
Expand All @@ -28,9 +32,9 @@ public class CustomApplicationRepositoryImpl implements CustomApplicationReposit
private final JPAQueryFactory queryFactory;

@Override
public List<ApplicationWaitingResponse> getWaitingApplications(Long volunteerId, Pageable pageable) {
public List<ApplicationVolunteerWaitingResponse> getVolunteerWaitingApplications(Long volunteerId, Pageable pageable) {
return queryFactory
.select(Projections.constructor(ApplicationWaitingResponse.class,
.select(Projections.constructor(ApplicationVolunteerWaitingResponse.class,
post.id, postImage.image, post.departureLoc, post.arrivalLoc, post.startDate, post.endDate,
intermediary.name, post.isKennel, application.id))
.from(application)
Expand All @@ -39,16 +43,16 @@ public List<ApplicationWaitingResponse> getWaitingApplications(Long volunteerId,
.join(application.post.mainImage, postImage)
.where(application.status.eq(ApplicationStatus.WAITING)
.and(application.volunteer.id.eq(volunteerId)))
.orderBy(application.createdDate.desc())
.orderBy(application.createdDate.desc()) // 신청 최신순
.offset(pageable.getOffset()) // 페이지 번호
.limit(pageable.getPageSize()) // 페이지 사이즈
.fetch();
}

@Override
public List<ApplicationProgressingResponse> getProgressingApplications(Long volunteerId, Pageable pageable) {
public List<ApplicationVolunteerProgressingResponse> getVolunteerProgressingApplications(Long volunteerId, Pageable pageable) {
return queryFactory
.select(Projections.constructor(ApplicationProgressingResponse.class,
.select(Projections.constructor(ApplicationVolunteerProgressingResponse.class,
post.id, postImage.image, post.departureLoc, post.arrivalLoc, post.startDate, post.endDate,
intermediary.name, post.isKennel))
.from(application)
Expand All @@ -57,7 +61,7 @@ public List<ApplicationProgressingResponse> getProgressingApplications(Long volu
.join(application.post.mainImage, postImage)
.where(application.status.eq(ApplicationStatus.PROGRESSING)
.and(application.volunteer.id.eq(volunteerId)))
.orderBy(application.createdDate.desc())
.orderBy(application.modifiedDate.desc()) // 신청 확정 최신순
.offset(pageable.getOffset()) // 페이지 번호
.limit(pageable.getPageSize()) // 페이지 사이즈
.fetch();
Expand All @@ -84,4 +88,42 @@ public Optional<Application> findByIdAndIntermediaryIdWithPost(Long applicationI
.and(application.intermediary.id.eq(intermediaryId)))
.fetchOne());
}

@Override
public List<ApplicationIntermediaryWaitingResponse> getIntermediaryWaitingApplications(Long intermediaryId, Pageable pageable) {
return queryFactory
.select(Projections.constructor(ApplicationIntermediaryWaitingResponse.class,
post.id, postImage.image, dog.name, post.startDate, post.endDate,
post.departureLoc, post.arrivalLoc, volunteer.name, application.id))
.from(application)
.join(application.post, post)
.join(application.post.mainImage, postImage)
.join(application.post.dog, dog)
.join(application.volunteer, volunteer)
.where(application.status.eq(ApplicationStatus.WAITING)
.and(application.intermediary.id.eq(intermediaryId)))
.orderBy(application.createdDate.desc()) // 신청 최신순
.offset(pageable.getOffset()) // 페이지 번호
.limit(pageable.getPageSize()) // 페이지 사이즈
.fetch();
}

@Override
public List<ApplicationIntermediaryProgressingResponse> getIntermediaryProgressingApplications(Long intermediaryId, Pageable pageable) {
return queryFactory
.select(Projections.constructor(ApplicationIntermediaryProgressingResponse.class,
post.id, postImage.image, dog.name, post.startDate, post.endDate,
post.departureLoc, post.arrivalLoc, volunteer.name, application.id))
.from(application)
.join(application.post, post)
.join(application.post.mainImage, postImage)
.join(application.post.dog, dog)
.join(application.volunteer, volunteer)
.where(application.status.eq(ApplicationStatus.PROGRESSING)
.and(application.intermediary.id.eq(intermediaryId)))
.orderBy(application.modifiedDate.desc()) // 신청 확정 최신순
.offset(pageable.getOffset()) // 페이지 번호
.limit(pageable.getPageSize()) // 페이지 사이즈
.fetch();
}
}
Loading

0 comments on commit 3452767

Please sign in to comment.