Skip to content

Commit

Permalink
Merge pull request #57 from PawWithU/feat/56-get-applications-api
Browse files Browse the repository at this point in the history
[Feature] 이동봉사자 봉사 관리 - 승인 대기중, 진행중 목록 조회 API 구현
  • Loading branch information
kyeong-hyeok authored Nov 13, 2023
2 parents 57e0c70 + 9f10be4 commit 90cec58
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pawwithu.connectdog.domain.application.controller;

import com.pawwithu.connectdog.domain.application.dto.request.VolunteerApplyRequest;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationWaitingResponse;
import com.pawwithu.connectdog.domain.application.service.ApplicationService;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -11,13 +13,13 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Application", description = "Application API")
@RestController
Expand All @@ -42,4 +44,30 @@ public ResponseEntity<Void> volunteerApply(@AuthenticationPrincipal UserDetails
applicationService.volunteerApply(loginUser.getUsername(), postId, request);
return ResponseEntity.noContent().build();
}

@Operation(summary = "봉사 관리 - 승인 대기중", description = "이동봉사 승인 대기중 목록을 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "이동봉사 승인 대기중 목록 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M1, 해당 이동봉사자를 찾을 수 없습니다."
, 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);
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 진행중", description = "이동봉사 진행중 목록을 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "이동봉사 진행중 목록 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M1, 해당 이동봉사자를 찾을 수 없습니다."
, 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);
return ResponseEntity.ok(response);
}
}
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 ApplicationProgressingResponse(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 ApplicationWaitingResponse(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) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 org.springframework.data.domain.Pageable;

import java.util.List;

public interface CustomApplicationRepository {

List<ApplicationWaitingResponse> getWaitingApplications(Long volunteerId, Pageable pageable);
List<ApplicationProgressingResponse> getProgressingApplications(Long volunteerId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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.entity.ApplicationStatus;
import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.pawwithu.connectdog.domain.application.entity.QApplication.application;
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;

@Repository
@RequiredArgsConstructor
@Slf4j
public class CustomApplicationRepositoryImpl implements CustomApplicationRepository {

private final JPAQueryFactory queryFactory;

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

@Override
public List<ApplicationProgressingResponse> getProgressingApplications(Long volunteerId, Pageable pageable) {
return queryFactory
.select(Projections.constructor(ApplicationProgressingResponse.class,
postImage.image, post.departureLoc, post.arrivalLoc, post.startDate, post.endDate,
intermediary.name, post.isKennel))
.from(application)
.join(application.post, post)
.join(application.post.intermediary, intermediary)
.join(application.post.mainImage, postImage)
.where(application.status.eq(ApplicationStatus.PROGRESSING)
.and(application.volunteer.id.eq(volunteerId)))
.orderBy(application.createdDate.desc())
.offset(pageable.getOffset()) // 페이지 번호
.limit(pageable.getPageSize()) // 페이지 사이즈
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.pawwithu.connectdog.domain.application.service;

import com.pawwithu.connectdog.domain.application.dto.request.VolunteerApplyRequest;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationProgressingResponse;
import com.pawwithu.connectdog.domain.application.dto.response.ApplicationWaitingResponse;
import com.pawwithu.connectdog.domain.application.entity.Application;
import com.pawwithu.connectdog.domain.application.repository.ApplicationRepository;
import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository;
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import com.pawwithu.connectdog.domain.post.repository.PostRepository;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
import com.pawwithu.connectdog.error.ErrorCode;
import com.pawwithu.connectdog.error.exception.custom.BadRequestException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.pawwithu.connectdog.error.ErrorCode.*;

@Slf4j
Expand All @@ -27,6 +32,7 @@ public class ApplicationService {
private final VolunteerRepository volunteerRepository;
private final PostRepository postRepository;
private final ApplicationRepository applicationRepository;
private final CustomApplicationRepository customApplicationRepository;

public void volunteerApply(String email, Long postId, VolunteerApplyRequest request) {
// 이동봉사자
Expand All @@ -48,4 +54,18 @@ public void volunteerApply(String email, Long postId, VolunteerApplyRequest requ
// 공고 상태 승인 대기 중으로 변경
post.updateStatus(PostStatus.WAITING);
}

public List<ApplicationWaitingResponse> getWaitingApplications(String email, Pageable pageable) {
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
List<ApplicationWaitingResponse> waitingApplications = customApplicationRepository.getWaitingApplications(volunteer.getId(), pageable);
return waitingApplications;
}

public List<ApplicationProgressingResponse> getProgressingApplications(String email, Pageable pageable) {
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
List<ApplicationProgressingResponse> progressingApplications = customApplicationRepository.getProgressingApplications(volunteer.getId(), pageable);
return progressingApplications;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class CustomPostRepositoryImpl implements CustomPostRepository {

private final JPAQueryFactory queryFactory;
private final BookmarkRepository bookmarkRepository;

// 홈 화면 공고 5개 조회
@Override
Expand Down
38 changes: 38 additions & 0 deletions src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- INSERT INTERMEDIARY
INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, created_date, modified_date) VALUES (1, '[email protected]', '{bcrypt}$2a$10$Llg2MwZS/oOv/2/ozaice.49CU35kK6W9kYEb.oqyTy6vmh7E4yv2', '한호정', 'https://connectdog.site', 'authImageUrl', 'profileImageUrl', '안녕하세요.', '인스타그램: @hoxjeong', 'AUTH_INTERMEDIARY', false, false, now(), now());
-- INSERT VOLUNTEER
INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (1, '[email protected]', '{bcrypt}$2a$10$VieltvcRaI/rJnaRHuRPju9rqM9BvmKRkmn./oOninx7fOGT/q2De', '봉사자하노정', 1, '한호정', '01022223333', 'AUTH_VOLUNTEER', false, false, now(), now());
-- INSERT DOG
INSERT INTO dog (id, name, size, gender, weight, specifics, created_date, modified_date) VALUES (1, '포포', 0, 1, 4.6, '밥을 잘 먹음', now(), now());
INSERT INTO dog (id, name, size, gender, weight, specifics, created_date, modified_date) VALUES (2, '남2포포', 1, 0, 4.6, '밥을 잘 먹음', now(), now());
INSERT INTO dog (id, name, size, gender, weight, specifics, created_date, modified_date) VALUES (3, '여3포포', 2, 1, 4.6, '밥을 잘 먹음', now(), now());
INSERT INTO dog (id, name, size, gender, weight, specifics, created_date, modified_date) VALUES (4, '여4포포', 2, 1, 4.6, '밥을 잘 먹음', now(), now());
INSERT INTO dog (id, name, size, gender, weight, specifics, created_date, modified_date) VALUES (5, '남5포포', 1, 0, 4.6, '밥을 잘 먹음', now(), now());
-- INSERT POST
INSERT INTO post (id, status, departure_loc, arrival_loc, start_date, end_date, pick_up_time, is_kennel, content, intermediary_id, dog_id, created_date, modified_date) VALUES (1, 0, '서울시 성북구', '경기 고양시', '2023-11-13', '2023-11-25', '13:00', false, '이동봉사 공고입니다.', 1, 1, now(), now());
INSERT INTO post (id, status, departure_loc, arrival_loc, start_date, end_date, pick_up_time, is_kennel, content, intermediary_id, dog_id, created_date, modified_date) VALUES (2, 0, '서울시 성북구', '경기 고양시', '2023-11-13', '2023-11-25', '13:00', false, '이동봉사 공고입니다.', 1, 2, now(), now());
INSERT INTO post (id, status, departure_loc, arrival_loc, start_date, end_date, pick_up_time, is_kennel, content, intermediary_id, dog_id, created_date, modified_date) VALUES (3, 1, '서울시 성북구', '경기 고양시', '2023-11-13', '2023-11-25', '13:00', false, '이동봉사 공고입니다.', 1, 3, now(), now());
INSERT INTO post (id, status, departure_loc, arrival_loc, start_date, end_date, pick_up_time, is_kennel, content, intermediary_id, dog_id, created_date, modified_date) VALUES (4, 2, '서울시 성북구', '경기 고양시', '2023-11-13', '2023-11-25', '13:00', false, '이동봉사 공고입니다.', 1, 4, now(), now());
INSERT INTO post (id, status, departure_loc, arrival_loc, start_date, end_date, pick_up_time, is_kennel, content, intermediary_id, dog_id, created_date, modified_date) VALUES (5, 3, '서울시 성북구', '경기 고양시', '2023-11-13', '2023-11-25', '13:00', false, '이동봉사 공고입니다.', 1, 5, now(), now());
-- INSERT POST_IMAGE
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (1, 'image1', 1, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (2, 'image2', 1, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (3, 'image3', 1, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (4, 'image1', 2, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (5, 'image2', 2, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (6, 'image1', 3, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (7, 'image2', 3, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (8, 'image1', 4, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (9, 'image2', 4, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (10, 'image1', 5, now(), now());
INSERT INTO post_image (id, image, post_id, created_date, modified_date) VALUES (11, 'image2', 5, now(), now());
-- UPDATE POST MAIN IMAGE
UPDATE post SET main_image_id = 1 WHERE id = 1;
UPDATE post SET main_image_id = 4 WHERE id = 2;
UPDATE post SET main_image_id = 6 WHERE id = 3;
UPDATE post SET main_image_id = 8 WHERE id = 4;
UPDATE post SET main_image_id = 10 WHERE id = 5;
-- INSERT APPLICATION
INSERT INTO application (id, status, volunteer_name, phone, transportation, content, post_id, intermediary_id, volunteer_id, created_date, modified_date) VALUES (1, 0, '한호정', '01022223333', 'BMW', '이동봉사 신청합니다!', 3, 1, 1,now(), now());
INSERT INTO application (id, status, volunteer_name, phone, transportation, content, post_id, intermediary_id, volunteer_id, created_date, modified_date) VALUES (2, 1, '한호정', '01022223333', 'BMW', '이동봉사 신청합니다!', 4, 1, 1,now(), now());
INSERT INTO application (id, status, volunteer_name, phone, transportation, content, post_id, intermediary_id, volunteer_id, created_date, modified_date) VALUES (3, 2, '한호정', '01022223333', 'BMW', '이동봉사 신청합니다!', 5, 1, 1,now(), now());
Loading

0 comments on commit 90cec58

Please sign in to comment.