Skip to content

Commit

Permalink
feat: 오름 데이터 푸시 및 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-EunJu committed Nov 17, 2022
1 parent a71d47a commit 9b75a79
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.example.goorm.oreum;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -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;
}
28 changes: 28 additions & 0 deletions src/main/java/com/example/goorm/oreum/OreumController.java
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());
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/example/goorm/oreum/OreumRepository.java
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> {
}
48 changes: 48 additions & 0 deletions src/main/java/com/example/goorm/oreum/OreumService.java
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);
}
}
}

0 comments on commit 9b75a79

Please sign in to comment.