diff --git a/src/main/java/com/korad1004/back_end/my_travel_plan/controller/ScheduleController.java b/src/main/java/com/korad1004/back_end/my_travel_plan/controller/ScheduleController.java index 6134e76..2456fa9 100644 --- a/src/main/java/com/korad1004/back_end/my_travel_plan/controller/ScheduleController.java +++ b/src/main/java/com/korad1004/back_end/my_travel_plan/controller/ScheduleController.java @@ -2,12 +2,18 @@ import com.korad1004.back_end.my_travel_plan.dto.CreateCourseDto; import com.korad1004.back_end.my_travel_plan.service.ScheduleService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import lombok.AllArgsConstructor; +import java.net.URI; +import java.util.List; + @RestController @RequestMapping("/api/schedule") @AllArgsConstructor @@ -17,12 +23,20 @@ public class ScheduleController { //스케줄 만들기 @PostMapping - public void createSchedule(@RequestBody CreateCourseDto createCourseDto) throws Exception{ + public ResponseEntity createSchedule(@RequestBody CreateCourseDto createCourseDto) throws Exception{ try{ scheduleService.createSchedule(createCourseDto); } catch (Exception e) { throw new RuntimeException("암호 화가 안 됐어요 you know?",e); } + + return ResponseEntity.created(URI.create("/api/schedule")).build(); + } + + @GetMapping("/{travel_code}") + public ResponseEntity> getScheduleOfCode(@PathVariable(name="travel_code") String code){ + + return ResponseEntity.ok(scheduleService.getScheduleOfCode(code)); } } diff --git a/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetScheduleOfCode.java b/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetScheduleOfCode.java new file mode 100644 index 0000000..7c94899 --- /dev/null +++ b/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetScheduleOfCode.java @@ -0,0 +1,26 @@ +package com.korad1004.back_end.my_travel_plan.dto; + + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class GetScheduleOfCode { + + private String code; + + private String travelName; + + private Integer headCount; + + private String startDate; + + private String endDate; + + private Integer days; + + //number,[hotspot_image,hotspot_title,hotspot_address,hotspot_latitude,hotspot_longitude],memo +} diff --git a/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetSpotInfoOfMyTravel.java b/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetSpotInfoOfMyTravel.java new file mode 100644 index 0000000..4316857 --- /dev/null +++ b/src/main/java/com/korad1004/back_end/my_travel_plan/dto/GetSpotInfoOfMyTravel.java @@ -0,0 +1,25 @@ +package com.korad1004.back_end.my_travel_plan.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +//하나의 객체 +public class GetSpotInfoOfMyTravel { + + private Integer number; + + private String memo; + + private String image; + + private String title; + + private String address; + + private String latitude; + + private String longitude; + +} diff --git a/src/main/java/com/korad1004/back_end/my_travel_plan/entity/TourList.java b/src/main/java/com/korad1004/back_end/my_travel_plan/entity/TourList.java index 26609a0..9622e75 100644 --- a/src/main/java/com/korad1004/back_end/my_travel_plan/entity/TourList.java +++ b/src/main/java/com/korad1004/back_end/my_travel_plan/entity/TourList.java @@ -31,6 +31,4 @@ public class TourList { @JoinColumn(name = "schedule_code") private Schedule schedule; - - } diff --git a/src/main/java/com/korad1004/back_end/my_travel_plan/service/ScheduleService.java b/src/main/java/com/korad1004/back_end/my_travel_plan/service/ScheduleService.java index 4238650..ccceb7d 100644 --- a/src/main/java/com/korad1004/back_end/my_travel_plan/service/ScheduleService.java +++ b/src/main/java/com/korad1004/back_end/my_travel_plan/service/ScheduleService.java @@ -2,6 +2,8 @@ import com.korad1004.back_end.category.repository.HotspotRepository; import com.korad1004.back_end.my_travel_plan.dto.CreateCourseDto; +import com.korad1004.back_end.my_travel_plan.dto.GetScheduleOfCode; +import com.korad1004.back_end.my_travel_plan.dto.GetSpotInfoOfMyTravel; import com.korad1004.back_end.my_travel_plan.dto.TourListDto; import com.korad1004.back_end.my_travel_plan.entity.Schedule; import com.korad1004.back_end.my_travel_plan.entity.TourList; @@ -13,6 +15,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; @RestController @@ -76,6 +82,44 @@ public void createSchedule(CreateCourseDto createCourseDto) throws Exception { tourListRepository.save(tourList); } + } + + public List getScheduleOfCode(String code){ + + GetScheduleOfCode getScheduleOfCode = new GetScheduleOfCode(); + Optional optionalSchedule= scheduleRepository.findByCode(code); + Schedule schedule; + List getSpotInfoOfMyTravelList = new ArrayList<>(); + List objectList = new ArrayList<>(); + if(optionalSchedule.isPresent()){ + schedule = optionalSchedule.get(); + getScheduleOfCode.setCode(schedule.getCode()); + getScheduleOfCode.setTravelName(schedule.getTravelName()); + getScheduleOfCode.setHeadCount(schedule.getHeadCount()); + getScheduleOfCode.setStartDate(schedule.getStartDate()); + getScheduleOfCode.setEndDate(schedule.getEndDate()); + getScheduleOfCode.setDays(schedule.getDays()); + + objectList.add(getScheduleOfCode); + + for(TourList tourList:schedule.getTourLists()){ + + GetSpotInfoOfMyTravel getSpotInfoOfMyTravel = new GetSpotInfoOfMyTravel(); + + getSpotInfoOfMyTravel.setNumber(tourList.getNumber()); + getSpotInfoOfMyTravel.setMemo(tourList.getMemo()); + getSpotInfoOfMyTravel.setImage(tourList.getHotspot().getImage()); + getSpotInfoOfMyTravel.setTitle(tourList.getHotspot().getTitle()); + getSpotInfoOfMyTravel.setAddress(tourList.getHotspot().getAddress()); + getSpotInfoOfMyTravel.setLatitude(tourList.getHotspot().getLatitude()); + getSpotInfoOfMyTravel.setLongitude(tourList.getHotspot().getLongitude()); + + getSpotInfoOfMyTravelList.add(getSpotInfoOfMyTravel); + } + + objectList.add(getSpotInfoOfMyTravelList); + } + return objectList; } }