-
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.
Merge pull request #6 from hanium-haemil/feature/schedule
[FEAT] 일정 CRUD #5
- Loading branch information
Showing
14 changed files
with
598 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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/haemil/backend/global/config/SpringConfig.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,20 @@ | ||
package com.haemil.backend.global.config; | ||
|
||
import com.haemil.backend.schedule.repository.ScheduleRepository; | ||
import com.haemil.backend.schedule.service.ScheduleService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SpringConfig { | ||
private final ScheduleRepository scheduleRepository; | ||
|
||
public SpringConfig(ScheduleRepository scheduleRepository){ | ||
this.scheduleRepository = scheduleRepository; | ||
} | ||
|
||
@Bean | ||
public ScheduleService scheduleService(){ | ||
return new ScheduleService(scheduleRepository); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/haemil/backend/global/exception/BaseException.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,19 @@ | ||
package com.haemil.backend.global.exception; | ||
|
||
import com.haemil.backend.global.config.ResponseStatus; | ||
|
||
public class BaseException extends RuntimeException { | ||
|
||
private final ResponseStatus status; | ||
|
||
|
||
public BaseException(ResponseStatus status) { | ||
super(status.getMessage()); | ||
this.status = status; | ||
} | ||
|
||
public ResponseStatus getStatus() { | ||
return status; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/haemil/backend/global/exception/MissingRequiredFieldException.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,11 @@ | ||
package com.haemil.backend.global.exception; | ||
|
||
import com.haemil.backend.global.config.ResponseStatus; | ||
|
||
public class MissingRequiredFieldException extends BaseException { | ||
|
||
public MissingRequiredFieldException(String s) { | ||
super(ResponseStatus.MISSING_REQUIRED_FIELD); | ||
} | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
src/main/java/com/haemil/backend/schedule/controller/ScheduleController.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,4 +1,121 @@ | ||
package com.haemil.backend.schedule.controller; | ||
|
||
import com.haemil.backend.global.config.BaseResponse; | ||
import com.haemil.backend.global.exception.BaseException; | ||
import com.haemil.backend.map.service.MapService; | ||
import com.haemil.backend.schedule.dto.ScheduleRequestDto; | ||
import com.haemil.backend.schedule.dto.ScheduleResponseDto; | ||
import com.haemil.backend.schedule.entity.Schedule; | ||
import com.haemil.backend.schedule.service.ScheduleService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/schedules") | ||
@Slf4j | ||
public class ScheduleController { | ||
|
||
public final ScheduleService scheduleService; | ||
public final MapService mapService; | ||
|
||
@Autowired | ||
public ScheduleController(ScheduleService scheduleService, MapService mapService) { | ||
this.scheduleService = scheduleService; | ||
this.mapService = mapService; | ||
} | ||
|
||
//일정 추가 API | ||
@PostMapping("/schedule") | ||
public ResponseEntity<BaseResponse> createSchedule(@RequestBody ScheduleRequestDto scheduleRequestDto) { | ||
|
||
try { | ||
ScheduleResponseDto createSchedule = scheduleService.createSchedule(scheduleRequestDto); | ||
|
||
// 맵 API 호출하여 맵 URL 얻어오는 부분 | ||
String mapUrl = mapService.getMapUrl(scheduleRequestDto.getPlace()); | ||
// 응답에 맵 URL을 포함하여 리턴 | ||
createSchedule.setMapUrl(mapUrl); | ||
|
||
BaseResponse<ScheduleResponseDto> response = new BaseResponse<>(createSchedule); | ||
return response.convert(); | ||
|
||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()).convert(); | ||
} catch (com.haemil.backend.global.config.BaseException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
//주어진 날짜에 해당하는 일정 조회 API | ||
@GetMapping("/getSchedule") | ||
public ResponseEntity<BaseResponse> getSchedulesByDate(@RequestParam("localDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate localDate) { | ||
try { | ||
List<Schedule> schedules = scheduleService.getSchedule(localDate); | ||
return new BaseResponse<>(schedules).convert(); | ||
|
||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()).convert(); | ||
} | ||
} | ||
|
||
|
||
//오늘 일정 조회 API | ||
@GetMapping("/today") | ||
public ResponseEntity<BaseResponse> getTodaySchedules() { | ||
try { | ||
List<Schedule> todaySchedules = scheduleService.getTodaySchedules(); | ||
return new BaseResponse<>(todaySchedules).convert(); | ||
|
||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()).convert(); | ||
} | ||
} | ||
|
||
|
||
//일정 삭제 API | ||
@DeleteMapping("/schedule/{scheduleId}") | ||
public ResponseEntity<BaseResponse> deleteSchedule(@PathVariable Long scheduleId) { | ||
try { | ||
Long deletedId = scheduleService.deleteSchedule(scheduleId); | ||
BaseResponse<Long> response = new BaseResponse<>(deletedId); | ||
return response.convert(); | ||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()).convert(); | ||
} | ||
} | ||
|
||
|
||
//일정 수정 API | ||
@PatchMapping("/schedule/{scheduleId}") | ||
public ResponseEntity<BaseResponse> updateSchedule(@PathVariable Long scheduleId, @RequestBody ScheduleRequestDto requestDto) { | ||
try { | ||
Schedule updateSchedule = scheduleService.updateSchedule(scheduleId, requestDto); | ||
log.debug("requestDto.getPlace() = {}",requestDto.getPlace()); | ||
|
||
// 맵 API 호출하여 맵 URL 얻어오는 부분 | ||
String mapUrl = mapService.getMapUrl(requestDto.getPlace()); | ||
|
||
// 응답에 맵 URL을 포함하여 리턴 | ||
updateSchedule.setMapUrl(mapUrl); | ||
System.out.println(mapUrl); | ||
|
||
ScheduleResponseDto responseDto = new ScheduleResponseDto(updateSchedule); | ||
BaseResponse<ScheduleResponseDto> response = new BaseResponse<>(responseDto); | ||
return response.convert(); | ||
|
||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()).convert(); | ||
|
||
} catch (com.haemil.backend.global.config.BaseException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/haemil/backend/schedule/dto/ScheduleRequestDto.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,35 @@ | ||
package com.haemil.backend.schedule.dto; | ||
|
||
import com.haemil.backend.schedule.entity.RepeatType; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
//schedule에 데이터를 넣을 때의 입력 요청 값을 받음 | ||
@NoArgsConstructor | ||
@Getter | ||
public class ScheduleRequestDto { | ||
|
||
private Long id; | ||
|
||
private LocalDate localDate; | ||
|
||
private DayOfWeek dayOfWeek; | ||
|
||
private LocalTime time; | ||
|
||
private String content; | ||
|
||
private Boolean done; | ||
|
||
private String place; | ||
|
||
private String medicine; | ||
|
||
private RepeatType repeatType; | ||
|
||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/haemil/backend/schedule/dto/ScheduleResponseDto.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,63 @@ | ||
package com.haemil.backend.schedule.dto; | ||
|
||
import com.haemil.backend.schedule.entity.RepeatType; | ||
import com.haemil.backend.schedule.entity.Schedule; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
//schedule에서 값을 가져올 때 직접적인 entity 대신 앞에 써줌 | ||
//클라이언트에게 응답할 때 필요한 속성들 추가 | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class ScheduleResponseDto { | ||
|
||
private String mapUrl; | ||
|
||
private Long id; | ||
|
||
private LocalDate localDate; | ||
|
||
private DayOfWeek dayOfWeek; | ||
|
||
private LocalTime time; | ||
|
||
private String content; | ||
|
||
private String place; | ||
|
||
private Boolean done; | ||
|
||
private String medicine; | ||
|
||
private RepeatType repeatType; | ||
|
||
|
||
public ScheduleResponseDto(Schedule schedule){ | ||
this.mapUrl = schedule.getMapUrl(); | ||
|
||
this.id = schedule.getId(); | ||
|
||
this.localDate = schedule.getLocalDate(); | ||
|
||
this.dayOfWeek = schedule.getDayOfWeek(); | ||
|
||
this.time = schedule.getTime(); | ||
|
||
this.content = schedule.getContent(); | ||
|
||
this.place = schedule.getPlace(); | ||
|
||
this.done = schedule.getDone(); | ||
|
||
this.medicine = schedule.getMedicine(); | ||
|
||
this.repeatType = schedule.getRepeatType(); | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/haemil/backend/schedule/entity/RepeatType.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 com.haemil.backend.schedule.entity; | ||
|
||
|
||
public enum RepeatType { | ||
DAILY, | ||
WEEKLY, | ||
MONTHLY, | ||
NONE | ||
} |
59 changes: 53 additions & 6 deletions
59
src/main/java/com/haemil/backend/schedule/entity/Schedule.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,19 +1,66 @@ | ||
package com.haemil.backend.schedule.entity; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Id; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
import javax.persistence.*; | ||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
@Entity(name = "schedules") | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
public class Schedule { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
//date는 생성과 수정 필요 | ||
private LocalDate date; | ||
//일정의 실제 날짜 정보(year, month, day) | ||
@Column(nullable = false) | ||
private LocalDate localDate; | ||
|
||
//요일 | ||
@Column(nullable = false) | ||
private DayOfWeek dayOfWeek; | ||
|
||
private DayOfWeek week; | ||
//일정 시간(hour, minute, second, nano) | ||
@Column(nullable = false) | ||
private LocalTime time; | ||
|
||
@Column(nullable = true, length = 100) | ||
//일정 내용 | ||
@Column(nullable = false, length = 100) | ||
private String content; | ||
|
||
//일정 완료 여부 | ||
@Column(nullable = false) | ||
private Boolean done; | ||
|
||
//장소 | ||
@Column(nullable = true, length = 50) | ||
private String place; | ||
|
||
//약 | ||
@Column(nullable = true, length = 50) | ||
private String medicine; | ||
|
||
//반복 routine | ||
@Enumerated(value = EnumType.STRING) | ||
@Column(nullable = false) | ||
private RepeatType repeatType; | ||
|
||
private String mapUrl; | ||
|
||
public String getMapUrl() { | ||
return mapUrl; | ||
} | ||
|
||
public void setMapUrl(String mapUrl) { | ||
this.mapUrl = mapUrl; | ||
} | ||
|
||
} |
Oops, something went wrong.