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 @@ -2,7 +2,9 @@

import java.util.List;

@Deprecated
public record OnboardRequest(
List<OnboardArtistRequest> favoriteArtists
List<OnboardArtistRequest> favoriteArtists
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,21 @@ public void logout(Long userId) {
logoutService.logout(userId);
}

@Deprecated
@Transactional
public void onboard(long userId, OnboardDTO onboardDTO) {
User user = userService.findById(userId);
Set<String> favoriteArtistIds = onboardDTO.favoriteArtists().stream()
.map(OnboardArtistDTO::artistId)
.collect(Collectors.toSet());
.map(OnboardArtistDTO::artistId)
.collect(Collectors.toSet());

onboardService.validateFavoriteArtistCount(favoriteArtistIds);
artistFavoriteService.addFavorites(user, favoriteArtistIds);
user.setRole(Role.GENERAL);
}

public void flushCachedTopArtists(long userId) {
userOnboardService.flushCachedTopArtists(userId);
userOnboardService.flushCachedOnboardArtists(userId);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public ResponseEntity<BaseResponse<UserOnboardFavoriteArtistsResponse>> getFavor
UserOnboardFavoriteArtistsResponse.from(favoriteArtists));
}

/**
* 개발을 위해 임시로 Role.GENERAL 접근 허용
*/
@Permission(role = {Role.ONBOARDING, Role.GENERAL})
@PostMapping()
public ResponseEntity<BaseResponse<Void>> onboard(
@UserId Long userId
) {
userOnboardFacade.onboard(userId);
userOnboardFacade.flushCachedOnboardArtists(userId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}

/**
* 개발을 위해 임시로 Role.GENERAL 접근 허용
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sopt.confeti.api.user.dto.request.PatchOnboardFavoriteArtistsRequest;
import org.sopt.confeti.api.user.dto.response.onboard.UserOnboardFavoriteArtistsResponse;
import org.sopt.confeti.global.annotation.UserId;
import org.sopt.confeti.global.common.BaseResponse;
import org.sopt.confeti.global.common.swagger.AuthErrorResponses;
import org.sopt.confeti.global.common.swagger.CommonErrorResponses;
Expand All @@ -29,6 +30,29 @@ ResponseEntity<BaseResponse<UserOnboardFavoriteArtistsResponse>> getFavoriteArti
Long userId
);

@Operation(
summary = "회원가입한 유저의 온보딩 완료 요청",
description =
"""
V4 변경사항
- RequestBody 로 favoriteArtistId 목록을 받아서 처리하던 부분이 사라짐
- 서버에서 내부적으로 온보딩 시 사용된 favoriteArtistId 를 관리하므로 해당 데이터를 사용해 온보딩 완료 로직을 진행함
"""
)
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "성공"
)
}
)
@CommonErrorResponses
@AuthErrorResponses
ResponseEntity<BaseResponse<Void>> onboard(
@UserId Long userId
);

@Operation(
summary = "온보딩 진행 중 favorite 으로 선택했던 아티스트 목록 수정",
description =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import org.sopt.confeti.api.user.facade.dto.response.onboard.UserOnboardCacheDTO;
import org.sopt.confeti.api.user.facade.dto.response.onboard.UserOnboardFavoriteArtistsDTO;
import org.sopt.confeti.api.user.facade.dto.response.onboard.UserOnboardRelatedArtistsDTO;
import org.sopt.confeti.domain.artist_favorite.application.ArtistFavoriteService;
import org.sopt.confeti.domain.user.User;
import org.sopt.confeti.domain.user.application.UserOnboardService;
import org.sopt.confeti.domain.user.application.UserService;
import org.sopt.confeti.domain.user.constant.Role;
import org.sopt.confeti.global.annotation.Facade;
import org.sopt.confeti.global.exception.BadRequestException;
import org.sopt.confeti.global.exception.NotFoundException;
import org.sopt.confeti.global.message.ErrorMessage;
import org.sopt.confeti.global.resolver.music_api.artist.vo.ConfetiArtist;
Expand All @@ -45,6 +48,7 @@ public class UserOnboardFacade {
private final UserOnboardService userOnboardService;
private final RedisTemplate<String, Object> redisTemplate;
private final ObjectMapper objectMapper;
private final ArtistFavoriteService artistFavoriteService;

public UserOnboardRelatedArtistsDTO getArtistsRelatedTerm(long userId, String term, int limit) {
Set<String> topArtistIds = userOnboardService.getCachedExposedArtistIds(userId);
Expand Down Expand Up @@ -150,6 +154,22 @@ public UserOnboardFavoriteArtistsDTO getFavoriteArtists(long userId) {
return UserOnboardFavoriteArtistsDTO.from(favoriteArtists);
}

@Transactional
public void onboard(long userId) {
UserOnboardCacheDTO cachedArtists = userOnboardService.getCachedArtists(userId);
validOnboardArtists(cachedArtists);

Set<String> favoriteArtistIds = cachedArtists.favoriteArtistIds();
User user = userService.findById(userId);

artistFavoriteService.addFavorites(user, favoriteArtistIds);
user.setRole(Role.GENERAL);
}

public void flushCachedOnboardArtists(long userId) {
userOnboardService.flushCachedOnboardArtists(userId);
}

public void cacheTopArtists(List<ConfetiArtist> topArtists) {
redisTemplate.opsForValue().set(RedisKey.MUSIC_TOP_ARTISTS.get(), topArtists);
}
Expand Down Expand Up @@ -219,4 +239,12 @@ private void cacheRelatedArtists(
UserOnboardCacheDTO.of(newFavoriteArtistIds, newExposedArtistIds));
}

private void validOnboardArtists(UserOnboardCacheDTO userOnboardCacheDTO) {
Set<String> favoriteArtistIds = userOnboardCacheDTO.favoriteArtistIds();

if (favoriteArtistIds == null || favoriteArtistIds.isEmpty()) {
throw new BadRequestException(ErrorMessage.BAD_REQUEST);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void cacheOnboardArtists(long userId, UserOnboardCacheDTO artistsDTO) {
.set(generateRedisKey(userId), artistsDTO, REDIS_TTL_DAY, TimeUnit.DAYS);
}

public void flushCachedTopArtists(long userId) {
public void flushCachedOnboardArtists(long userId) {
redisTemplate.delete(generateRedisKey(userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.confeti.global.exception;

import org.sopt.confeti.global.message.ErrorMessage;

public class BadRequestException extends ConfetiException {

public BadRequestException(ErrorMessage message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(BadRequestException.class)
public ResponseEntity<BaseResponse<Void>> handleIllegalArgumentException(
BadRequestException e, HttpServletRequest request) {
request.setAttribute("exception", e);
return ApiResponseUtil.failure(ErrorMessage.BAD_REQUEST);
}

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<BaseResponse<Void>> handleIllegalArgumentException(
IllegalArgumentException e, HttpServletRequest request) {
Expand Down