forked from 9oorm-Oreum/9oorm-Oreum-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a71d47a
commit 9b75a79
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/goorm/oreum/OreumController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> pushData(){ | ||
oreumService.readCsv(); | ||
return ResponseEntity.ok().body("완성"); | ||
} | ||
|
||
@GetMapping("/oreum") | ||
public ResponseEntity<List<Oreum>> getData(){ | ||
return ResponseEntity.ok().body(oreumService.getOreums()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.goorm.oreum; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface OreumRepository extends JpaRepository<Oreum, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Oreum> 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); | ||
} | ||
} | ||
} |