Skip to content

Commit

Permalink
Merge pull request GDSC-snowflowerthon#39 from ri-naa/feat/message-3
Browse files Browse the repository at this point in the history
[fix] 지역명, 재해구분명 번역 추가 GDSC-snowflowerthon#3
  • Loading branch information
ri-naa authored Jan 12, 2024
2 parents c014dcb + 6f9f065 commit 31db6b1
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class TokenResponseDto {
private String grantType;
private String jwtAccessToken;
private String jwtRefreshToken;
private String language;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public TokenResponseDto login(LoginRequestDto requestDto){

return TokenResponseDto.builder()
.grantType("Bearer")
.language(user.getLanguage())
.jwtAccessToken(accessToken)
.jwtRefreshToken(refreshToken)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/ALGo/ALGo_server/entity/Quiz.java
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
@Data
public class MessageResponse {
private String MSG_CN; //메세지 내용
private String trans_MSG_CN; //번역된 내용
private String CREAT_DT; //생성일
private List<String> RCV_AREA_ID; //수신지역 id
private List<String> RCV_AREA_NM; //수신지역명
private String EMRGNCY_STEP_ID; //긴급단계 id
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<String> RCV_AREA_ID, List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizDto.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ALGo.ALGo_server.quiz.Dto;

import lombok.Getter;

import java.util.List;

@Getter
public class QuizResponseDto {
List<QuizDto> quizList;

public QuizResponseDto(List<QuizDto> quizList){
this.quizList = quizList;
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java
Original file line number Diff line number Diff line change
@@ -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<QuizDto> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Quiz, Long> {
}

0 comments on commit 31db6b1

Please sign in to comment.