Skip to content

Commit

Permalink
[FIX] schedule api
Browse files Browse the repository at this point in the history
  • Loading branch information
hisemsem committed Oct 11, 2023
1 parent e1e6515 commit 66d73ce
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public ResponseEntity<BaseResponse> createSchedule(@RequestBody ScheduleRequestD

try {
ScheduleResponseDto createSchedule = scheduleService.createSchedule(scheduleRequestDto);

// 맵 API 호출하여 맵 URL 얻어오는 부분
String mapUrl = mapService.getMapUrl(scheduleRequestDto.getPlace());
// 응답에 맵 URL을 포함하여 리턴
createSchedule.setMapUrl(mapUrl);

BaseResponse<ScheduleResponseDto> response = new BaseResponse<>(createSchedule);
Expand Down Expand Up @@ -98,12 +95,9 @@ public ResponseEntity<BaseResponse> deleteSchedule(@PathVariable Long 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class ScheduleRequestDto {

private LocalDate localDate;

private DayOfWeek dayOfWeek;

private LocalTime time;

private String content;
Expand All @@ -27,8 +25,6 @@ public class ScheduleRequestDto {

private String place;

private String medicine;

private RepeatType repeatType;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class ScheduleResponseDto {

private LocalDate localDate;

private DayOfWeek dayOfWeek;

private LocalTime time;

private String content;
Expand All @@ -33,8 +31,6 @@ public class ScheduleResponseDto {

private Boolean done;

private String medicine;

private RepeatType repeatType;


Expand All @@ -45,8 +41,6 @@ public ScheduleResponseDto(Schedule schedule){

this.localDate = schedule.getLocalDate();

this.dayOfWeek = schedule.getDayOfWeek();

this.time = schedule.getTime();

this.content = schedule.getContent();
Expand All @@ -55,8 +49,6 @@ public ScheduleResponseDto(Schedule schedule){

this.done = schedule.getDone();

this.medicine = schedule.getMedicine();

this.repeatType = schedule.getRepeatType();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class Schedule {
@Column(nullable = false)
private LocalDate localDate;

//요일
@Column(nullable = false)
private DayOfWeek dayOfWeek;

//일정 시간(hour, minute, second, nano)
@Column(nullable = false)
private LocalTime time;
Expand All @@ -44,10 +40,6 @@ public class Schedule {
@Column(nullable = true, length = 50)
private String place;

//약
@Column(nullable = true, length = 50)
private String medicine;

//반복 routine
@Enumerated(value = EnumType.STRING)
@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Optional;

@Primary
//JpaRepository를 상속받아서 데이터베이스와 상호작용하는 메서드들 제공
public interface ScheduleRepository extends JpaRepository<Schedule,Long> {

//일정을 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.util.Optional;



//Schedule 객체를 저장하고 조회하는 기능을 구현
//ScheduleRepository를 사용하여 데이터베이스와 상호작용
@Slf4j
@Transactional
public class ScheduleService {
Expand All @@ -41,40 +38,34 @@ public ScheduleService(ScheduleRepository scheduleRepository) {
public ScheduleResponseDto createSchedule(ScheduleRequestDto scheduleRequestDto) throws BaseException {
try {
LocalDate localDate = scheduleRequestDto.getLocalDate();
DayOfWeek dayOfWeek = scheduleRequestDto.getDayOfWeek();
String content = scheduleRequestDto.getContent();
Boolean done = scheduleRequestDto.getDone();
LocalTime time = scheduleRequestDto.getTime();
String place = scheduleRequestDto.getPlace();
String medicine = scheduleRequestDto.getMedicine();
RepeatType repeatType = scheduleRequestDto.getRepeatType();

Schedule schedule = new Schedule();

schedule.setLocalDate(localDate);
schedule.setDayOfWeek(dayOfWeek);
schedule.setContent(content);
schedule.setDone(done);
schedule.setTime(time);
schedule.setPlace(place);
schedule.setRepeatType(repeatType);
schedule.setMedicine(medicine);

// missing field 존재 여부 검사
if (localDate == null || dayOfWeek == null || time == null || content == null || done == null || repeatType == null) {
if (localDate == null || time == null || content == null || done == null || repeatType == null) {
throw new MissingRequiredFieldException("Required field(s) are missing");
}

// 여기서 중복 일정 검사를 수행하고 이미 존재하는 경우 예외를 던짐
List<Schedule> existingSchedules = scheduleRepository.findByLocalDate(localDate);
for (Schedule existingSchedule : existingSchedules) {
if (existingSchedule.getDayOfWeek() == dayOfWeek &&
existingSchedule.getTime().equals(time) &&
if (existingSchedule.getTime().equals(time) &&
existingSchedule.getContent().equals(content) &&
existingSchedule.getDone().equals(done) &&
existingSchedule.getRepeatType().equals(repeatType) &&
existingSchedule.getPlace().equals(place) &&
existingSchedule.getMedicine().equals(medicine)) {
existingSchedule.getPlace().equals(place)) {
throw new BaseException(ResponseStatus.CONFLICT);
}
}
Expand All @@ -99,7 +90,7 @@ public List<Schedule> getSchedule(LocalDate localDate) throws BaseException {
}
return schedules;
} catch (BaseException e) {
throw new BaseException(ResponseStatus.NOT_FOUND); // 현재의 예외를 다시 던져줍니다.
throw new BaseException(ResponseStatus.NOT_FOUND);
}

}
Expand All @@ -114,12 +105,10 @@ public List<Schedule> getTodaySchedules() throws BaseException {
if (todaySchedules.isEmpty()) {
throw new BaseException(ResponseStatus.NOT_FOUND);
}

return todaySchedules;

} catch (BaseException e) {

throw new BaseException(ResponseStatus.NOT_FOUND); // 현재의 예외를 다시 던져줍니다.
throw new BaseException(ResponseStatus.NOT_FOUND);
}
}

Expand Down Expand Up @@ -148,42 +137,35 @@ public Schedule updateSchedule(Long id, ScheduleRequestDto requestDto) {
Schedule schedule = scheduleRepository.findById(id).orElse(null);

LocalDate newLocalDate = requestDto.getLocalDate();
DayOfWeek newDayOfWeek = requestDto.getDayOfWeek();
String newContent = requestDto.getContent();
Boolean newDone = requestDto.getDone();
LocalTime newTime = requestDto.getTime();
String newPlace = requestDto.getPlace();
String newMedicine = requestDto.getMedicine();
RepeatType newRepeatType = requestDto.getRepeatType();

if (newLocalDate == null || newDayOfWeek == null || newTime == null || newContent == null || newDone == null || newRepeatType == null) {
if (newLocalDate == null || newTime == null || newContent == null || newDone == null || newRepeatType == null) {
throw new MissingRequiredFieldException("Required field(s) are missing in updated schedule");
}

// 여기서 중복 일정 검사를 수행하고 이미 존재하는 경우 예외를 던짐
List<Schedule> existingSchedules = scheduleRepository.findByLocalDate(newLocalDate);
for (Schedule existingSchedule : existingSchedules) {
System.out.println("existingSchedule: " + existingSchedule);
if (
existingSchedule.getDayOfWeek() == newDayOfWeek &&
existingSchedule.getTime().equals(newTime) &&
existingSchedule.getTime().equals(newTime) &&
existingSchedule.getContent().equals(newContent) &&
existingSchedule.getDone().equals(newDone) &&
existingSchedule.getRepeatType().equals(newRepeatType) &&
existingSchedule.getPlace().equals(newPlace) &&
existingSchedule.getMedicine().equals(newMedicine)) {
existingSchedule.getPlace().equals(newPlace)
) {
throw new BaseException(ResponseStatus.CONFLICT);
}
}
schedule.setLocalDate(newLocalDate);
schedule.setDayOfWeek(newDayOfWeek);
schedule.setContent(newContent);
schedule.setDone(newDone);
schedule.setTime(newTime);
schedule.setPlace(newPlace);
schedule.setRepeatType(newRepeatType);
schedule.setMedicine(newMedicine);

log.debug("newContent = {}", newContent);

return scheduleRepository.save(schedule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void createSchedule(){
LocalTime time = LocalTime.of(5, 3);
String place = "Test Place";

//when
/*//when
Schedule schedule = scheduleService.createSchedule(creationDate, dayOfWeek, content, important_schedule, fixed_schedule, time, place);
//then
Expand All @@ -52,7 +52,7 @@ void createSchedule(){
assertThat(schedule.isImportant()).isEqualTo(important_schedule);
assertThat(schedule.isFixed()).isEqualTo(fixed_schedule);
assertThat(schedule.getTime()).isEqualTo(time);
assertThat(schedule.getPlace()).isEqualTo(place);
assertThat(schedule.getPlace()).isEqualTo(place);*/

}

Expand Down

0 comments on commit 66d73ce

Please sign in to comment.