diff --git a/src/main/java/com/example/goorm/oreum/BirtyDayRequest.java b/src/main/java/com/example/goorm/oreum/BirtyDayRequest.java index 82ddf6e..653ab5f 100644 --- a/src/main/java/com/example/goorm/oreum/BirtyDayRequest.java +++ b/src/main/java/com/example/goorm/oreum/BirtyDayRequest.java @@ -1,2 +1,15 @@ -package com.example.goorm.oreum;public class BirtyDayRequest { +package com.example.goorm.oreum; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BirtyDayRequest { + private int month; + private int day; } diff --git a/src/main/java/com/example/goorm/oreum/EnumMapperType.java b/src/main/java/com/example/goorm/oreum/EnumMapperType.java index 9d80543..67c7269 100644 --- a/src/main/java/com/example/goorm/oreum/EnumMapperType.java +++ b/src/main/java/com/example/goorm/oreum/EnumMapperType.java @@ -1,2 +1,9 @@ -package com.example.goorm.oreum;public class EnumMapperType { -} +package com.example.goorm.oreum; + +public interface EnumMapperType { + // 해당 Enum의 이름을 조회하는 변수 + String getCode(); + + // 해당 Enum의 설명을 조회하는 변수 + String getTitle(); +} \ No newline at end of file diff --git a/src/main/java/com/example/goorm/oreum/MyOreum.java b/src/main/java/com/example/goorm/oreum/MyOreum.java index b12aadb..c2af468 100644 --- a/src/main/java/com/example/goorm/oreum/MyOreum.java +++ b/src/main/java/com/example/goorm/oreum/MyOreum.java @@ -1,2 +1,25 @@ -package com.example.goorm.oreum;public class MyOreum { +package com.example.goorm.oreum; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MyOreum { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private Long oreumId; } diff --git a/src/main/java/com/example/goorm/oreum/Oreum.java b/src/main/java/com/example/goorm/oreum/Oreum.java index 5b49110..69c41d9 100644 --- a/src/main/java/com/example/goorm/oreum/Oreum.java +++ b/src/main/java/com/example/goorm/oreum/Oreum.java @@ -10,6 +10,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import java.time.LocalDateTime; +import java.util.Arrays; @Entity @Getter @@ -20,12 +21,21 @@ public class Oreum { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private String name; - private String type; + private OreumType type; private Double xPos; private Double yPos; private Double zPos; - private LocalDateTime birthDate; + private int month; + private int day; + + // 랜덤 색상값 추가해줘야 함 + public void toTypeEnum(String type) { + this.type = Arrays.stream(OreumType.values()) + .filter(o1 -> o1.getTitle().equals(type)) + .findFirst() + .get(); + } } + diff --git a/src/main/java/com/example/goorm/oreum/OreumController.java b/src/main/java/com/example/goorm/oreum/OreumController.java index 5c4fa00..eadc5ce 100644 --- a/src/main/java/com/example/goorm/oreum/OreumController.java +++ b/src/main/java/com/example/goorm/oreum/OreumController.java @@ -4,6 +4,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @@ -13,16 +16,21 @@ public class OreumController { private final OreumService oreumService; - private final OreumRepository oreumRepository; - @GetMapping("/") + @GetMapping("/oreums") + public ResponseEntity> getData(){ + return ResponseEntity.ok().body(oreumService.getOreums()); + } + + @PostMapping("/oreums") public ResponseEntity pushData(){ oreumService.readCsv(); return ResponseEntity.ok().body("완성"); } + // 생일에 따른 오름 정보 보여주기 @GetMapping("/oreum") - public ResponseEntity> getData(){ - return ResponseEntity.ok().body(oreumService.getOreums()); + public ResponseEntity getOreum(@RequestBody BirtyDayRequest request){ + return ResponseEntity.ok().body(oreumService.getOreum(request)); } } diff --git a/src/main/java/com/example/goorm/oreum/OreumRepository.java b/src/main/java/com/example/goorm/oreum/OreumRepository.java index 1be4e5b..4343f01 100644 --- a/src/main/java/com/example/goorm/oreum/OreumRepository.java +++ b/src/main/java/com/example/goorm/oreum/OreumRepository.java @@ -1,6 +1,9 @@ package com.example.goorm.oreum; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface OreumRepository extends JpaRepository { + @Query("select o from Oreum o where o.month=:month and o.day=:day") + Oreum findByBirthday(int month, int day); } diff --git a/src/main/java/com/example/goorm/oreum/OreumService.java b/src/main/java/com/example/goorm/oreum/OreumService.java index e1d58be..cdef7fb 100644 --- a/src/main/java/com/example/goorm/oreum/OreumService.java +++ b/src/main/java/com/example/goorm/oreum/OreumService.java @@ -4,6 +4,9 @@ import org.springframework.stereotype.Service; import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; @Service @@ -14,6 +17,12 @@ public List getOreums(){ return oreumRepository.findAll(); } + public Oreum getOreum(BirtyDayRequest request){ + int month = request.getMonth(); + int day = request.getDay(); + return oreumRepository.findByBirthday(month, day); + } + public void readCsv(){ File csv = new File("C:\\Users\\Windows10\\Desktop\\오름.txt"); BufferedReader br = null; @@ -21,27 +30,47 @@ public void readCsv(){ try { br = new BufferedReader(new FileReader(csv)); - while((line = br.readLine()) != null){ + int monthCheck = 1; + int dayCheck = 1; + + int cnt =0 ; + while((line = br.readLine()) != null) { + System.out.println(cnt++); 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); + String type = lineArr[1].split("/")[1]; + String pos = lineArr[2]; 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) + .month(monthCheck) + .day(dayCheck) .build(); + oreum.toTypeEnum(type); oreumRepository.save(oreum); + if((monthCheck == 1 || monthCheck == 3 || monthCheck == 5 || monthCheck == 7 + || monthCheck == 8 || monthCheck == 10 || monthCheck ==12) && dayCheck == 31) { + monthCheck++; + dayCheck = 0; + } + else if(monthCheck == 2 && dayCheck == 29){ + monthCheck++; + dayCheck = 0; + } + else if((monthCheck == 4 || monthCheck == 6 || monthCheck ==9 || monthCheck == 11) && dayCheck == 30){ + monthCheck++; + dayCheck = 0; + } + dayCheck++; } - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { + + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/example/goorm/oreum/OreumType.java b/src/main/java/com/example/goorm/oreum/OreumType.java index 4b40056..3a9893f 100644 --- a/src/main/java/com/example/goorm/oreum/OreumType.java +++ b/src/main/java/com/example/goorm/oreum/OreumType.java @@ -1,2 +1,26 @@ -package com.example.goorm.oreum;public enum OreumType { +package com.example.goorm.oreum; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum OreumType implements EnumMapperType{ + HORSESHOE("말굽"), + CONE("원추"), + CIRCLE("원형"), + COMPLEX("복합"); + + @Getter + private final String status; + + @Override + public String getCode() { + return name(); + } + + @Override + public String getTitle() { + return status; + } }