Skip to content

Commit

Permalink
Merge pull request #39 from KORAD1004/feature/my-cource
Browse files Browse the repository at this point in the history
♻️Refactor: 나만의 일정 짜기 및 URL 추가
  • Loading branch information
Jindongleee authored Oct 7, 2024
2 parents d3a6fba + 7a84714 commit 8214800
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/korad1004/back_end/course/dto/CourseInfoDto.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class CoursePlace {
@Column
private String longitude;

@Column
private String spotURL;

@ManyToOne
@JoinColumn(name = "course_course_id")
private Course course;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,18 @@ public List<CourseInfoDto> getCoursePlace(Long id){
//
List<CoursePlace> coursePlaceList = coursePlaceRepository.findByCourse(optionalCourse.get());

CourseInfoDto courseInfoDto;
for(CoursePlace coursePlace:coursePlaceList) {

CourseInfoDto courseInfoDto=new CourseInfoDto();
Optional<Hotspot> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ResponseEntity<String> createSchedule(@RequestBody CreateCourseDto create
@GetMapping("/{travel_code}")
public ResponseEntity<List<Object>> getScheduleOfCode(@PathVariable(name="travel_code") String code){

return ResponseEntity.ok(scheduleService.getScheduleOfCode("#"+code));
return ResponseEntity.ok(scheduleService.getScheduleOfCode(code));
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -90,35 +88,25 @@ public String createSchedule(CreateCourseDto createCourseDto) throws Exception {

}

//해당 코드에 대한 스케줄 받아오기
public List<Object> getScheduleOfCode(String code){

GetScheduleOfCode getScheduleOfCode = new GetScheduleOfCode();
GetScheduleOfCode getScheduleOfCode;
Optional<Schedule> optionalSchedule= scheduleRepository.findByCode(code);
Schedule schedule;
GetSpotInfoOfMyTravel getSpotInfoOfMyTravel;
List<GetSpotInfoOfMyTravel> getSpotInfoOfMyTravelList = new ArrayList<>();
List<Object> 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);
}
Expand Down

0 comments on commit 8214800

Please sign in to comment.