-
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.
Feat: Merge branch 'feat/disast_text'
- Loading branch information
Showing
8 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/com/numberone/backend/domain/disaster/controller/DisasterController.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,18 @@ | ||
package com.numberone.backend.domain.disaster.controller; | ||
|
||
import com.numberone.backend.domain.disaster.dto.request.LatestDisasterRequest; | ||
import com.numberone.backend.domain.disaster.dto.response.LatestDisasterResponse; | ||
import com.numberone.backend.domain.disaster.service.DisasterService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/disaster") | ||
public class DisasterController { | ||
private final DisasterService disasterService; | ||
@PostMapping("/latest") | ||
public LatestDisasterResponse getLatestDisaster(@RequestBody LatestDisasterRequest latestDisasterRequest){ | ||
return disasterService.getLatestDisaster(latestDisasterRequest); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/numberone/backend/domain/disaster/dto/request/LatestDisasterRequest.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,23 @@ | ||
package com.numberone.backend.domain.disaster.dto.request; | ||
|
||
import com.numberone.backend.domain.disaster.dto.response.LatestDisasterResponse; | ||
import com.numberone.backend.domain.disaster.entity.Disaster; | ||
import com.numberone.backend.domain.disaster.util.DisasterType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class LatestDisasterRequest { | ||
@Schema(defaultValue = "126.9723") | ||
@NotNull(message = "경도 정보는 null 일 수 없습니다.") | ||
private Double longitude; | ||
|
||
@Schema(defaultValue = "37.5559") | ||
@NotNull(message = "위도 정보는 null 일 수 없습니다.") | ||
private Double latitude; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/numberone/backend/domain/disaster/dto/response/LatestDisasterResponse.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,27 @@ | ||
package com.numberone.backend.domain.disaster.dto.response; | ||
|
||
import com.numberone.backend.domain.disaster.entity.Disaster; | ||
import com.numberone.backend.domain.disaster.util.DisasterType; | ||
import lombok.*; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Builder | ||
public class LatestDisasterResponse { | ||
private String disasterType; | ||
private Integer severity; | ||
private String title; | ||
private String msg; | ||
private String info; | ||
|
||
public static LatestDisasterResponse of(Disaster disaster) { | ||
return LatestDisasterResponse.builder() | ||
.disasterType(disaster.getDisasterType().getDescription()) | ||
.severity(disaster.getSeverity()) | ||
.title(disaster.getTitle()) | ||
.msg(disaster.getMsg()) | ||
.info(disaster.getInfo()) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/numberone/backend/domain/disaster/entity/Disaster.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,44 @@ | ||
package com.numberone.backend.domain.disaster.entity; | ||
|
||
import com.numberone.backend.domain.disaster.util.DisasterType; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Disaster { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private DisasterType disasterType; | ||
|
||
private Integer severity; | ||
|
||
private String title; | ||
|
||
private String msg; | ||
|
||
private String info; | ||
|
||
@Builder | ||
public Disaster(DisasterType disasterType, Integer severity, String title, String msg, String info) { | ||
this.disasterType = disasterType; | ||
this.severity = severity; | ||
this.title = title; | ||
this.msg = msg; | ||
this.info = info; | ||
} | ||
|
||
public static Disaster of(DisasterType disasterType, Integer severity, String title, String msg, String info) { | ||
return Disaster.builder() | ||
.disasterType(disasterType) | ||
.severity(severity) | ||
.title(title) | ||
.msg(msg) | ||
.info(info) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/numberone/backend/domain/disaster/service/DisasterService.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,25 @@ | ||
package com.numberone.backend.domain.disaster.service; | ||
|
||
import com.numberone.backend.domain.disaster.dto.request.LatestDisasterRequest; | ||
import com.numberone.backend.domain.disaster.dto.response.LatestDisasterResponse; | ||
import com.numberone.backend.domain.disaster.entity.Disaster; | ||
import com.numberone.backend.domain.disaster.util.DisasterType; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class DisasterService { | ||
public LatestDisasterResponse getLatestDisaster(LatestDisasterRequest latestDisasterRequest) { | ||
Disaster disaster = Disaster.of( | ||
DisasterType.kor2code("화재"), | ||
2, | ||
"서울특별시 강남구 동작동 화재 발생", | ||
"금일 10.23. 19:39경 소촌동 855 화재 발생, 인근주민은 안전유의 및 차량우회바랍니다. 960-8222", | ||
"서울특별시 강남구 ・ 오후 2시 46분" | ||
); | ||
return LatestDisasterResponse.of(disaster); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/numberone/backend/domain/disaster/util/DisasterType.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,65 @@ | ||
package com.numberone.backend.domain.disaster.util; | ||
|
||
import com.numberone.backend.exception.badrequest.InvalidDisasterTypeException; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum DisasterType { | ||
TYPHOON("태풍"), | ||
DRYNESS("건조"), | ||
WILDFIRE("산불"), | ||
LANDSLIDE("산사태"), | ||
FLOOD("홍수"), | ||
HEAVY_RAIN("호우"), | ||
HEATWAVE("폭염"), | ||
FOG("안개"), | ||
ROUGH_SEA("풍랑"), | ||
FINE_DUST("미세먼지"), | ||
TIDAL_WAVE("대조기"), | ||
DROUGHT("가뭄"), | ||
HEAVY_SNOWFALL("대설"), | ||
TSUNAMI("지진해일"), | ||
EARTHQUAKE("지진"), | ||
COLD_WAVE("한파"), | ||
YELLOW_DUST("황사"), | ||
STRONG_WIND("강풍"), | ||
TRAFFIC_CONTROL("교통통제"), | ||
FIRE("화재"), | ||
COLLAPSE("붕괴"), | ||
EXPLOSION("폭발"), | ||
TRAFFIC_ACCIDENT("교통사고"), | ||
ENVIRONMENTAL_POLLUTION("환경오염사고"), | ||
ENERGY("에너지"), | ||
COMMUNICATION("통신"), | ||
TRAFFIC("교통"), | ||
FINANCE("금융"), | ||
MEDICAL("의료"), | ||
WATER_SUPPLY("수도"), | ||
INFECTIOUS_DISEASE("전염병"), | ||
POWER_OUTAGE("정전"), | ||
GAS("가스"), | ||
AI("AI"), | ||
CHEMICAL("화생방사고"), | ||
RIOT("폭동"), | ||
TERROR("테러"), | ||
EMERGENCY("비상사태"), | ||
CIVIL_DEFENSE("민방공"), | ||
OTHERS("기타"); | ||
|
||
private final String description; | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public static DisasterType kor2code(String kor) { | ||
for (DisasterType type : DisasterType.values()) { | ||
if (type.getDescription().equals(kor)) { | ||
return type; | ||
} | ||
} | ||
throw new InvalidDisasterTypeException(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/numberone/backend/exception/badrequest/InvalidDisasterTypeException.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,9 @@ | ||
package com.numberone.backend.exception.badrequest; | ||
|
||
import static com.numberone.backend.exception.context.CustomExceptionContext.INVALID_DISASTER_TYPE; | ||
|
||
public class InvalidDisasterTypeException extends BadRequestException { | ||
public InvalidDisasterTypeException() { | ||
super(INVALID_DISASTER_TYPE); | ||
} | ||
} |
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