diff --git a/src/main/java/com/korad1004/back_end/category/controller/HotspotController.java b/src/main/java/com/korad1004/back_end/category/controller/HotspotController.java index fec4e22..8c4c331 100644 --- a/src/main/java/com/korad1004/back_end/category/controller/HotspotController.java +++ b/src/main/java/com/korad1004/back_end/category/controller/HotspotController.java @@ -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; @@ -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 @@ -45,9 +48,20 @@ public ResponseEntity> getHotspotOfCategory(@PathVariable(n return ResponseEntity.notFound().build(); } + //무한 GET요청 모든 HOTSPOT 넘겨주기 + @GetMapping + public ResponseEntity> getAllHotspot(){ + + return ResponseEntity.ok(hotspotService.getAllHotspot()); + + } + + //CSV 데이터 넣기 @PostMapping("/all-place-insert") - public void createHotspotCategory() { + public ResponseEntity createHotspotCategory() { hotspotService.createHotspots(); + + return ResponseEntity.created(URI.create("/all-place-insert")).build(); } } 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 58da31f..a0a93d9 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 @@ -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; @@ -29,6 +30,7 @@ public HotspotService(HotspotRepository hotspotRepository, CategoryRepository ca this.categoryRepository = categoryRepository; } + //가볼 만한 곳 넣기 public void createHotspotInfo(HotspotInfoDto hotspotInfoDto,String category){ Hotspot hotspot=new Hotspot(); @@ -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){ @@ -74,6 +76,7 @@ public void createHotspots(){ } } + //원하는 카테고리에 대한 정보 리스트업 public List getHotspotList(String category){ List hotspotInfoDtoList =new ArrayList<>(); @@ -104,8 +107,28 @@ public List getHotspotList(String category){ } - return null; } + //모든 장소 리스트업 + public List getAllHotspot(){ + + List hotspotList =hotspotRepository.findAll(); + List 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; + + + } + }