Skip to content

Commit

Permalink
Feat: Merge branch 'feat/disast_text'
Browse files Browse the repository at this point in the history
  • Loading branch information
nohy6630 committed Nov 3, 2023
2 parents f8cf976 + b9f74d7 commit e20488c
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 1 deletion.
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);
}
}
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;
}
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();
}
}
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();
}
}
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);
}
}
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();
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public enum CustomExceptionContext implements ExceptionContext {

// S3 관련 예외
S3_FILE_UPLOAD_FAILED("S3 파일 업로드에 실패했습니다.", 4000),
S3_MULTIPART_MISSING("Multipart 파일이 null 이거나 없습니다.", 4001)
S3_MULTIPART_MISSING("Multipart 파일이 null 이거나 없습니다.", 4001),

// DISASTER 관련 예외
INVALID_DISASTER_TYPE("존재하지 않는 대피소 유형입니다.",5000)
;


Expand Down

0 comments on commit e20488c

Please sign in to comment.