Skip to content

Commit

Permalink
♻️Refactor: LocalDate로 바꿨습니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jindongleee committed Oct 8, 2024
1 parent 8214800 commit 484dad0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.korad1004.back_end.my_travel_plan.dto.CreateCourseDto;
import com.korad1004.back_end.my_travel_plan.service.ScheduleService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -23,13 +24,14 @@ public class ScheduleController {

//스케줄 만들기
@PostMapping
public ResponseEntity<String> createSchedule(@RequestBody CreateCourseDto createCourseDto) throws Exception{
public ResponseEntity<?> createSchedule(@RequestBody CreateCourseDto createCourseDto) throws Exception{
try{
return ResponseEntity.ok(scheduleService.createSchedule(createCourseDto));
} catch (Exception e) {
throw new RuntimeException("암호 화가 안 됐어요 you know?",e);
scheduleService.createSchedule(createCourseDto);
}catch (RuntimeException e){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

return ResponseEntity.created(URI.create("/api/schedule")).build();
}

@GetMapping("/{travel_code}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import java.time.LocalDate;
import java.util.List;

@Getter
Expand All @@ -14,9 +15,9 @@ public class CreateCourseDto {

private Integer headCount;

private String startDate;
private LocalDate startDate;

private String endDate;
private LocalDate endDate;

private String days;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.korad1004.back_end.my_travel_plan.entity.Schedule;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.time.LocalDate;

@Getter
@Setter
Expand All @@ -17,14 +16,12 @@ public class GetScheduleOfCode {

private Integer headCount;

private String startDate;
private LocalDate startDate;

private String endDate;
private LocalDate endDate;

private String days;

//number,[hotspot_image,hotspot_title,hotspot_address,hotspot_latitude,hotspot_longitude],memo

public static GetScheduleOfCode from(Schedule schedule){

GetScheduleOfCode getScheduleOfCode = new GetScheduleOfCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDate;
import java.util.List;

@Entity
Expand All @@ -23,11 +24,11 @@ public class Schedule {

//시작날짜
@Column(name = "start_date")
private String startDate;
private LocalDate startDate;

//종료날짜
@Column(name = "end_date")
private String endDate;
private LocalDate endDate;

//일차
@Column(name = "travel_days")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,24 @@ public String createSchedule(CreateCourseDto createCourseDto) throws Exception {
//인원수
schedule.setHeadCount(createCourseDto.getHeadCount());

//시작날짜
schedule.setStartDate(createCourseDto.getStartDate());

//종료 날짜
schedule.setEndDate(createCourseDto.getEndDate());
//시작날짜가 종료날짜보다 작다 -> true 반환
if(createCourseDto.getStartDate().isBefore(createCourseDto.getEndDate())){
//시작날짜
schedule.setStartDate(createCourseDto.getStartDate());

//종료 날짜
schedule.setEndDate(createCourseDto.getEndDate());
}
else if(createCourseDto.getStartDate().isEqual(createCourseDto.getEndDate())){
//시작날짜
schedule.setStartDate(createCourseDto.getStartDate());

//종료 날짜
schedule.setEndDate(createCourseDto.getEndDate());
}
else throw new RuntimeException("시간 잘못 입력 하셨습니다.");


//일수
schedule.setDays(createCourseDto.getDays());
Expand Down

0 comments on commit 484dad0

Please sign in to comment.