-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat : main API 추가
- Loading branch information
Showing
10 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kusitms.gallae.config; | ||
|
||
public class BaseException extends RuntimeException { | ||
private final BaseResponseStatus status; | ||
|
||
public BaseException(BaseResponseStatus status) { | ||
this.status = status; | ||
} | ||
|
||
public BaseResponseStatus getStatus() { | ||
return this.status; | ||
} | ||
|
||
public String getMessage() { | ||
return this.status.getMessage(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kusitms/gallae/config/ExceptionHandlerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package kusitms.gallae.config; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class ExceptionHandlerAdvice { | ||
|
||
@ExceptionHandler(BaseException.class) | ||
public ResponseEntity<BaseResponse<?>> handleBaseException(BaseException e, HttpServletRequest request) { | ||
|
||
return ResponseEntity.status(e.getStatus().getHttpStatus()).body(new BaseResponse<>(e.getStatus())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 54 additions & 1 deletion
55
src/main/java/kusitms/gallae/controller/ProgramController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,79 @@ | ||
package kusitms.gallae.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.Positive; | ||
import kusitms.gallae.config.BaseResponse; | ||
import kusitms.gallae.dto.program.ProgramDetailRes; | ||
import kusitms.gallae.dto.program.ProgramMainRes; | ||
import kusitms.gallae.service.ProgramService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/program") | ||
@RequestMapping("/programs") | ||
public class ProgramController { | ||
|
||
private final ProgramService programService; | ||
|
||
@Operation(summary = "최신 프로그램 상위 4개", description = """ | ||
최근에 등록된 프로그램 상위 4개를 반환 합니다. | ||
""") | ||
@GetMapping("/recent") | ||
public ResponseEntity<BaseResponse<List<ProgramMainRes>>> findRecentProgram(){ | ||
return ResponseEntity.ok(new BaseResponse<>(this.programService.getRecentPrograms())); | ||
} | ||
|
||
@Operation(summary = "프로그램 유형별 프로그램들", description = """ | ||
여행지원사업, 여행공모전, 여행대외활동 세가지 유형별로 프로그램들을 반환합니다. | ||
""") | ||
@GetMapping("/type") | ||
public ResponseEntity<BaseResponse<List<ProgramMainRes>>> findProgramsByProgramType( | ||
@Parameter(description = "프로그램 유형", example = "여행지원사업, 여행공모전, 여행대외활동") | ||
@RequestParam(value = "programType", required = true) | ||
String programType, | ||
|
||
@Parameter(description = "페이지 번호") | ||
@Positive(message = "must be greater than 0") | ||
@RequestParam(value = "page", defaultValue = "1") | ||
Integer pageNumber, | ||
|
||
@Parameter(description = "페이징 사이즈 (최대 100)") | ||
@Min(value = 1, message = "must be greater than or equal to 1") | ||
@Max(value = 100, message = "must be less than or equal to 100") | ||
@RequestParam(value = "size", defaultValue = "20") | ||
Integer pagingSize | ||
) { | ||
|
||
PageRequest pageRequest = PageRequest.of(pageNumber,pagingSize); | ||
return ResponseEntity.ok(new BaseResponse<>(this.programService.getProgramsByProgramType(programType,pageRequest))); | ||
} | ||
|
||
@Operation(summary = "인기 많은 프로그램들", description = """ | ||
찜수가 가장 높은 프로그램들을 상위 4개를 반환합니다. | ||
""") | ||
@GetMapping("/best") | ||
public ResponseEntity<BaseResponse<List<ProgramMainRes>>> findBestPrograms(){ | ||
return ResponseEntity.ok(new BaseResponse<>(this.programService.getBestPrograms())); | ||
} | ||
|
||
@GetMapping("/program") | ||
public ResponseEntity<BaseResponse<ProgramDetailRes>> findProgramDetail( | ||
@Parameter(description = "프로그램 ID") | ||
@RequestParam(value = "id", required = false) Long id | ||
){ | ||
return ResponseEntity.ok(new BaseResponse<>(this.programService.getProgramDetail(id))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/kusitms/gallae/dto/program/ProgramDetailRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package kusitms.gallae.dto.program; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
public class ProgramDetailRes { | ||
|
||
private Long id; | ||
|
||
private String photoUrl; | ||
|
||
private String programName; | ||
|
||
private Long Like; | ||
|
||
private String remainDay; | ||
|
||
private String location; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime recruitStartDate; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime recruitEndDate; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime tripStartDate; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime tripEndDate; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime activeStartDate; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime activeEndDate; | ||
|
||
private String contact; | ||
|
||
private String contactNumber; | ||
|
||
private String programLink; | ||
|
||
private String description; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package kusitms.gallae.service; | ||
|
||
import kusitms.gallae.dto.program.ProgramDetailRes; | ||
import kusitms.gallae.dto.program.ProgramMainRes; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ProgramService { | ||
|
||
ProgramDetailRes getProgramDetail(Long id); | ||
|
||
List<ProgramMainRes> getRecentPrograms(); | ||
|
||
List<ProgramMainRes> getProgramsByProgramType(String programType , Pageable pageable); | ||
|
||
List<ProgramMainRes> getBestPrograms(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters