Skip to content

Commit

Permalink
Merge pull request #24 from RumosZin/feat/#22
Browse files Browse the repository at this point in the history
[feat] 주 언어, 보조 언어 입력 API 구현
  • Loading branch information
RumosZin authored Feb 17, 2024
2 parents 2e142b0 + ad4a2e2 commit 5003da7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
3 changes: 2 additions & 1 deletion BE/src/main/java/com/FTIsland/BE/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected SecurityFilterChain configure(HttpSecurity http) throws Exception {
new AntPathRequestMatcher("/book/info"),
new AntPathRequestMatcher("/saveBookContent"),
new AntPathRequestMatcher("/book/content"),
new AntPathRequestMatcher("/book/quiz")
new AntPathRequestMatcher("/book/quiz"),
new AntPathRequestMatcher("/language")
).permitAll()
//.requestMatchers(new AntPathRequestMatcher("/api/v1/**")).hasRole(Role.USER.name())
.anyRequest().authenticated())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.FTIsland.BE.controller;

import com.FTIsland.BE.dto.UserLanguageDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.FTIsland.BE.service.UserService;

@Slf4j
@RestController
@RequiredArgsConstructor
public class LanguageController {

private final UserService userService;

@PostMapping("/language")
public UserLanguageDTO saveUserLanguage(@RequestBody UserLanguageDTO userLanguageDTO){ // DB에 동화 정보 저장
return userService.save(userLanguageDTO);
}
}
23 changes: 23 additions & 0 deletions BE/src/main/java/com/FTIsland/BE/dto/UserLanguageDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.FTIsland.BE.dto;

import com.FTIsland.BE.entity.User;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@NoArgsConstructor
@ToString
public class UserLanguageDTO {
private Long userId;
private String mainLanguage;
private String subLanguage;

public UserLanguageDTO(Long userId, String mainLanguage, String subLanguage) {
this.userId = userId;
this.mainLanguage = mainLanguage;
this.subLanguage = subLanguage;
}
}
1 change: 1 addition & 0 deletions BE/src/main/java/com/FTIsland/BE/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.FTIsland.BE.repository;
import com.FTIsland.BE.dto.UserLanguageDTO;
import com.FTIsland.BE.entity.SocialType;
import com.FTIsland.BE.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -24,4 +25,5 @@ public interface UserRepository extends JpaRepository<User, Long> {
* 따라서 추가 정보를 입력받아 회원 가입을 진행할 때 소셜 타입, 식별자로 해당 회원을 찾기 위한 메소드
*/
Optional<User> findBySocialTypeAndSocialId(SocialType socialType, String socialId);

}
11 changes: 10 additions & 1 deletion BE/src/main/java/com/FTIsland/BE/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.FTIsland.BE.dto.BookInfoDTO;
import com.FTIsland.BE.dto.QuizDTO;
import com.FTIsland.BE.dto.UserLanguageDTO;
import com.FTIsland.BE.dto.UserSignUpDTO;
import com.FTIsland.BE.entity.Role;
import com.FTIsland.BE.entity.User;
Expand Down Expand Up @@ -30,7 +31,7 @@ public void signUp(UserSignUpDTO userSignUpDto) throws Exception {
throw new Exception("이미 존재하는 이름입니다.");
}

User user = User.builder()
User user = User.builder() // 자체 로그인에서는 mainLanguage, subLanguage를 입력하니까 바로 USER로 등록함
.email(userSignUpDto.getEmail())
.password(userSignUpDto.getPassword())
.name(userSignUpDto.getName())
Expand All @@ -55,4 +56,12 @@ public Integer findLevelById(Long userId){
}
}

public UserLanguageDTO save(UserLanguageDTO userLanguageDTO) {
// 넘어온 userId, mainLanguage, subLanguage로 userDB에 저장하기
User user = userRepository.findById(userLanguageDTO.getUserId()).get();
user.setMainLanguage(userLanguageDTO.getMainLanguage());
user.setSubLanguage(userLanguageDTO.getSubLanguage());
userRepository.save(user);
return userLanguageDTO;
}
}

0 comments on commit 5003da7

Please sign in to comment.