Skip to content

Commit

Permalink
Merge pull request #64 from team-Ollie/develop
Browse files Browse the repository at this point in the history
[develop]
  • Loading branch information
Haeun-Y authored Jun 26, 2024
2 parents d61b4fd + f993bb1 commit be9b4e1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ollie.wecare.challenge.dto.*;
import ollie.wecare.challenge.service.ChallengeService;
import ollie.wecare.common.base.BaseException;
Expand All @@ -16,6 +17,7 @@
@RestController
@RequestMapping(challenge)
@RequiredArgsConstructor
@Slf4j
public class ChallengeController {

private final ChallengeService challengeService;
Expand Down Expand Up @@ -66,7 +68,7 @@ public BaseResponse<String> participateChallenge(@RequestBody PostChallengeReq p
* */
@GetMapping("/search")
@ResponseBody
public BaseResponse<List<GetChallengesRes>> getChallenges(@RequestParam(value = "searhWord", defaultValue = "", required = false) String searchWord)throws BaseException {
public BaseResponse<List<GetChallengesRes>> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException {
return new BaseResponse<>(challengeService.getChallenges(searchWord));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum BaseResponseStatus {
ACCESS_DENIED(false, HttpStatus.BAD_REQUEST, "접근 권한이 없습니다."),

// program
INVALID_PROGRAM_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 ProgramIdx 입니다."),

// challenge
INVALID_ATTENDANCE_CODE(false, HttpStatus.BAD_REQUEST, "잘못된 인증번호입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import ollie.wecare.common.base.BaseException;
import ollie.wecare.common.base.BaseResponse;
import ollie.wecare.program.dto.GetProgramDetailRes;
import ollie.wecare.program.dto.GetProgramRes;
import ollie.wecare.program.dto.PostProgramReq;
import ollie.wecare.program.service.ProgramService;
Expand Down Expand Up @@ -30,6 +31,12 @@ public BaseResponse<List<GetProgramRes>> getPrograms(@RequestParam(value = "year
return new BaseResponse<>(programService.getPrograms(year, month));
}

@GetMapping("/{programIdx}")
@ResponseBody
public BaseResponse<GetProgramDetailRes> getProgram(@PathVariable(value = "programIdx") Long programIdx) {
return new BaseResponse<>(programService.getProgram(programIdx));
}

/*
* 프로그램 등록
* */
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ollie.wecare.program.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.program.entity.Program;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class GetProgramDetailRes {


private Long programIdx;

private String name;

private DateDto openDate;

private DateDto dueDate;

private String location;

private String host;

private String schedule;

private String description;


public static GetProgramDetailRes fromProgram(Program program) {
return GetProgramDetailRes.builder()
.programIdx(program.getProgramIdx())
.name(program.getName())
.openDate(convertToDateDto(program.getOpenDate()))
.dueDate(convertToDateDto(program.getDueDate()))
.location(program.getLocation())
.host(program.getHost())
.schedule(program.getSchedule())
.description(program.getDescription()).build();
}

private static DateDto convertToDateDto(LocalDateTime dueDate) {
if (dueDate == null) return null;
return new DateDto(
dueDate.getYear(),
dueDate.getMonthValue(),
dueDate.getDayOfMonth());
}
}
17 changes: 4 additions & 13 deletions src/main/java/ollie/wecare/program/dto/GetProgramRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,16 @@ public class GetProgramRes {

private String name;

private DateDto dueDate;

private String location;

private String host;
private DateDto openDate;

private String schedule;

private String description;
private DateDto dueDate;

public static GetProgramRes fromProgram(Program program) {
return GetProgramRes.builder()
.programIdx(program.getProgramIdx())
.name(program.getName())
.dueDate(convertToDateDto(program.getDueDate()))
.location(program.getLocation())
.host(program.getHost())
.schedule(program.getSchedule())
.description(program.getDescription()).build();
.openDate(convertToDateDto(program.getOpenDate()))
.dueDate(convertToDateDto(program.getDueDate())).build();
}

private static DateDto convertToDateDto(LocalDateTime dueDate) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ollie/wecare/program/entity/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Program extends BaseEntity {

private LocalDateTime dueDate;

private LocalDateTime openDate;

private String location;

private String host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ollie.wecare.challenge.repository.ChallengeRepository;
import ollie.wecare.common.base.BaseException;
import ollie.wecare.common.enums.Role;
import ollie.wecare.program.dto.GetProgramDetailRes;
import ollie.wecare.program.dto.GetProgramRes;
import ollie.wecare.program.dto.PostProgramReq;
import ollie.wecare.program.entity.Program;
Expand All @@ -20,8 +21,7 @@
import java.time.temporal.TemporalAdjusters;
import java.util.List;

import static ollie.wecare.common.base.BaseResponseStatus.INVALID_ROLE;
import static ollie.wecare.common.base.BaseResponseStatus.INVALID_USER_IDX;
import static ollie.wecare.common.base.BaseResponseStatus.*;

@Service
@RequiredArgsConstructor
Expand All @@ -45,6 +45,11 @@ public List<GetProgramRes> getPrograms(Long year, Long month) {
.toList();
}

public GetProgramDetailRes getProgram(Long programIdx) {
return GetProgramDetailRes.fromProgram(
programRepository.findById(programIdx).orElseThrow(()-> new BaseException(INVALID_PROGRAM_IDX)));
}

public void saveProgram(PostProgramReq postProgramReq) {
User user = userRepository.findById(authService.getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER_IDX));
if(!user.getRole().equals(Role.Admin)) throw new BaseException(INVALID_ROLE);
Expand Down

0 comments on commit be9b4e1

Please sign in to comment.