From 7a84714b6ee148684c9edd527aad72be3dc15699 Mon Sep 17 00:00:00 2001 From: Jindongleee Date: Mon, 7 Oct 2024 22:55:50 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FRefactor:=20=EB=82=98?= =?UTF-8?q?=EB=A7=8C=EC=9D=98=20=EC=9D=BC=EC=A0=95=20=EC=A7=9C=EA=B8=B0=20?= =?UTF-8?q?=EB=B0=8F=20URL=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back_end/category/entity/Hotspot.java | 5 +++- .../category/service/HotspotService.java | 1 + .../back_end/course/dto/CourseInfoDto.java | 19 +++++++------ .../back_end/course/entity/CoursePlace.java | 3 ++ .../course/service/CoursePlaceService.java | 11 +++----- .../controller/ScheduleController.java | 2 +- .../my_travel_plan/dto/GetScheduleOfCode.java | 14 ++++++++++ .../dto/GetSpotInfoOfMyTravel.java | 17 +++++++++++ .../service/ScheduleService.java | 28 ++++++------------- 9 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/korad1004/back_end/category/entity/Hotspot.java b/src/main/java/com/korad1004/back_end/category/entity/Hotspot.java index 715a9bc..a8c2df8 100644 --- a/src/main/java/com/korad1004/back_end/category/entity/Hotspot.java +++ b/src/main/java/com/korad1004/back_end/category/entity/Hotspot.java @@ -42,10 +42,13 @@ public class Hotspot { @Column private String longitude; - //장소 URL (도메인 주소) @Column private String subTitle; + //장소 URL (도메인 주소) + @Column + private String spotURL; + //카테고리 별 장소 지정 @ManyToOne @JoinColumn(name="category_category_name") diff --git a/src/main/java/com/korad1004/back_end/category/service/HotspotService.java b/src/main/java/com/korad1004/back_end/category/service/HotspotService.java index 2190259..ab6a726 100644 --- a/src/main/java/com/korad1004/back_end/category/service/HotspotService.java +++ b/src/main/java/com/korad1004/back_end/category/service/HotspotService.java @@ -67,6 +67,7 @@ public void createHotspots(){ hotspot.setLatitude(arr[5]); hotspot.setLongitude(arr[6]); hotspot.setSubTitle(arr[7]); + hotspot.setSpotURL(arr[8]); optionalCategory.ifPresent(hotspot::setCategory); hotspotRepository.save(hotspot); } diff --git a/src/main/java/com/korad1004/back_end/course/dto/CourseInfoDto.java b/src/main/java/com/korad1004/back_end/course/dto/CourseInfoDto.java index 7faf3e0..7c9b850 100644 --- a/src/main/java/com/korad1004/back_end/course/dto/CourseInfoDto.java +++ b/src/main/java/com/korad1004/back_end/course/dto/CourseInfoDto.java @@ -1,6 +1,6 @@ package com.korad1004.back_end.course.dto; -import com.korad1004.back_end.course.entity.CoursePlace; +import com.korad1004.back_end.category.entity.Hotspot; import lombok.Getter; import lombok.Setter; @@ -21,19 +21,22 @@ public class CourseInfoDto { private String longitude; + private String spotURL; + private String category; - public static CourseInfoDto from(CoursePlace coursePlace){ + public static CourseInfoDto from(Hotspot hotspot){ CourseInfoDto courseInfoDto=new CourseInfoDto(); - courseInfoDto.setNumber(courseInfoDto.getNumber()); - courseInfoDto.setImage(courseInfoDto.getImage()); - courseInfoDto.setTitle(courseInfoDto.getTitle()); - courseInfoDto.setAddress(courseInfoDto.getAddress()); - courseInfoDto.setLatitude(courseInfoDto.getLatitude()); - courseInfoDto.setLongitude(courseInfoDto.getLongitude()); + courseInfoDto.setImage(hotspot.getImage()); + courseInfoDto.setTitle(hotspot.getTitle()); + courseInfoDto.setAddress(hotspot.getAddress()); + courseInfoDto.setLatitude(hotspot.getLatitude()); + courseInfoDto.setLongitude(hotspot.getLongitude()); + courseInfoDto.setSpotURL(hotspot.getSpotURL()); + courseInfoDto.setCategory(hotspot.getCategory().getCategoryName()); return courseInfoDto; diff --git a/src/main/java/com/korad1004/back_end/course/entity/CoursePlace.java b/src/main/java/com/korad1004/back_end/course/entity/CoursePlace.java index ece9e51..980774c 100644 --- a/src/main/java/com/korad1004/back_end/course/entity/CoursePlace.java +++ b/src/main/java/com/korad1004/back_end/course/entity/CoursePlace.java @@ -39,6 +39,9 @@ public class CoursePlace { @Column private String longitude; + @Column + private String spotURL; + @ManyToOne @JoinColumn(name = "course_course_id") private Course course; diff --git a/src/main/java/com/korad1004/back_end/course/service/CoursePlaceService.java b/src/main/java/com/korad1004/back_end/course/service/CoursePlaceService.java index 8f902e2..10d3869 100644 --- a/src/main/java/com/korad1004/back_end/course/service/CoursePlaceService.java +++ b/src/main/java/com/korad1004/back_end/course/service/CoursePlaceService.java @@ -58,21 +58,18 @@ public List getCoursePlace(Long id){ // List coursePlaceList = coursePlaceRepository.findByCourse(optionalCourse.get()); + CourseInfoDto courseInfoDto; for(CoursePlace coursePlace:coursePlaceList) { - CourseInfoDto courseInfoDto=new CourseInfoDto(); Optional optionalHotspot= hotspotRepository.findById(coursePlace.getHotspot().getId()); if(optionalHotspot.isPresent()) { Hotspot hotspot=optionalHotspot.get(); + courseInfoDto=CourseInfoDto.from(hotspot); + courseInfoDto.setNumber(coursePlace.getNumber()); - courseInfoDto.setTitle(hotspot.getTitle()); - courseInfoDto.setAddress(hotspot.getAddress()); - courseInfoDto.setImage(hotspot.getImage()); - courseInfoDto.setLatitude(hotspot.getLatitude()); - courseInfoDto.setLongitude(hotspot.getLongitude()); - courseInfoDto.setCategory(hotspot.getCategory().getCategoryName()); + courseInfoDtoList.add(courseInfoDto); } } 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 837d386..99ded57 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 @@ -35,7 +35,7 @@ public ResponseEntity createSchedule(@RequestBody CreateCourseDto create @GetMapping("/{travel_code}") public ResponseEntity> getScheduleOfCode(@PathVariable(name="travel_code") String code){ - return ResponseEntity.ok(scheduleService.getScheduleOfCode("#"+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 index e177921..e09d7f3 100644 --- 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 @@ -1,6 +1,7 @@ package com.korad1004.back_end.my_travel_plan.dto; +import com.korad1004.back_end.my_travel_plan.entity.Schedule; import lombok.Getter; import lombok.Setter; @@ -23,4 +24,17 @@ public class GetScheduleOfCode { 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(); + getScheduleOfCode.setCode(schedule.getCode()); + getScheduleOfCode.setTravelName(schedule.getTravelName()); + getScheduleOfCode.setHeadCount(schedule.getHeadCount()); + getScheduleOfCode.setStartDate(schedule.getStartDate()); + getScheduleOfCode.setEndDate(schedule.getEndDate()); + getScheduleOfCode.setDays(schedule.getDays()); + + return getScheduleOfCode; + } } 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 index 4316857..df1acec 100644 --- 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 @@ -1,5 +1,6 @@ package com.korad1004.back_end.my_travel_plan.dto; +import com.korad1004.back_end.my_travel_plan.entity.TourList; import lombok.Getter; import lombok.Setter; @@ -22,4 +23,20 @@ public class GetSpotInfoOfMyTravel { private String longitude; + private String spotURL; + + public static GetSpotInfoOfMyTravel from(TourList tourList){ + 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()); + getSpotInfoOfMyTravel.setSpotURL(tourList.getHotspot().getSpotURL()); + + return getSpotInfoOfMyTravel; + } + } 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 cfb234a..f5d0acd 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 @@ -13,8 +13,6 @@ import lombok.Getter; import lombok.Setter; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import java.time.LocalDateTime; @@ -42,7 +40,7 @@ public String createSchedule(CreateCourseDto createCourseDto) throws Exception { while(true){ SecretKey secretKey = KeyGenerator.getInstance(localDateTimeNumericEncryption.getALGORITHM()).generateKey(); LocalDateTime code = LocalDateTime.now(); - numericEncryptedDateTime = new StringBuilder("#").append(localDateTimeNumericEncryption.encryptToSixDigits(code, secretKey)); + numericEncryptedDateTime = new StringBuilder(localDateTimeNumericEncryption.encryptToSixDigits(code, secretKey)); if(scheduleRepository.findByCode(String.valueOf(numericEncryptedDateTime)).isEmpty()) break; @@ -79,7 +77,7 @@ public String createSchedule(CreateCourseDto createCourseDto) throws Exception { //메모 저장 tourList.setMemo(tourListDto.getMemo()); - //해당 스케줄 id 받아오기 + //해당 스케줄 code 받아오기 if(scheduleRepository.findByCode(schedule.getCode()).isPresent()) tourList.setSchedule(scheduleRepository.findByCode(schedule.getCode()).get()); @@ -90,35 +88,25 @@ public String createSchedule(CreateCourseDto createCourseDto) throws Exception { } + //해당 코드에 대한 스케줄 받아오기 public List getScheduleOfCode(String code){ - GetScheduleOfCode getScheduleOfCode = new GetScheduleOfCode(); + GetScheduleOfCode getScheduleOfCode; Optional optionalSchedule= scheduleRepository.findByCode(code); Schedule schedule; + GetSpotInfoOfMyTravel getSpotInfoOfMyTravel; 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()); + + getScheduleOfCode=GetScheduleOfCode.from(schedule); 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()); + getSpotInfoOfMyTravel=GetSpotInfoOfMyTravel.from(tourList); getSpotInfoOfMyTravelList.add(getSpotInfoOfMyTravel); }