Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
83602b3
feat: 프로필 Repository 6개 추가 (#39)
p1001q Jul 24, 2026
a2c3f0d
feat: 프로필 에러 코드 4개 추가 (#39)
p1001q Jul 24, 2026
04ffe98
feat: PIANO 악기 시드 데이터 추가 (#39)
p1001q Jul 24, 2026
e99d1f1
feat: 프로필 조회 API 구현 (#39)
p1001q Jul 24, 2026
fe98864
feat: 프로필 최초 등록 API 구현 (#39)
p1001q Jul 24, 2026
5d3a2c1
feat: 프로필 수정 API 구현 (#39)
p1001q Jul 24, 2026
e8c44c1
test: 프로필 API 컨트롤러 테스트 추가 (#39)
p1001q Jul 24, 2026
4a8642a
fix: 프로필 조회 시 활성 구독만 조회하도록 수정 (#39)
p1001q Jul 24, 2026
73b8684
fix: 시드 동시 실행 시 중복 저장 안전 처리 (#39)
p1001q Jul 24, 2026
da3f6d2
fix: 닉네임 중복 검사를 엔티티 변경 전으로 이동 (#39)
p1001q Jul 24, 2026
8403213
fix: 온보딩 동시 요청 시 중복 생성 방지 (#39)
p1001q Jul 24, 2026
8fdd0e3
fix: 구독등급 타입을 String으로 통일하고 값 검증 추가 (#39)
p1001q Jul 24, 2026
3eca142
fix: IllegalStateException을 GeneralException으로 교체 (#39)
p1001q Jul 24, 2026
e445c83
fix: 시드 실행에서 트랜잭션 오염 문제 해결 (#39)
p1001q Jul 24, 2026
825a92c
fix: 시드 실행에서 트랜잭션 오염 문제 해결 (#39)
p1001q Jul 24, 2026
32daad5
fix: 시드 중복키 외 무결성 오류는 그대로 전파 (#39)
p1001q Jul 24, 2026
da5c092
fix: 구독등급 검증 순서 및 Student 저장 방식 개선 (#39)
p1001q Jul 24, 2026
a61f637
docs: 프로필 API 스웨거 설명 추가 (#39)
p1001q Jul 24, 2026
47c6fbf
Merge remote-tracking branch 'origin/develop' into feat/#39-user-prof…
p1001q Jul 25, 2026
ef97044
fix: 닉네임 trim을 한 곳에서 처리하도록 정리 (#39)
p1001q Jul 25, 2026
67ba529
refactor: DTO를 req/res 패키지로 분리 (#39)
p1001q Jul 25, 2026
600940b
fix: 온보딩 구독 등급을 요청값 대신 서버에서 PRO로 고정 (#39)
p1001q Jul 26, 2026
ad9a833
fix: 닉네임/온보딩 동시성 예외를 SQLState로 구분해 처리 (#39)
p1001q Jul 26, 2026
f824f11
refactor: 동시성 예외 판별 분기를 긍정문으로 정리 (#39)
p1001q Jul 26, 2026
7c17409
feat: completedLearningCount를 실제 집계값으로 연동 (#39)
p1001q Jul 26, 2026
9a53f66
fix: 프로필 수정 API를 부분 수정 방식으로 변경 (#39)
p1001q Jul 26, 2026
7d8ab2f
Merge branch 'develop' into feat/#39-user-profile-api
p1001q Jul 26, 2026
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,10 @@
package com.mr.domain.statistics.repository;

import com.mr.domain.statistics.entity.UserStatistics;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserStatisticsRepository extends JpaRepository<UserStatistics, Long> {

Optional<UserStatistics> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mr.domain.subscriptions.entity.enums;

public enum SubscriptionTier {
FREE,
STANDARD,
PRO
}
Comment thread
p1001q marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mr.domain.subscriptions.repository;

import com.mr.domain.subscriptions.entity.Subscription;
import com.mr.domain.user.entity.User;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SubscriptionRepository extends JpaRepository<Subscription, Long> {

Optional<Subscription> findFirstByUserOrderByStartDateDesc(User user);
Comment thread
p1001q marked this conversation as resolved.
Resolved
}
26 changes: 26 additions & 0 deletions src/main/java/com/mr/domain/user/config/InstrumentSeeder.java
Comment thread
p1001q marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mr.domain.user.config;

import com.mr.domain.user.entity.Instrument;
import com.mr.domain.user.repository.InstrumentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
public class InstrumentSeeder implements ApplicationRunner {

private static final String PIANO_CODE = "PIANO";
private static final String PIANO_NAME = "피아노";

private final InstrumentRepository instrumentRepository;

@Override
@Transactional
public void run(ApplicationArguments args) {
instrumentRepository.findByCode(PIANO_CODE)
.orElseGet(() -> instrumentRepository.save(Instrument.create(PIANO_CODE, PIANO_NAME)));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mr.domain.user.controller;

import com.mr.domain.user.dto.UserProfileRequestDTO;
import com.mr.domain.user.dto.UserProfileResponseDTO;
import com.mr.domain.user.service.UserProfileService;
import com.mr.global.apipayload.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/users/me/profile")
public class UserProfileController {

private final UserProfileService userProfileService;

@GetMapping
public ApiResponse<UserProfileResponseDTO.ProfileResponse> getMyProfile() {
return ApiResponse.onSuccess(userProfileService.getMyProfile());
}

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ApiResponse<UserProfileResponseDTO.OnboardingResponse> registerProfile(
@RequestBody UserProfileRequestDTO.OnboardingRequest request
Comment thread
p1001q marked this conversation as resolved.
Resolved
) {
return ApiResponse.onSuccess(userProfileService.registerProfile(request));
}

@PatchMapping
public ApiResponse<UserProfileResponseDTO.UpdateResponse> updateProfile(
@RequestBody UserProfileRequestDTO.UpdateRequest request
) {
return ApiResponse.onSuccess(userProfileService.updateProfile(request));
}
}
Comment thread
p1001q marked this conversation as resolved.
Resolved
18 changes: 18 additions & 0 deletions src/main/java/com/mr/domain/user/dto/UserProfileRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mr.domain.user.dto;

import com.mr.domain.subscriptions.entity.enums.SubscriptionTier;
import com.mr.domain.user.entity.enums.TheoryLevel;

public class UserProfileRequestDTO {

public record OnboardingRequest(
String nickname,
TheoryLevel skillLevel,
SubscriptionTier subscriptionTier
) {}

public record UpdateRequest(
String nickname,
TheoryLevel skillLevel
) {}
}
43 changes: 43 additions & 0 deletions src/main/java/com/mr/domain/user/dto/UserProfileResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mr.domain.user.dto;

import com.mr.domain.user.entity.enums.TheoryLevel;
import java.time.LocalDateTime;
import lombok.Builder;

public class UserProfileResponseDTO {

@Builder
public record ProfileResponse(
String nickname,
String profileImgUrl,
String instrumentType,
TheoryLevel skillLevel,
String subscriptionTier,
StatisticsResponse statistics
) {}

@Builder
public record StatisticsResponse(
Long practiceSessionCount,
Long totalPracticeMinutes,
Long completedLearningCount
) {}

@Builder
public record OnboardingResponse(
Long userId,
String nickname,
TheoryLevel skillLevel,
String instrumentType,
String subscriptionTier,
String profileImgUrl
) {}

@Builder
public record UpdateResponse(
Long userId,
String nickname,
TheoryLevel skillLevel,
LocalDateTime updatedAt
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public enum StudentErrorStatus implements BaseCode {

USER_REQUIRED(HttpStatus.BAD_REQUEST, "STUDENT_400_01", "user는 필수입니다."),
THEORY_LEVEL_REQUIRED(HttpStatus.BAD_REQUEST, "STUDENT_400_02", "theoryLevel은 필수입니다.");
THEORY_LEVEL_REQUIRED(HttpStatus.BAD_REQUEST, "STUDENT_400_02", "theoryLevel은 필수입니다."),
STUDENT_NOT_FOUND(HttpStatus.NOT_FOUND, "STUDENT_404_01", "온보딩 정보가 없는 사용자입니다.");

private final HttpStatus status;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public enum UserErrorStatus implements BaseCode {

NICKNAME_REQUIRED(HttpStatus.BAD_REQUEST, "USER_400_01", "닉네임은 필수입니다."),
NICKNAME_INVALID_FORMAT(HttpStatus.BAD_REQUEST, "USER_400_02", "닉네임은 한글, 영어, 숫자 2~10자로 입력해야 합니다."),
PROFILE_IMAGE_REQUIRED(HttpStatus.BAD_REQUEST, "USER_400_03", "프로필 이미지 URL은 필수입니다.");
PROFILE_IMAGE_REQUIRED(HttpStatus.BAD_REQUEST, "USER_400_03", "프로필 이미지 URL은 필수입니다."),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER_404_01", "존재하지 않는 사용자입니다."),
NICKNAME_DUPLICATED(HttpStatus.CONFLICT, "USER_409_01", "이미 사용 중인 닉네임입니다."),
ONBOARDING_ALREADY_COMPLETED(HttpStatus.CONFLICT, "USER_409_02", "이미 온보딩을 완료한 사용자입니다.");

private final HttpStatus status;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mr.domain.user.repository;

import com.mr.domain.user.entity.Instrument;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface InstrumentRepository extends JpaRepository<Instrument, Long> {

Optional<Instrument> findByCode(String code);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mr.domain.user.repository;

import com.mr.domain.user.entity.Student;
import com.mr.domain.user.entity.StudentInstrument;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StudentInstrumentRepository extends JpaRepository<StudentInstrument, Long> {

Optional<StudentInstrument> findByStudentAndPrimaryTrue(Student student);
}
11 changes: 11 additions & 0 deletions src/main/java/com/mr/domain/user/repository/StudentRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mr.domain.user.repository;

import com.mr.domain.user.entity.Student;
import com.mr.domain.user.entity.User;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StudentRepository extends JpaRepository<Student, Long> {

Optional<Student> findByUser(User user);
}
11 changes: 11 additions & 0 deletions src/main/java/com/mr/domain/user/repository/UserRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mr.domain.user.repository;

import com.mr.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

// NOTE: feat/#32-learning-status-api(PR #46, 동균 강)에도 동일한 이름의 빈 UserRepository가 있음.
// 그쪽이 먼저 머지되면 병합 시 이 파일(메서드 포함된 상위호환 버전)로 유지하면 됨.
Comment thread
p1001q marked this conversation as resolved.
Resolved
public interface UserRepository extends JpaRepository<User, Long> {

boolean existsByNicknameAndUserIdNot(String nickname, Long userId);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
148 changes: 148 additions & 0 deletions src/main/java/com/mr/domain/user/service/UserProfileService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.mr.domain.user.service;

import com.mr.domain.subscriptions.entity.Subscription;
import com.mr.domain.subscriptions.repository.SubscriptionRepository;
import com.mr.domain.statistics.entity.UserStatistics;
import com.mr.domain.statistics.repository.UserStatisticsRepository;
import com.mr.domain.user.dto.UserProfileRequestDTO;
import com.mr.domain.user.dto.UserProfileResponseDTO;
import com.mr.domain.user.entity.Instrument;
import com.mr.domain.user.entity.Student;
import com.mr.domain.user.entity.StudentInstrument;
import com.mr.domain.user.entity.User;
import com.mr.domain.user.exception.StudentErrorStatus;
import com.mr.domain.user.exception.UserErrorStatus;
import com.mr.domain.user.repository.InstrumentRepository;
import com.mr.domain.user.repository.StudentInstrumentRepository;
import com.mr.domain.user.repository.StudentRepository;
import com.mr.domain.user.repository.UserRepository;
import com.mr.global.apipayload.exception.GeneralException;
import com.mr.global.security.SecurityUtil;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserProfileService {

private static final String PIANO_CODE = "PIANO";
private static final int SUBSCRIPTION_PERIOD_DAYS = 30;

private final UserRepository userRepository;
private final StudentRepository studentRepository;
private final StudentInstrumentRepository studentInstrumentRepository;
private final InstrumentRepository instrumentRepository;
private final SubscriptionRepository subscriptionRepository;
private final UserStatisticsRepository userStatisticsRepository;

public UserProfileResponseDTO.ProfileResponse getMyProfile() {
Long userId = SecurityUtil.getCurrentUserId();
User user = getUser(userId);
Student student = getStudent(user);

String instrumentType = studentInstrumentRepository.findByStudentAndPrimaryTrue(student)
.map(StudentInstrument::getInstrument)
.map(Instrument::getCode)
.orElseThrow(() -> new IllegalStateException("대표 악기 정보가 존재하지 않습니다."));

String subscriptionTier = subscriptionRepository.findFirstByUserOrderByStartDateDesc(user)
.map(Subscription::getTier)
.orElseThrow(() -> new IllegalStateException("구독 정보가 존재하지 않습니다."));
Comment thread
p1001q marked this conversation as resolved.
Resolved

return UserProfileResponseDTO.ProfileResponse.builder()
.nickname(user.getNickname())
.profileImgUrl(user.getProfileImgUrl())
.instrumentType(instrumentType)
.skillLevel(student.getTheoryLevel())
.subscriptionTier(subscriptionTier)
.statistics(buildStatistics(userId))
.build();
}

@Transactional
public UserProfileResponseDTO.OnboardingResponse registerProfile(UserProfileRequestDTO.OnboardingRequest request) {
Long userId = SecurityUtil.getCurrentUserId();
User user = getUser(userId);

if (user.isOnboardingCompleted()) {
throw new GeneralException(UserErrorStatus.ONBOARDING_ALREADY_COMPLETED);
}

user.updateNickname(request.nickname());
ensureNicknameNotTaken(user);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Student student = studentRepository.save(Student.create(user, request.skillLevel()));

Instrument piano = instrumentRepository.findByCode(PIANO_CODE)
.orElseThrow(() -> new IllegalStateException("PIANO 악기 시드 데이터가 존재하지 않습니다."));
studentInstrumentRepository.save(StudentInstrument.createPrimary(student, piano));

String tier = request.subscriptionTier() == null ? null : request.subscriptionTier().name();
LocalDateTime now = LocalDateTime.now();
Subscription subscription = subscriptionRepository.save(
Subscription.create(user, tier, now, now.plusDays(SUBSCRIPTION_PERIOD_DAYS)));
Comment thread
p1001q marked this conversation as resolved.
Resolved

return UserProfileResponseDTO.OnboardingResponse.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.skillLevel(student.getTheoryLevel())
.instrumentType(piano.getCode())
.subscriptionTier(subscription.getTier())
.profileImgUrl(user.getProfileImgUrl())
.build();
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

@Transactional
public UserProfileResponseDTO.UpdateResponse updateProfile(UserProfileRequestDTO.UpdateRequest request) {
Long userId = SecurityUtil.getCurrentUserId();
User user = getUser(userId);
Student student = getStudent(user);

user.updateNickname(request.nickname());
ensureNicknameNotTaken(user);
student.updateTheoryLevel(request.skillLevel());

return UserProfileResponseDTO.UpdateResponse.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.skillLevel(student.getTheoryLevel())
.updatedAt(LocalDateTime.now())
.build();
}

private User getUser(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new GeneralException(UserErrorStatus.USER_NOT_FOUND));
}

private Student getStudent(User user) {
return studentRepository.findByUser(user)
.orElseThrow(() -> new GeneralException(StudentErrorStatus.STUDENT_NOT_FOUND));
}

private void ensureNicknameNotTaken(User user) {
if (userRepository.existsByNicknameAndUserIdNot(user.getNickname(), user.getUserId())) {
throw new GeneralException(UserErrorStatus.NICKNAME_DUPLICATED);
}
}
Comment thread
p1001q marked this conversation as resolved.
Resolved

private UserProfileResponseDTO.StatisticsResponse buildStatistics(Long userId) {
UserStatistics stats = userStatisticsRepository.findByUserId(userId).orElse(null);

return UserProfileResponseDTO.StatisticsResponse.builder()
.practiceSessionCount(stats == null ? 0L : stats.getTotalPracticeCount().longValue())
.totalPracticeMinutes(stats == null ? 0L : stats.getTotalPracticeMinutes().longValue())
.completedLearningCount(countCompletedLearnings(userId))
.build();
}

// TODO: feat/#32-learning-status-api(동균 강) 병합 후 UserLearningProgressRepository로 교체
// SELECT COUNT(DISTINCT ulp.learning_id) FROM user_learning_progress ulp
// WHERE ulp.user_id = :userId AND ulp.score >= 90
private Long countCompletedLearnings(Long userId) {
return 0L;
}
Comment thread
p1001q marked this conversation as resolved.
Resolved
}
Loading
Loading