Skip to content

Commit

Permalink
Merge pull request #29 from ri-naa/feat/message-3
Browse files Browse the repository at this point in the history
[fix] 재난문자 번역 수정 #3
  • Loading branch information
ri-naa authored Jan 11, 2024
2 parents 9d85906 + 9522abc commit c014dcb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.authorizeRequests()
.requestMatchers("/disaster/**").authenticated()
.requestMatchers("/setting/**").authenticated()
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() //prefilght request 허용
.anyRequest().permitAll();

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/ALGo/ALGo_server/entity/User.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ALGo.ALGo_server.entity;

import com.ALGo.ALGo_server.mypage.Dto.ChangeInfoRequestDto;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -32,6 +33,13 @@ public class User implements UserDetails {
@Enumerated(EnumType.STRING)
private Role role;

public void updateInfo(ChangeInfoRequestDto requestDto){
this.language = requestDto.getLanguage();
this.city = requestDto.getCity();
this.gu = requestDto.getGu();
}


public void encodePassword(PasswordEncoder passwordEncoder){
this.password = passwordEncoder.encode(password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class MessageResponse {
private String DSSTR_SE_ID; //재해구분 id
private String DSSTR_SE_NM; //재해구분 명

public MessageResponse(String MSG_CN, String trans_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){
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;
//this.trans_MSG_CN = trans_MSG_CN;
this.CREAT_DT = CREAT_DT;
this.RCV_AREA_ID = RCV_AREA_ID;
this.RCV_AREA_NM = RCV_AREA_NM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public MessageResponse message(User user) throws IOException, ParseException {
String a = areaNmArr.get(j);
}

String translatedMSG = naverTransService.getTransSentence(MSG_CN, user);
MessageResponse response = new MessageResponse(MSG_CN, translatedMSG, CREAT_DT, areaIdArr, areaNmArr, EMRGNCY_STEP_ID, DSSTR_SE_ID, DSSTR_SE_NM);
//String translatedMSG = naverTransService.getTransSentence(MSG_CN, user);
MessageResponse response = new MessageResponse(MSG_CN, CREAT_DT, areaIdArr, areaNmArr, EMRGNCY_STEP_ID, DSSTR_SE_ID, DSSTR_SE_NM);

msgResArr.add(response);
}
Expand All @@ -107,7 +107,6 @@ public MessageResponse message(User user) throws IOException, ParseException {
String combinedCity = city + gu;

MessageResponse result = null;

// 지역 찾기
for (int i=0; i<msgResArr.size(); i++) {

Expand All @@ -128,6 +127,15 @@ public MessageResponse message(User user) throws IOException, ParseException {
}

}

//String translatedMSG = naverTransService.getTransSentence(MSG_CN, user);

if(result != null){
String MSG_CN = result.getMSG_CN();
String translatedMSG = naverTransService.getTransSentence(MSG_CN, user);
result.setTrans_MSG_CN(translatedMSG);
}

return result;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ALGo.ALGo_server.mypage.Controller;

import com.ALGo.ALGo_server.entity.User;
import com.ALGo.ALGo_server.mypage.Dto.ChangeInfoRequestDto;
import com.ALGo.ALGo_server.mypage.Dto.MyInfoResponseDto;
import com.ALGo.ALGo_server.mypage.Service.MyPageService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/setting")
public class MyPageController {
private final MyPageService myPageService;

@GetMapping()
public MyInfoResponseDto getMyInfo(@AuthenticationPrincipal User user){
return myPageService.getMyInfo(user);
}

@PutMapping("/change")
public ResponseEntity changeInfo(@AuthenticationPrincipal User user, @RequestBody ChangeInfoRequestDto requestDto){
return myPageService.changeInfo(user, requestDto);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ALGo.ALGo_server.mypage.Dto;

import lombok.Getter;

@Getter
public class ChangeInfoRequestDto {
private String language;
private String city;
private String gu;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ALGo.ALGo_server.mypage.Dto;

import com.ALGo.ALGo_server.entity.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class MyInfoResponseDto {
private String email;
private String language;
private String city;
private String gu;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ALGo.ALGo_server.mypage.Service;

import com.ALGo.ALGo_server.entity.User;
import com.ALGo.ALGo_server.mypage.Dto.ChangeInfoRequestDto;
import com.ALGo.ALGo_server.mypage.Dto.MyInfoResponseDto;
import com.ALGo.ALGo_server.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;

@Service
@RequiredArgsConstructor
public class MyPageService {
private final UserRepository userRepository;

@Transactional(readOnly = true)
public MyInfoResponseDto getMyInfo(User user){
MyInfoResponseDto responseDto = MyInfoResponseDto.builder()
.email(user.getEmail())
.language(user.getLanguage())
.city(user.getCity())
.gu(user.getGu())
.build();
return responseDto;
}

@Transactional
public ResponseEntity changeInfo(User user, ChangeInfoRequestDto requestDto){
user.updateInfo(requestDto);
userRepository.save(user);
return new ResponseEntity(HttpStatus.OK);
}
}

0 comments on commit c014dcb

Please sign in to comment.