Skip to content

Commit

Permalink
Merge pull request #25 from KORAD1004/feature/my-cource
Browse files Browse the repository at this point in the history
♻️Refactor: 코스 검색시 무한 GET 요청 보내기 (Id,Title,Address)
  • Loading branch information
Jindongleee authored Oct 4, 2024
2 parents 20c1576 + 9009eef commit fe513ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.korad1004.back_end.category.controller;


import com.korad1004.back_end.category.dto.GetAllHotspotInfo;
import com.korad1004.back_end.category.dto.HotspotInfoDto;
import com.korad1004.back_end.category.service.HotspotService;
import org.springframework.http.HttpStatus;
Expand All @@ -11,6 +12,8 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.List;

@RestController
Expand Down Expand Up @@ -45,9 +48,20 @@ public ResponseEntity<List<HotspotInfoDto>> getHotspotOfCategory(@PathVariable(n
return ResponseEntity.notFound().build();
}

//무한 GET요청 모든 HOTSPOT 넘겨주기
@GetMapping
public ResponseEntity<List<GetAllHotspotInfo>> getAllHotspot(){

return ResponseEntity.ok(hotspotService.getAllHotspot());

}

//CSV 데이터 넣기
@PostMapping("/all-place-insert")
public void createHotspotCategory() {
public ResponseEntity<Void> createHotspotCategory() {
hotspotService.createHotspots();

return ResponseEntity.created(URI.create("/all-place-insert")).build();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.korad1004.back_end.category.service;


import com.korad1004.back_end.category.dto.GetAllHotspotInfo;
import com.opencsv.CSVReader;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -29,6 +30,7 @@ public HotspotService(HotspotRepository hotspotRepository, CategoryRepository ca
this.categoryRepository = categoryRepository;
}

//가볼 만한 곳 넣기
public void createHotspotInfo(HotspotInfoDto hotspotInfoDto,String category){

Hotspot hotspot=new Hotspot();
Expand All @@ -48,10 +50,10 @@ public void createHotspotInfo(HotspotInfoDto hotspotInfoDto,String category){
hotspotRepository.save(hotspot);
}

//csv 데이터 넣기 (가볼만한 곳)
public void createHotspots(){


try(CSVReader reader = new CSVReader(new FileReader("/home/ubuntu/nuclear_server/data.csv"))){
try(CSVReader reader = new CSVReader(new FileReader("/Users/eddy/Desktop/data.csv"))){
reader.readNext();
String[] arr;
while((arr=reader.readNext())!=null){
Expand All @@ -74,6 +76,7 @@ public void createHotspots(){
}
}

//원하는 카테고리에 대한 정보 리스트업
public List<HotspotInfoDto> getHotspotList(String category){

List<HotspotInfoDto> hotspotInfoDtoList =new ArrayList<>();
Expand Down Expand Up @@ -104,8 +107,28 @@ public List<HotspotInfoDto> getHotspotList(String category){

}


return null;
}

//모든 장소 리스트업
public List<GetAllHotspotInfo> getAllHotspot(){

List<Hotspot> hotspotList =hotspotRepository.findAll();
List<GetAllHotspotInfo> getAllHotspotInfoList = new ArrayList<>();

for(Hotspot hotspot:hotspotList){
GetAllHotspotInfo getAllHotspotInfo = new GetAllHotspotInfo();

getAllHotspotInfo.setId(hotspot.getId());
getAllHotspotInfo.setTitle(hotspot.getTitle());
getAllHotspotInfo.setAddress(hotspot.getAddress());

getAllHotspotInfoList.add(getAllHotspotInfo);
}

return getAllHotspotInfoList;


}

}

0 comments on commit fe513ee

Please sign in to comment.