diff --git a/src/main/java/org/sopt/sopkerton/common/exception/ProgramError.java b/src/main/java/org/sopt/sopkerton/common/exception/ProgramError.java new file mode 100644 index 0000000..14e335b --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/common/exception/ProgramError.java @@ -0,0 +1,4 @@ +package org.sopt.sopkerton.common.exception; + +public enum ProgramError { +} diff --git a/src/main/java/org/sopt/sopkerton/common/exception/ProgramSuccess.java b/src/main/java/org/sopt/sopkerton/common/exception/ProgramSuccess.java new file mode 100644 index 0000000..893ec06 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/common/exception/ProgramSuccess.java @@ -0,0 +1,29 @@ +package org.sopt.sopkerton.common.exception; + +import lombok.AllArgsConstructor; +import org.sopt.sopkerton.common.exception.base.SuccessBase; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +public enum ProgramSuccess implements SuccessBase { + PROGRAM_LIST_VIEW_SUCCESS(HttpStatus.OK, "Get Program List View Data Successful.") + ; + + private final HttpStatus status; + private final String successMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getSuccessMessage() { + return this.successMessage; + } +} diff --git a/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java b/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java new file mode 100644 index 0000000..449c87f --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java @@ -0,0 +1,32 @@ +package org.sopt.sopkerton.program.controller; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.sopt.sopkerton.common.exception.ProgramSuccess; +import org.sopt.sopkerton.common.response.ApiResponse; +import org.sopt.sopkerton.program.dto.request.ProgramListRequest; +import org.sopt.sopkerton.program.dto.response.ProgramListResponse; +import org.sopt.sopkerton.program.service.ProgramService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +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.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/program") +public class ProgramController { + private final ProgramService programService; + + @GetMapping("") + public ResponseEntity>> programListView(@RequestParam(name = "program_type") String type) { + List programListByProgramType = programService.getProgramListByProgramType(type); + return ResponseEntity + .status(ProgramSuccess.PROGRAM_LIST_VIEW_SUCCESS.getHttpStatus()) + .body( + ApiResponse.success(ProgramSuccess.PROGRAM_LIST_VIEW_SUCCESS, programListByProgramType) + ); + } +} diff --git a/src/main/java/org/sopt/sopkerton/program/domain/Program.java b/src/main/java/org/sopt/sopkerton/program/domain/Program.java index 31ab2e4..e8fd2a3 100644 --- a/src/main/java/org/sopt/sopkerton/program/domain/Program.java +++ b/src/main/java/org/sopt/sopkerton/program/domain/Program.java @@ -20,21 +20,23 @@ @Getter @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn +@DiscriminatorColumn(name = "program_type") @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "programs") public abstract class Program extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "program_id") private Long id; @Column(nullable = false) private String title; - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private Category category; + private String imageUrl; + private String type; + @Enumerated(value = EnumType.STRING) + private Status status; @Column(nullable = false) private String organizationName; diff --git a/src/main/java/org/sopt/sopkerton/program/domain/Category.java b/src/main/java/org/sopt/sopkerton/program/domain/Status.java similarity index 64% rename from src/main/java/org/sopt/sopkerton/program/domain/Category.java rename to src/main/java/org/sopt/sopkerton/program/domain/Status.java index 2a10653..621c9af 100644 --- a/src/main/java/org/sopt/sopkerton/program/domain/Category.java +++ b/src/main/java/org/sopt/sopkerton/program/domain/Status.java @@ -6,9 +6,6 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public enum Category { - VOLUNTEERING("봉사"), - EMPLOYMENT("취업"); - - private final String value; +public enum Status { + REGISTER, DONE; } diff --git a/src/main/java/org/sopt/sopkerton/program/dto/request/ProgramListRequest.java b/src/main/java/org/sopt/sopkerton/program/dto/request/ProgramListRequest.java new file mode 100644 index 0000000..bb3723d --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/program/dto/request/ProgramListRequest.java @@ -0,0 +1,9 @@ +package org.sopt.sopkerton.program.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public record ProgramListRequest( + @JsonProperty("program_type") + String programType +) { +} diff --git a/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramListResponse.java b/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramListResponse.java new file mode 100644 index 0000000..707e054 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramListResponse.java @@ -0,0 +1,15 @@ +package org.sopt.sopkerton.program.dto.response; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public record ProgramListResponse( + long programId, + String title, + String registerAt, + String imageUrl, + String Region +) { + +} diff --git a/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java b/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java new file mode 100644 index 0000000..158051d --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java @@ -0,0 +1,13 @@ +package org.sopt.sopkerton.program.infrastructure; + +import java.util.List; +import org.sopt.sopkerton.program.domain.Program; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface ProgramRepository extends JpaRepository { + + @Query("select p from Program p where p.type = :type order by p.registerAt") + List findAllByProgramType(@Param("type")String programType); +} diff --git a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java new file mode 100644 index 0000000..bc29012 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java @@ -0,0 +1,39 @@ +package org.sopt.sopkerton.program.service; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.sopt.sopkerton.program.domain.Program; +import org.sopt.sopkerton.program.dto.response.ProgramListResponse; +import org.sopt.sopkerton.program.infrastructure.ProgramRepository; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ProgramService { + private final ProgramRepository programRepository; + + public List getProgramListByProgramType(String programType) { + List programs = programRepository.findAllByProgramType(programType); + + List programListResponses = programs.stream() + .map(program -> new ProgramListResponse( + program.getId(), + program.getTitle(), + formatToLocalDate(program.getRegisterAt()), + program.getImageUrl(), + program.getRegion() + )) + .collect(Collectors.toList()); + return programListResponses; + } + + private String formatToLocalDate(LocalDateTime localDateTime) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM월 dd일"); + return localDateTime.format(formatter); + } + + +}