-
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
…ram_type_api Feat/#13 separate program type api
- Loading branch information
Showing
9 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/main/java/org/sopt/sopkerton/common/exception/ProgramError.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,4 @@ | ||
package org.sopt.sopkerton.common.exception; | ||
|
||
public enum ProgramError { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sopt/sopkerton/common/exception/ProgramSuccess.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,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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/sopt/sopkerton/program/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 |
---|---|---|
@@ -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<ApiResponse<List<ProgramListResponse>>> programListView(@RequestParam(name = "program_type") String type) { | ||
List<ProgramListResponse> programListByProgramType = programService.getProgramListByProgramType(type); | ||
return ResponseEntity | ||
.status(ProgramSuccess.PROGRAM_LIST_VIEW_SUCCESS.getHttpStatus()) | ||
.body( | ||
ApiResponse.success(ProgramSuccess.PROGRAM_LIST_VIEW_SUCCESS, programListByProgramType) | ||
); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/sopkerton/program/dto/request/ProgramListRequest.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,9 @@ | ||
package org.sopt.sopkerton.program.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ProgramListRequest( | ||
@JsonProperty("program_type") | ||
String programType | ||
) { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/sopt/sopkerton/program/dto/response/ProgramListResponse.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,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 | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.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,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<Program, Long> { | ||
|
||
@Query("select p from Program p where p.type = :type order by p.registerAt") | ||
List<Program> findAllByProgramType(@Param("type")String programType); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sopt/sopkerton/program/service/ProgramService.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,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<ProgramListResponse> getProgramListByProgramType(String programType) { | ||
List<Program> programs = programRepository.findAllByProgramType(programType); | ||
|
||
List<ProgramListResponse> 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); | ||
} | ||
|
||
|
||
} |