Skip to content

Commit

Permalink
Merge pull request #35 from KORAD1004/feature/my-cource
Browse files Browse the repository at this point in the history
♻️Refactor: 나만의 일정 짜기 GET 요청
  • Loading branch information
Jindongleee authored Oct 6, 2024
2 parents 81854e8 + 4e530a8 commit c88884f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,12 +23,20 @@ public class ScheduleController {

//스케줄 만들기
@PostMapping
public void createSchedule(@RequestBody CreateCourseDto createCourseDto) throws Exception{
public ResponseEntity<Void> 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<List<Object>> getScheduleOfCode(@PathVariable(name="travel_code") String code){

return ResponseEntity.ok(scheduleService.getScheduleOfCode(code));
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ public class TourList {
@JoinColumn(name = "schedule_code")
private Schedule schedule;



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -76,6 +82,44 @@ public void createSchedule(CreateCourseDto createCourseDto) throws Exception {

tourListRepository.save(tourList);
}
}

public List<Object> getScheduleOfCode(String code){

GetScheduleOfCode getScheduleOfCode = new GetScheduleOfCode();
Optional<Schedule> optionalSchedule= scheduleRepository.findByCode(code);
Schedule schedule;
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());

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;
}
}

0 comments on commit c88884f

Please sign in to comment.