diff --git a/src/main/java/Oreum.java b/src/main/java/com/example/goorm/oreum/Oreum.java similarity index 75% rename from src/main/java/Oreum.java rename to src/main/java/com/example/goorm/oreum/Oreum.java index 3b633b5..5b49110 100644 --- a/src/main/java/Oreum.java +++ b/src/main/java/com/example/goorm/oreum/Oreum.java @@ -1,3 +1,5 @@ +package com.example.goorm.oreum; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -19,7 +21,11 @@ public class Oreum { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + private String name; + private String type; + private Double xPos; + private Double yPos; + private Double zPos; private LocalDateTime birthDate; - private String oreumType; } diff --git a/src/main/java/com/example/goorm/oreum/OreumController.java b/src/main/java/com/example/goorm/oreum/OreumController.java new file mode 100644 index 0000000..5c4fa00 --- /dev/null +++ b/src/main/java/com/example/goorm/oreum/OreumController.java @@ -0,0 +1,28 @@ +package com.example.goorm.oreum; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + + +@Controller +@RequiredArgsConstructor +public class OreumController { + + private final OreumService oreumService; + private final OreumRepository oreumRepository; + + @GetMapping("/") + public ResponseEntity pushData(){ + oreumService.readCsv(); + return ResponseEntity.ok().body("완성"); + } + + @GetMapping("/oreum") + public ResponseEntity> getData(){ + return ResponseEntity.ok().body(oreumService.getOreums()); + } +} diff --git a/src/main/java/com/example/goorm/oreum/OreumRepository.java b/src/main/java/com/example/goorm/oreum/OreumRepository.java new file mode 100644 index 0000000..1be4e5b --- /dev/null +++ b/src/main/java/com/example/goorm/oreum/OreumRepository.java @@ -0,0 +1,6 @@ +package com.example.goorm.oreum; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OreumRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/goorm/oreum/OreumService.java b/src/main/java/com/example/goorm/oreum/OreumService.java new file mode 100644 index 0000000..e1d58be --- /dev/null +++ b/src/main/java/com/example/goorm/oreum/OreumService.java @@ -0,0 +1,48 @@ +package com.example.goorm.oreum; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.io.*; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class OreumService { + private final OreumRepository oreumRepository; + public List getOreums(){ + return oreumRepository.findAll(); + } + + public void readCsv(){ + File csv = new File("C:\\Users\\Windows10\\Desktop\\오름.txt"); + BufferedReader br = null; + String line = ""; + + try { + br = new BufferedReader(new FileReader(csv)); + while((line = br.readLine()) != null){ + String[] lineArr = line.split(","); + String name = lineArr[0]; + String type = lineArr[1].substring(1, lineArr[1].length()-1).split("/")[1]; + String pos = lineArr[2].substring(1, lineArr[2].length()-1); + Double x = Double.parseDouble(pos.split(" ")[0]); + Double y = Double.parseDouble(pos.split(" ")[1]); + Double z = Double.parseDouble(pos.split(" ")[2]); + System.out.println(name+" "+type+" "+x+" "+y+" "+z); + Oreum oreum = Oreum.builder() + .name(name) + .type(type) + .xPos(x) + .yPos(y) + .zPos(z) + .build(); + oreumRepository.save(oreum); + } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +}