Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PC-382] 어드민 프로필 상태 변경 기능 #33

Open
wants to merge 6 commits into
base: feature/PC-383-admin-read-block
Choose a base branch
from
Open
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,54 @@
package org.yapp.profile.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yapp.domain.profile.Profile;
import org.yapp.domain.profile.ProfileRejectHistory;
import org.yapp.domain.profile.ProfileStatus;
import org.yapp.domain.user.RoleStatus;
import org.yapp.domain.user.User;
import org.yapp.error.dto.ProfileErrorCode;
import org.yapp.error.exception.ApplicationException;
import org.yapp.profile.dao.ProfileRejectHistoryRepository;
import org.yapp.user.application.UserService;

@Service
@RequiredArgsConstructor
public class AdminProfileService {

private final ProfileRejectHistoryRepository profileRejectHistoryRepository;
private final UserService userService;

@Transactional
public void updateProfileStatus(Long userId, boolean reasonImage, boolean reasonDescription) {
User user = userService.getUserById(userId);
Profile profile = user.getProfile();

if (profile == null) {
throw new ApplicationException(ProfileErrorCode.NOTFOUND_PROFILE);
}

if (reasonImage || reasonDescription) {
rejectProfile(user.getProfile(), reasonImage, reasonDescription);
} else {
passProfile(profile);
}
}

private void rejectProfile(Profile profile, boolean reasonImage, boolean reasonDescription) {
profileRejectHistoryRepository.save(ProfileRejectHistory.builder()
.user(profile.getUser())
.reasonImage(reasonImage)
.reasonDescription(reasonDescription)
.build());

profile.updateProfileStatus(ProfileStatus.REJECTED);
profile.getUser().updateUserRole(RoleStatus.PENDING.getStatus());
}

private void passProfile(Profile profile) {
profile.updateProfileStatus(ProfileStatus.APPROVED);
profile.getUser().updateUserRole(RoleStatus.USER.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.yapp.user.presentation;

import jakarta.validation.constraints.NotNull;

public record UpdateProfileStatusRequest(@NotNull boolean rejectImage,
@NotNull boolean rejectDescription) {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.yapp.user.presentation;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yapp.profile.application.AdminProfileService;
import org.yapp.user.application.UserService;
import org.yapp.user.presentation.response.UserProfileDetailResponses;
import org.yapp.user.presentation.response.UserProfileValidationResponse;
Expand All @@ -19,6 +23,7 @@
public class UserController {

private final UserService userService;
private final AdminProfileService adminProfileService;

@GetMapping("")
public ResponseEntity<CommonResponse<PageResponse<UserProfileValidationResponse>>> getUsers(
Expand All @@ -33,9 +38,20 @@ public ResponseEntity<CommonResponse<PageResponse<UserProfileValidationResponse>

@GetMapping("/{userId}")
public ResponseEntity<CommonResponse<UserProfileDetailResponses>> getUserProfile(
@PathVariable long userId) {
@PathVariable Long userId) {

UserProfileDetailResponses userProfileDetails = userService.getUserProfileDetails(userId);
return ResponseEntity.ok(CommonResponse.createSuccess(userProfileDetails));
}

@PostMapping("/{userId}/profile")
public ResponseEntity<CommonResponse<Void>> updateUserProfileStatus(
@PathVariable Long userId,
@RequestBody @Valid UpdateProfileStatusRequest request) {

adminProfileService.updateProfileStatus(userId, request.rejectImage(),
request.rejectDescription());

return ResponseEntity.ok(CommonResponse.createSuccess(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public record UserProfileValidationResponse(Long userId, String description,
String nickname,
String name, LocalDate birthdate, String phoneNumber,
LocalDate joinDate,
String profileStatus, boolean reasonImage,
boolean reasonDescription) {
String profileStatus, boolean rejectImage,
boolean rejectDescription) {

public static UserProfileValidationResponse from(User user, boolean reasonImage,
boolean reasonDescription) {
public static UserProfileValidationResponse from(User user, boolean rejectImage,
boolean rejectDescription) {
Profile profile = user.getProfile();

return UserProfileValidationResponse.builder()
Expand All @@ -26,8 +26,8 @@ public static UserProfileValidationResponse from(User user, boolean reasonImage,
.phoneNumber(user.getPhoneNumber() != null ? user.getPhoneNumber() : null)
.joinDate(user.getCreatedAt() != null ? user.getCreatedAt().toLocalDate() : null)
.profileStatus(profile != null ? profile.getProfileStatus().getDisplayName() : null)
.reasonImage(reasonImage)
.reasonDescription(reasonDescription)
.rejectImage(rejectImage)
.rejectDescription(rejectDescription)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.yapp.domain.auth.application.jwt.JwtUtil;
import org.yapp.domain.auth.application.oauth.OauthProvider;
import org.yapp.domain.auth.application.oauth.OauthProviderResolver;
import org.yapp.domain.auth.presentation.dto.enums.RoleStatus;
import org.yapp.domain.auth.presentation.dto.request.OauthLoginRequest;
import org.yapp.domain.auth.presentation.dto.response.OauthLoginResponse;
import org.yapp.domain.user.RoleStatus;
import org.yapp.domain.user.User;
import org.yapp.domain.user.dao.UserRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yapp.domain.auth.presentation.dto.enums.RoleStatus;
import org.yapp.domain.profile.Profile;
import org.yapp.domain.profile.ProfileBasic;
import org.yapp.domain.profile.ProfileValuePick;
Expand All @@ -19,6 +18,7 @@
import org.yapp.domain.profile.presentation.request.ProfileValuePickUpdateRequest.ProfileValuePickPair;
import org.yapp.domain.profile.presentation.request.ProfileValueTalkUpdateRequest;
import org.yapp.domain.profile.presentation.request.ProfileValueTalkUpdateRequest.ProfileValueTalkPair;
import org.yapp.domain.user.RoleStatus;
import org.yapp.domain.user.User;
import org.yapp.domain.user.application.UserService;
import org.yapp.error.dto.ProfileErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.springframework.transaction.annotation.Transactional;
import org.yapp.application.AuthenticationService;
import org.yapp.domain.auth.application.jwt.JwtUtil;
import org.yapp.domain.auth.presentation.dto.enums.RoleStatus;
import org.yapp.domain.auth.presentation.dto.response.OauthLoginResponse;
import org.yapp.domain.profile.Profile;
import org.yapp.domain.user.RoleStatus;
import org.yapp.domain.user.User;
import org.yapp.domain.user.dao.UserRepository;
import org.yapp.error.dto.UserErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ public void updateProfileValuePicks(List<ProfileValuePick> profileValuePicks) {
public void updateProfileValueTalks(List<ProfileValueTalk> profileValueTalks) {
this.profileValueTalks = profileValueTalks;
}

public void updateProfileStatus(ProfileStatus profileStatus) {
this.profileStatus = profileStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -26,7 +27,7 @@ public class ProfileRejectHistory extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne()
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.yapp.domain.auth.presentation.dto.enums;
package org.yapp.domain.user;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
Expand Down