|
| 1 | +package com.somemore.recruitboard.controller; |
| 2 | + |
| 3 | +import static org.springframework.data.domain.Sort.Direction.DESC; |
| 4 | + |
| 5 | +import com.somemore.global.common.response.ApiResponse; |
| 6 | +import com.somemore.recruitboard.domain.RecruitStatus; |
| 7 | +import com.somemore.recruitboard.domain.VolunteerType; |
| 8 | +import com.somemore.recruitboard.dto.condition.RecruitBoardNearByCondition; |
| 9 | +import com.somemore.recruitboard.dto.condition.RecruitBoardSearchCondition; |
| 10 | +import com.somemore.recruitboard.dto.response.RecruitBoardDetailResponseDto; |
| 11 | +import com.somemore.recruitboard.dto.response.RecruitBoardResponseDto; |
| 12 | +import com.somemore.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; |
| 13 | +import com.somemore.recruitboard.dto.response.RecruitBoardWithLocationResponseDto; |
| 14 | +import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; |
| 15 | +import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | +import java.util.UUID; |
| 18 | +import lombok.RequiredArgsConstructor; |
| 19 | +import org.springframework.data.domain.Page; |
| 20 | +import org.springframework.data.domain.Pageable; |
| 21 | +import org.springframework.data.web.PageableDefault; |
| 22 | +import org.springframework.web.bind.annotation.GetMapping; |
| 23 | +import org.springframework.web.bind.annotation.PathVariable; |
| 24 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 25 | +import org.springframework.web.bind.annotation.RequestParam; |
| 26 | +import org.springframework.web.bind.annotation.RestController; |
| 27 | + |
| 28 | +@Tag(name = "Recruit Board Query API", description = "봉사 활동 모집 조회 관련 API") |
| 29 | +@RequiredArgsConstructor |
| 30 | +@RequestMapping("/api") |
| 31 | +@RestController |
| 32 | +public class RecruitBoardQueryController { |
| 33 | + |
| 34 | + private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; |
| 35 | + |
| 36 | + @GetMapping("/recruit-board/{id}") |
| 37 | + @Operation(summary = "봉사 모집글 상세 조회", description = "특정 모집글의 상세 정보를 조회합니다.") |
| 38 | + public ApiResponse<RecruitBoardWithLocationResponseDto> getById( |
| 39 | + @PathVariable Long id |
| 40 | + ) { |
| 41 | + return ApiResponse.ok( |
| 42 | + 200, |
| 43 | + recruitBoardQueryUseCase.getWithLocationById(id), |
| 44 | + "봉사 활동 모집 상세 조회 성공" |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + @GetMapping("/recruit-boards") |
| 49 | + @Operation(summary = "전체 모집글 조회", description = "모든 봉사 모집글 목록을 조회합니다.") |
| 50 | + public ApiResponse<Page<RecruitBoardWithCenterResponseDto>> getAll( |
| 51 | + @PageableDefault(size = 10, page = 0, sort = "created_at", direction = DESC) |
| 52 | + Pageable pageable |
| 53 | + ) { |
| 54 | + RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder() |
| 55 | + .pageable(pageable) |
| 56 | + .build(); |
| 57 | + |
| 58 | + return ApiResponse.ok( |
| 59 | + 200, |
| 60 | + recruitBoardQueryUseCase.getAllWithCenter(condition), |
| 61 | + "봉사 활동 모집글 리스트 조회 성공" |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + @GetMapping("/recruit-boards/search") |
| 66 | + @Operation(summary = "모집글 검색 조회", description = "검색 조건을 기반으로 모집글을 조회합니다.") |
| 67 | + public ApiResponse<Page<RecruitBoardWithCenterResponseDto>> getAllBySearch( |
| 68 | + @PageableDefault(size = 10, page = 0, sort = "created_at", direction = DESC) Pageable pageable, |
| 69 | + @RequestParam(required = false) String keyword, |
| 70 | + @RequestParam(required = false) VolunteerType type, |
| 71 | + @RequestParam(required = false) String region, |
| 72 | + @RequestParam(required = false) Boolean admitted, |
| 73 | + @RequestParam(required = false) RecruitStatus status |
| 74 | + ) { |
| 75 | + RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder() |
| 76 | + .keyword(keyword) |
| 77 | + .type(type) |
| 78 | + .region(region) |
| 79 | + .admitted(admitted) |
| 80 | + .status(status) |
| 81 | + .pageable(pageable) |
| 82 | + .build(); |
| 83 | + |
| 84 | + return ApiResponse.ok( |
| 85 | + 200, |
| 86 | + recruitBoardQueryUseCase.getAllWithCenter(condition), |
| 87 | + "봉사 활동 모집글 검색 조회 성공" |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + @GetMapping("/recruit-boards/nearby") |
| 92 | + @Operation(summary = "근처 모집글 조회", description = "주변 반경 내의 봉사 모집글을 조회합니다.") |
| 93 | + public ApiResponse<Page<RecruitBoardDetailResponseDto>> getNearby( |
| 94 | + @RequestParam double latitude, |
| 95 | + @RequestParam double longitude, |
| 96 | + @RequestParam(required = false, defaultValue = "5") double radius, |
| 97 | + @RequestParam(required = false) String keyword, |
| 98 | + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable |
| 99 | + ) { |
| 100 | + RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder() |
| 101 | + .latitude(latitude) |
| 102 | + .longitude(longitude) |
| 103 | + .radius(radius) |
| 104 | + .keyword(keyword) |
| 105 | + .pageable(pageable) |
| 106 | + .build(); |
| 107 | + |
| 108 | + return ApiResponse.ok( |
| 109 | + 200, |
| 110 | + recruitBoardQueryUseCase.getRecruitBoardsNearby(condition), |
| 111 | + "근처 봉사 활동 모집글 조회 성공" |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + @GetMapping("/recruit-boards/center/{centerId}") |
| 116 | + @Operation(summary = "특정 기관 모집글 조회", description = "특정 기관의 봉사 모집글을 조회합니다.") |
| 117 | + public ApiResponse<Page<RecruitBoardResponseDto>> getRecruitBoardsByCenterId( |
| 118 | + @PathVariable UUID centerId, |
| 119 | + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable |
| 120 | + ) { |
| 121 | + return ApiResponse.ok( |
| 122 | + 200, |
| 123 | + recruitBoardQueryUseCase.getRecruitBoardsByCenterId(centerId, pageable), |
| 124 | + "기관 봉사 활동 모집글 조회 성공" |
| 125 | + ); |
| 126 | + } |
| 127 | +} |
0 commit comments