Skip to content

Commit

Permalink
add: 오름별 날짜 매핑 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-EunJu committed Nov 17, 2022
1 parent 75779e5 commit 72ac8ea
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 20 deletions.
15 changes: 14 additions & 1 deletion src/main/java/com/example/goorm/oreum/BirtyDayRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 9 additions & 2 deletions src/main/java/com/example/goorm/oreum/EnumMapperType.java
Original file line number Diff line number Diff line change
@@ -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();
}
25 changes: 24 additions & 1 deletion src/main/java/com/example/goorm/oreum/MyOreum.java
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 13 additions & 3 deletions src/main/java/com/example/goorm/oreum/Oreum.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;
import java.util.Arrays;

@Entity
@Getter
Expand All @@ -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();
}

}

16 changes: 12 additions & 4 deletions src/main/java/com/example/goorm/oreum/OreumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,16 +16,21 @@
public class OreumController {

private final OreumService oreumService;
private final OreumRepository oreumRepository;

@GetMapping("/")
@GetMapping("/oreums")
public ResponseEntity<List<Oreum>> getData(){
return ResponseEntity.ok().body(oreumService.getOreums());
}

@PostMapping("/oreums")
public ResponseEntity<String> pushData(){
oreumService.readCsv();
return ResponseEntity.ok().body("완성");
}

// 생일에 따른 오름 정보 보여주기
@GetMapping("/oreum")
public ResponseEntity<List<Oreum>> getData(){
return ResponseEntity.ok().body(oreumService.getOreums());
public ResponseEntity<Oreum> getOreum(@RequestBody BirtyDayRequest request){
return ResponseEntity.ok().body(oreumService.getOreum(request));
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/goorm/oreum/OreumRepository.java
Original file line number Diff line number Diff line change
@@ -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<Oreum, Long> {
@Query("select o from Oreum o where o.month=:month and o.day=:day")
Oreum findByBirthday(int month, int day);
}
45 changes: 37 additions & 8 deletions src/main/java/com/example/goorm/oreum/OreumService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,34 +17,60 @@ public List<Oreum> 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;
String line = "";

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);
}
}
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/example/goorm/oreum/OreumType.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 72ac8ea

Please sign in to comment.