diff --git a/src/main/java/com/ALGo/ALGo_server/authentication/Dto/TokenResponseDto.java b/src/main/java/com/ALGo/ALGo_server/authentication/Dto/TokenResponseDto.java index 3d0c2ca..c0802cf 100644 --- a/src/main/java/com/ALGo/ALGo_server/authentication/Dto/TokenResponseDto.java +++ b/src/main/java/com/ALGo/ALGo_server/authentication/Dto/TokenResponseDto.java @@ -13,4 +13,5 @@ public class TokenResponseDto { private String grantType; private String jwtAccessToken; private String jwtRefreshToken; + private String language; } diff --git a/src/main/java/com/ALGo/ALGo_server/authentication/Jwt/JwtTokenProvider.java b/src/main/java/com/ALGo/ALGo_server/authentication/Jwt/JwtTokenProvider.java index 666b1f6..866acff 100644 --- a/src/main/java/com/ALGo/ALGo_server/authentication/Jwt/JwtTokenProvider.java +++ b/src/main/java/com/ALGo/ALGo_server/authentication/Jwt/JwtTokenProvider.java @@ -20,8 +20,8 @@ public class JwtTokenProvider { private static final String AUTHORITIES_KEY = "auth"; private static final String BEARER_TYPE = "BEARER"; - private final Long ACCESS_TOKEN_EXPIRE_TIME = 10000L * 60 * 60; - private final Long REFRESH_TOKEN_EXPIRE_TIME = 10000L * 60 * 60 * 24 * 7; + private final Long ACCESS_TOKEN_EXPIRE_TIME = 1000L * 60 * 60 * 24 * 3; + private final Long REFRESH_TOKEN_EXPIRE_TIME = 1000L * 60 * 60 * 24 * 7; private final CustomUserDetailsService customUserDetailsService; diff --git a/src/main/java/com/ALGo/ALGo_server/authentication/Service/UserService.java b/src/main/java/com/ALGo/ALGo_server/authentication/Service/UserService.java index e6378c2..ab49b9d 100644 --- a/src/main/java/com/ALGo/ALGo_server/authentication/Service/UserService.java +++ b/src/main/java/com/ALGo/ALGo_server/authentication/Service/UserService.java @@ -52,6 +52,7 @@ public TokenResponseDto login(LoginRequestDto requestDto){ return TokenResponseDto.builder() .grantType("Bearer") + .language(user.getLanguage()) .jwtAccessToken(accessToken) .jwtRefreshToken(refreshToken) .build(); diff --git a/src/main/java/com/ALGo/ALGo_server/config/SecurityConfig.java b/src/main/java/com/ALGo/ALGo_server/config/SecurityConfig.java index 57d37f1..cd4af11 100644 --- a/src/main/java/com/ALGo/ALGo_server/config/SecurityConfig.java +++ b/src/main/java/com/ALGo/ALGo_server/config/SecurityConfig.java @@ -65,6 +65,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.addAllowedOrigin("http://localhost:5173"); + configuration.addAllowedOrigin("https://alertglobal.vercel.app/"); configuration.addAllowedMethod("*"); configuration.addAllowedHeader("*"); configuration.setAllowCredentials(true); diff --git a/src/main/java/com/ALGo/ALGo_server/entity/Quiz.java b/src/main/java/com/ALGo/ALGo_server/entity/Quiz.java new file mode 100644 index 0000000..569e8d9 --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/entity/Quiz.java @@ -0,0 +1,25 @@ +package com.ALGo.ALGo_server.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +public class Quiz { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long quiz_id; + + @Column(nullable = false) + private String question; + + @Column(nullable = false) + private boolean answer; + + @Column(nullable = false) + private String description; + +} diff --git a/src/main/java/com/ALGo/ALGo_server/message/dto/MessageResponse.java b/src/main/java/com/ALGo/ALGo_server/message/dto/MessageResponse.java index 01cdd54..9636762 100644 --- a/src/main/java/com/ALGo/ALGo_server/message/dto/MessageResponse.java +++ b/src/main/java/com/ALGo/ALGo_server/message/dto/MessageResponse.java @@ -7,7 +7,6 @@ @Data public class MessageResponse { private String MSG_CN; //메세지 내용 - private String trans_MSG_CN; //번역된 내용 private String CREAT_DT; //생성일 private List RCV_AREA_ID; //수신지역 id private List RCV_AREA_NM; //수신지역명 @@ -15,6 +14,12 @@ public class MessageResponse { private String DSSTR_SE_ID; //재해구분 id private String DSSTR_SE_NM; //재해구분 명 + private String trans_MSG_CN; //문자 번역 + private String trans_AREA; //지역명 번역 + private String trnas_DSSTR; //재해구분명 번역 + + + public MessageResponse(String MSG_CN, String CREAT_DT, List RCV_AREA_ID, List RCV_AREA_NM, String EMRGNCY_STEP_ID, String DSSTR_SE_ID, String DSSTR_SE_NM){ this.MSG_CN = MSG_CN; //this.trans_MSG_CN = trans_MSG_CN; diff --git a/src/main/java/com/ALGo/ALGo_server/message/service/MessageService.java b/src/main/java/com/ALGo/ALGo_server/message/service/MessageService.java index effc3ab..800cf61 100644 --- a/src/main/java/com/ALGo/ALGo_server/message/service/MessageService.java +++ b/src/main/java/com/ALGo/ALGo_server/message/service/MessageService.java @@ -37,7 +37,7 @@ public MessageResponse message(User user) throws IOException, ParseException { urlBuilder.append("?serviceKey=" + secretKey); urlBuilder.append("&returnType=json"); urlBuilder.append("&pageNum=1"); - urlBuilder.append("&numRowsPerPage=10"); + urlBuilder.append("&numRowsPerPage=100"); URL url = new URL(urlBuilder.toString()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); @@ -132,8 +132,26 @@ public MessageResponse message(User user) throws IOException, ParseException { if(result != null){ String MSG_CN = result.getMSG_CN(); + String DSSTR = result.getDSSTR_SE_NM(); + + List areaArr = result.getRCV_AREA_NM(); + //문자 발송 지역 리스트 중 사용자 + String AREA = ""; + for (int i = 0; i < areaArr.size(); i++) { + if (combinedCity.equals(areaArr.get(i)) || city.equals(areaArr.get(i))) { + AREA = areaArr.get(i); + break; + } + } + String translatedMSG = naverTransService.getTransSentence(MSG_CN, user); + String translateDSSTR = naverTransService.getTransSentence(DSSTR, user); + String translateAREA = naverTransService.getTransSentence(AREA, user); + result.setTrans_MSG_CN(translatedMSG); + result.setTrnas_DSSTR(translateDSSTR); + result.setTrans_AREA(translateAREA); + } return result; diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Controller/QuizController.java b/src/main/java/com/ALGo/ALGo_server/quiz/Controller/QuizController.java new file mode 100644 index 0000000..729abb5 --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Controller/QuizController.java @@ -0,0 +1,21 @@ +package com.ALGo.ALGo_server.quiz.Controller; + +import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; +import com.ALGo.ALGo_server.quiz.Service.QuizService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/quiz") +@RequiredArgsConstructor +public class QuizController { + private final QuizService quizService; + + @GetMapping() + public QuizResponseDto getQuiz(){ + return quizService.getQuiz(); + } +} diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizDto.java b/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizDto.java new file mode 100644 index 0000000..b60158b --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizDto.java @@ -0,0 +1,15 @@ +package com.ALGo.ALGo_server.quiz.Dto; + +import com.ALGo.ALGo_server.entity.Quiz; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +public class QuizDto { + private Long id; + + public QuizDto(Quiz quiz){ + this.id = quiz.getQuiz_id(); + } +} diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.java b/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.java new file mode 100644 index 0000000..1fffd67 --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.java @@ -0,0 +1,14 @@ +package com.ALGo.ALGo_server.quiz.Dto; + +import lombok.Getter; + +import java.util.List; + +@Getter +public class QuizResponseDto { + List quizList; + + public QuizResponseDto(List quizList){ + this.quizList = quizList; + } +} diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java new file mode 100644 index 0000000..9595cfd --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java @@ -0,0 +1,34 @@ +package com.ALGo.ALGo_server.quiz.Service; + + +import com.ALGo.ALGo_server.entity.Quiz; +import com.ALGo.ALGo_server.quiz.Dto.QuizDto; +import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; +import com.ALGo.ALGo_server.repository.QuizRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +@Service +@RequiredArgsConstructor +public class QuizService { + private final QuizRepository quizRepository; + + @Transactional(readOnly = true) + public QuizResponseDto getQuiz(){ + Random random = new Random(); + + Set quizDtoList = new HashSet<>(); + while (quizDtoList.size() < 4){ + Long randomNum = Long.valueOf(random.nextInt(16) + 1); + Quiz q = quizRepository.findById(randomNum).get(); + QuizDto quizDto = new QuizDto(q); + quizDtoList.add(quizDto); + } + QuizResponseDto responseDto = new QuizResponseDto(quizDtoList.stream().toList()); + + return responseDto; + } +} diff --git a/src/main/java/com/ALGo/ALGo_server/repository/QuizRepository.java b/src/main/java/com/ALGo/ALGo_server/repository/QuizRepository.java new file mode 100644 index 0000000..2fdc03b --- /dev/null +++ b/src/main/java/com/ALGo/ALGo_server/repository/QuizRepository.java @@ -0,0 +1,8 @@ +package com.ALGo.ALGo_server.repository; + +import com.ALGo.ALGo_server.entity.Quiz; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +public interface QuizRepository extends JpaRepository { +}