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
Expand Up @@ -4,8 +4,10 @@
import com.example.hackathon.domain.user.dto.request.UserCreateRequest;
import com.example.hackathon.domain.user.dto.request.ActiveTeamRequest;
import com.example.hackathon.domain.user.dto.request.UserEmailRequest;
import com.example.hackathon.domain.user.dto.request.UserNotificationRequest;
import com.example.hackathon.domain.user.dto.response.UserCreateResponse;
import com.example.hackathon.domain.user.dto.response.UserHomeResponse;
import com.example.hackathon.domain.user.dto.response.UserResponse;
import com.example.hackathon.domain.user.service.UserService;

import com.example.hackathon.global.response.ApiResponse;
Expand Down Expand Up @@ -82,4 +84,21 @@ public ResponseEntity<ApiResponse<UserHomeResponse>> getHomeData(
UserHomeResponse response = userService.getHomeData(userId);
return ResponseEntity.ok(ApiResponse.ok("홈 화면 데이터 조회 성공", response));
}

// 8. 유저 정보 조회 (GET -> 알림 설정 화면 진입 시 이용)
@GetMapping("/{userId}")
public ResponseEntity<ApiResponse<UserResponse>> getUser(@PathVariable Long userId) {
UserResponse response = userService.getUser(userId);
return ResponseEntity.ok(ApiResponse.ok("유저 정보 조회 성공", response));
}

// 9. 알림 허용 여부 토글 (PATCH)
@PatchMapping("/{userId}/notification")
public ResponseEntity<ApiResponse<String>> updateNotificationSetting(
@PathVariable Long userId,
@Valid @RequestBody UserNotificationRequest request
) {
userService.updateNotificationSetting(userId, request.enabled());
return ResponseEntity.ok(ApiResponse.ok("알림 설정이 수정되었습니다.", "Success"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.hackathon.domain.user.dto.request;

import jakarta.validation.constraints.NotNull;

public record UserNotificationRequest(
@NotNull(message = "알림 설정값은 필수입니다.")
Boolean enabled
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.hackathon.domain.user.dto.response;

public record UserResponse(
Long id,
String nickname,
String email,
boolean emailNotificationEnabled
) {
public static UserResponse of(Long id, String nickname, String email, boolean emailNotificationEnabled) {
return new UserResponse(id, nickname, email, emailNotificationEnabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ public void updateLastPopupShownDate(LocalDate date) {
public void updateLastSettlementDate(LocalDate date) {
this.lastSettlementDate = date;
}

public void updateEmailNotificationEnabled(boolean enabled) {
this.emailNotificationEnabled = enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.hackathon.domain.user.repository.UserRepository;
import com.example.hackathon.domain.user.dto.response.UserCreateResponse;
import com.example.hackathon.domain.user.dto.response.UserHomeResponse;
import com.example.hackathon.domain.user.dto.response.UserResponse;
import com.example.hackathon.domain.user.dto.response.UserHomeResponse.HomeMemberStatus;
import com.example.hackathon.domain.user.dto.response.UserHomeResponse.HomePopupInfo;
import com.example.hackathon.domain.user.entity.DailySettlementLog;
Expand Down Expand Up @@ -102,6 +103,20 @@ public void updateUserEmail(Long userId, String email) {
user.updateEmail(email);
}

@Transactional(readOnly = true)
public UserResponse getUser(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.USER_ERROR_404_NOT_FOUND));
return UserResponse.of(user.getId(), user.getNickname(), user.getEmail(), user.isEmailNotificationEnabled());
}

@Transactional
public void updateNotificationSetting(Long userId, boolean enabled) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.USER_ERROR_404_NOT_FOUND));
user.updateEmailNotificationEnabled(enabled);
}

@Transactional
public UserHomeResponse getHomeData(Long userId) {
User user = userRepository.findByIdForUpdate(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.example.hackathon.domain.team.repository.TeamMemberRepository;
import com.example.hackathon.domain.team.repository.TeamRepository;
import com.example.hackathon.domain.user.dto.response.UserHomeResponse;
import com.example.hackathon.domain.user.dto.response.UserResponse;
import com.example.hackathon.domain.user.entity.DailySettlementLog;
import com.example.hackathon.domain.user.entity.User;
import com.example.hackathon.domain.user.repository.DailySettlementLogRepository;
Expand Down Expand Up @@ -171,4 +172,34 @@ void homeDataThrowsWhenDetoxTimeNull() {
() -> userService.getHomeData(user.getId())
);
}

@Test
@DisplayName("유저 상세 조회 시 등록 정보가 정상 반환된다")
void getUserDetailsSuccess() {
// given
User user = createUser("길동", "test@test.com");

// when
UserResponse response = userService.getUser(user.getId());

// then
assertThat(response.id()).isEqualTo(user.getId());
assertThat(response.nickname()).isEqualTo("길동");
assertThat(response.email()).isEqualTo("test@test.com");
assertThat(response.emailNotificationEnabled()).isTrue();
}

@Test
@DisplayName("알림 토글 API 호출 시 수신동의 플래그가 정상 업데이트된다")
void updateNotificationSettingSuccess() {
// given
User user = createUser("길동", "test@test.com");

// when
userService.updateNotificationSetting(user.getId(), false);

// then
User updated = userRepository.findById(user.getId()).orElseThrow();
assertThat(updated.isEmailNotificationEnabled()).isFalse();
}
}
Loading