Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.onebridge.ouch.controller.language;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.onebridge.ouch.apiPayload.ApiResponse;
import com.onebridge.ouch.service.language.LanguageService;
import com.onebridge.ouch.dto.language.response.GetLanguageResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@Tag(name = "언어 관련 API", description = "언어 관련 API 입니다.")
@RestController
@RequestMapping("/languages")
@RequiredArgsConstructor
public class LanguageController {

private final LanguageService languageService;

@Operation(summary = "언어 목록 조회 API", description = "데이터베이스 내 모든 언어 목록을 조회합니다.")
@GetMapping
public ResponseEntity<ApiResponse<List<GetLanguageResponse>>> getAllLanguages() {
List<GetLanguageResponse> languages = languageService.getAllLanguages();
return ResponseEntity.ok(ApiResponse.success(languages));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.onebridge.ouch.controller.nation;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.onebridge.ouch.apiPayload.ApiResponse;
import com.onebridge.ouch.dto.nation.response.GetNationResponse;
import com.onebridge.ouch.service.nation.NationService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@Tag(name = "국적 관련 API", description = "국적 관련 API 입니다.")
@RestController
@RequestMapping("/nations")
@RequiredArgsConstructor
public class NationController {

private final NationService nationService;

@Operation(summary = "국가 목록 조회 API", description = "데이터베이스 내 모든 국가 목록을 조회합니다.")
@GetMapping
public ResponseEntity<ApiResponse<List<GetNationResponse>>> getAllNations() {
List<GetNationResponse> nations = nationService.getAllNations();
return ResponseEntity.ok(ApiResponse.success(nations));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package com.onebridge.ouch.controller.user;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.onebridge.ouch.apiPayload.ApiResponse;
import com.onebridge.ouch.dto.language.response.GetLanguageResponse;
import com.onebridge.ouch.dto.nation.response.GetNationResponse;
import com.onebridge.ouch.dto.user.response.UserInfoResponse;
import com.onebridge.ouch.security.authorization.UserId;
import com.onebridge.ouch.service.user.UserService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@Tag(name = "사용자 관련 API", description = "사용자 관련 API 입니다.")
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
Expand All @@ -35,22 +44,34 @@ public ResponseEntity<ApiResponse<Void>> deactivateUser(
userService.deactivateUser(userId);
return ResponseEntity.ok(ApiResponse.successWithNoData());
}
}















@Operation(summary = "유저 언어 설정 변경 API", description = "언어코드를 전달받아 유저의 언어 설정을 변경합니다.")
@PatchMapping("/languages/{languageCode}")
public ResponseEntity<ApiResponse<Void>> updateUserLanguage(@UserId Long userId, @PathVariable("languageCode") String languageCode) {
userService.updateUserLanguage(userId, languageCode);
return ResponseEntity.ok(ApiResponse.successWithNoData());
}

@Operation(summary = "유저 설정 언어 조회 API", description = "로그인 된 유저의 설정된 언어를 조회합니다.")
@GetMapping("/languages")
public ResponseEntity<ApiResponse<GetLanguageResponse>> getUserLanguage(@UserId Long userId) {
userService.getUserLanguage(userId);
GetLanguageResponse languageResponse = userService.getUserLanguage(userId);
return ResponseEntity.ok(ApiResponse.success(languageResponse));
}

@Operation(summary = "유저 국적 설정 변경 API", description = "국가코드를 전달받아 유저의 국적 설정을 변경합니다.")
@PatchMapping("/nations/{nationCode}")
public ResponseEntity<ApiResponse<Void>> updateUserNation(@UserId Long userId, @PathVariable("nationCode") String nationCode) {
userService.updateUserNation(userId, nationCode);
return ResponseEntity.ok(ApiResponse.successWithNoData());
}

@Operation(summary = "유저 설정 국적 조회 API", description = "로그인 된 유저의 설정된 국적를 조회합니다.")
@GetMapping("/nations")
public ResponseEntity<ApiResponse<GetNationResponse>> getUserNation(@UserId Long userId) {
userService.getUserNation(userId);
GetNationResponse nationResponse = userService.getUserNation(userId);
return ResponseEntity.ok(ApiResponse.success(nationResponse));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/onebridge/ouch/domain/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class Language extends BaseEntity {
private Long id;

//국제 언어 코드
@Column(nullable = false, length = 4)
@Column(unique = true, nullable = false, length = 4)
private String code;

//언어 이름 - ex) 한국어, 영어
@Column(nullable = false, length = 30)
@Column(unique = true, nullable = false, length = 30)
private String name;
}
4 changes: 2 additions & 2 deletions src/main/java/com/onebridge/ouch/domain/Nation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class Nation extends BaseEntity {
private Long id;

// 국가 코드
@Column(nullable = false, length = 4)
@Column(unique = true, nullable = false, length = 4)
private String code;

@Column(nullable = false, length = 30)
@Column(unique = true, nullable = false, length = 30)
private String name;
}
8 changes: 8 additions & 0 deletions src/main/java/com/onebridge/ouch/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,12 @@ public class User extends BaseEntity {
public OuchAuthority getAuthority() {
return OuchAuthority.INDIVIDUAL;
}

public void updateLanguage(Language language) {
this.language = language;
}

public void updateNation(Nation nation) {
this.nation = nation;
}
}
11 changes: 0 additions & 11 deletions src/main/java/com/onebridge/ouch/dto/MessageResponse.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/com/onebridge/ouch/dto/MessageResponseDetailed.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.onebridge.ouch.dto.language.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class UserLangResponse {

private Long language_id;

private String language_name;
}
package com.onebridge.ouch.dto.language.response;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class GetLanguageResponse {
private String name;
private String code; // 언어 코드 (e.g., 'en', 'ko')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.onebridge.ouch.dto.nation.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class GetNationResponse {

private String name;

private String code;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.onebridge.ouch.repository.language;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.onebridge.ouch.domain.Language;

@Repository
public interface LanguageRepository extends JpaRepository<Language, Long> {
Optional<Language> findByCode(String code);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.onebridge.ouch.repository.nation;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import com.onebridge.ouch.domain.Language;
import com.onebridge.ouch.domain.Nation;

public interface NationRepository extends JpaRepository<Nation, Long> {
Optional<Nation> findByCode(String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Optional;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -12,4 +13,10 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByLoginId(String loginId);

Optional<User> findByNickname(String nickName);

@EntityGraph(attributePaths = {"language"}) // language 필드를 즉시 조인 (fetch join 쿼리 최적화)
Optional<User> findWithLanguageById(Long id);

@EntityGraph(attributePaths = {"nation"}) // language 필드를 즉시 조인 (fetch join 쿼리 최적화)
Optional<User> findWithNationById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.onebridge.ouch.domain.enums.Gender;
import com.onebridge.ouch.domain.enums.UserStatus;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -25,8 +26,10 @@ public class SignUpRequest {
private String email;
private String address;
private UserStatus status;
private Long languageId;
private Long nationId;
@Schema(example = "kr")
private String languageCode;
@Schema(example = "KO")
private String nationCode;

public User toEntity(String encodedPassword, Language language, Nation nation) {
return User.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public void signUpUser(SignUpRequest signUpRequest) {
checkDuplicatedNickname(signUpRequest.getNickname());

// ID를 통해 실제 Entity 조회
Language language = languageRepository.findById(signUpRequest.getLanguageId())
Language language = languageRepository.findByCode(signUpRequest.getLanguageCode())
.orElseThrow(() -> new OuchException(CommonErrorCode.LANGUAGE_NOT_FOUND));

Nation nation = nationRepository.findById(signUpRequest.getNationId())
Nation nation = nationRepository.findByCode(signUpRequest.getNationCode())
.orElseThrow(() -> new OuchException(CommonErrorCode.NATION_NOT_FOUND));

User user = signUpRequest.toEntity(passwordEncoder.encode(signUpRequest.getPassword()), language, nation);
Expand Down
Loading