Skip to content

Commit

Permalink
Merge pull request #327 from WE-ARE-RACCOONS/RAC-462
Browse files Browse the repository at this point in the history
RAC-462 feat : wish 분리 및 신청서 API
  • Loading branch information
ywj9811 authored Nov 19, 2024
2 parents 45024f4 + 7ca9c5e commit aa6d611
Show file tree
Hide file tree
Showing 64 changed files with 2,627 additions and 2,574 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.postgraduate.admin.application.mapper;

import com.postgraduate.admin.application.dto.res.*;
import com.postgraduate.domain.member.user.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.salary.domain.entity.Salary;
Expand All @@ -9,8 +10,6 @@
import com.postgraduate.domain.member.senior.domain.entity.Senior;
import com.postgraduate.domain.member.user.application.utils.UserUtils;
import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.domain.entity.constant.Role;
import com.postgraduate.domain.member.user.domain.entity.Wish;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -42,19 +41,17 @@ public CertificationDetailsResponse mapToCertificationInfo(Senior senior) {
);
}

public UserInfo mapToUserInfo(Wish wish) {
User user = wish.getUser();
Boolean isSenior = user.getRole() == Role.SENIOR;
public UserInfo mapToUserInfo(User user) {
return new UserInfo(
user.getUserId(),
user.getNickName(),
user.getPhoneNumber(),
user.getCreatedAt(),
user.getMarketingReceive(),
wish.getMatchingReceive(),
wish.getWishId(),
wish.getStatus(),
isSenior
false,
1L, // todo : wish 삭제에 따른 변경 필요
Status.MATCHED,
false
);
}

Expand All @@ -69,7 +66,7 @@ public SeniorInfo mapToSeniorInfo(Salary salary) {
senior.getStatus(),
salary.getTotalAmount(),
user.getMarketingReceive(),
user.isJunior()
false //todo : wish 삭제에 따른 선배에서 후배 판단 조건 삭제 or 수정 필요
);
}

Expand Down Expand Up @@ -242,17 +239,4 @@ private static MentoringWithPaymentResponse getMentoringWithPaymentResponse(Ment
SHORT.getCharge()
);
}

public WishResponse mapToWishResponse(Wish wish) {
User user = wish.getUser();
return new WishResponse(
wish.getWishId(),
user.getNickName(),
user.getPhoneNumber(),
user.getCreatedAt(),
user.getMarketingReceive(),
wish.getMatchingReceive(),
wish.getMajor(),
wish.getField());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.postgraduate.admin.application.mapper.AdminMapper;
import com.postgraduate.admin.domain.service.AdminUserService;
import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.domain.entity.Wish;
import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest;
import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,16 +30,15 @@ public User login(Login loginForm) {

@Transactional(readOnly = true)
public List<UserInfo> userInfos() {
List<Wish> all = adminUserService.allJunior();
List<User> all = adminUserService.allJunior();
return all.stream()
.map(adminMapper::mapToUserInfo)
.toList();
}

@Transactional(readOnly = true)
public WishResponse wishInfo(Long userId) {
User user = adminUserService.userByUserId(userId);
return adminMapper.mapToWishResponse(user.getWish());
return null; //todo : wish 변경에 따른 수정 필요
}

public void wishDone(Long wishId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.postgraduate.admin.domain.repository;

import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.domain.entity.Wish;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -16,19 +15,12 @@
public class AdminUserRepository {
private final JPAQueryFactory queryFactory;

public List<Wish> findAllJunior() {
return queryFactory.select(user.wish)
.from(user)
.where(user.wish.isNotNull())
public List<User> findAllJunior() {
return queryFactory.selectFrom(user)
// .where(user.role.eq(Role.USER))
.fetch();
}

public Optional<User> findUserByWishId(Long wishId) {
return Optional.ofNullable(queryFactory.selectFrom(user)
.where(user.wish.wishId.eq(wishId))
.fetchOne());
}

public Optional<User> findUserByUserId(Long userId) {
return Optional.ofNullable(queryFactory.selectFrom(user)
.where(user.userId.eq(userId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.postgraduate.admin.domain.repository.AdminUserRepository;
import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.exception.UserNotFoundException;
import com.postgraduate.domain.member.user.domain.entity.Wish;
import com.postgraduate.domain.member.user.exception.WishNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -15,14 +13,12 @@
public class AdminUserService {
private final AdminUserRepository adminUserRepository;

public List<Wish> allJunior() {
public List<User> allJunior() {
return adminUserRepository.findAllJunior();
}

public void updateWishDone(Long wishId) {
User user = adminUserRepository.findUserByWishId(wishId)
.orElseThrow(WishNotFoundException::new);
user.updateWishDone();
//todo : wish삭제에 따른 수정 필요
}

public User userByUserId(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;

import static com.postgraduate.domain.member.senior.application.mapper.SeniorMapper.*;
import static com.postgraduate.domain.member.user.domain.entity.constant.Role.SENIOR;

@Service
@Transactional
Expand All @@ -25,7 +24,7 @@ public class SeniorInfoUseCase {
private final SeniorUpdateService seniorUpdateService;

public SeniorDetailResponse getSeniorDetail(User user, Long seniorId) {
if (user != null && user.getRole() == SENIOR)
if (user != null && user.isSenior())
return checkIsMine(user, seniorId);
return getResponse(seniorId, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,4 @@ public SeniorMyPageUserAccountResponse getSeniorMyPageUserAccount(User user) {
String accountNumber = encryptorUtils.decryptData(account.getAccountNumber());
return mapToMyPageUserAccount(senior, account, accountNumber);
}

public SeniorPossibleResponse checkUser(User user) {
if (!user.isJunior())
return new SeniorPossibleResponse(FALSE, user.getSocialId());
return new SeniorPossibleResponse(TRUE, user.getSocialId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,4 @@ public ResponseEntity<ResponseDto<AllSeniorSearchResponse>> getFieldSenior(@Requ
AllSeniorSearchResponse searchSenior = seniorInfoUseCase.getFieldSenior(field, postgradu, page);
return ResponseEntity.ok(create(SeniorResponseCode.SENIOR_FIND.getCode(), SeniorResponseMessage.GET_SENIOR_LIST_INFO.getMessage(), searchSenior));
}

@GetMapping("/me/role")
@Operation(summary = "후배 전환시 가능 여부 확인 | 토큰 필요", description = "true-가능, false-불가능")
public ResponseEntity<ResponseDto<SeniorPossibleResponse>> checkRole(@AuthenticationPrincipal User user) {
SeniorPossibleResponse possibleResponse = seniorMyPageUseCase.checkUser(user);
return ResponseEntity.ok(create(SeniorResponseCode.SENIOR_FIND.getCode(), SeniorResponseMessage.GET_USER_CHECK.getMessage(), possibleResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.postgraduate.domain.member.user.application.dto.res.UserInfoResponse;
import com.postgraduate.domain.member.user.application.dto.res.UserMyPageResponse;
import com.postgraduate.domain.member.user.domain.entity.MemberRole;
import com.postgraduate.domain.member.user.domain.entity.constant.Role;
import com.postgraduate.domain.member.user.domain.entity.constant.Status;
import com.postgraduate.domain.member.user.domain.entity.Wish;
import com.postgraduate.global.auth.login.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.global.auth.login.application.dto.req.SignUpRequest;
import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.global.auth.login.application.dto.req.UserChangeRequest;

public class UserMapper {

Expand Down Expand Up @@ -48,29 +46,13 @@ public static User mapToUser(SeniorSignUpRequest request, String profile) {
.phoneNumber(request.phoneNumber())
.marketingReceive(request.marketingReceive())
.profile(profile)
.role(Role.SENIOR)
.build();
}

public static Wish mapToWish(User user, SignUpRequest request) {
Status matchingStatus = request.matchingReceive() ? Status.WAITING : Status.REJECTED;
return Wish.builder()
public static MemberRole mapToRole(Role role, User user) {
return MemberRole.builder()
.role(role)
.user(user)
.major(request.major())
.field(request.field())
.matchingReceive(request.matchingReceive())
.status(matchingStatus)
.build();
}

public static Wish mapToWish(User user, UserChangeRequest request) {
Status matchingStatus = request.matchingReceive() ? Status.WAITING : Status.REJECTED;
return Wish.builder()
.user(user)
.major(request.major())
.field(request.field())
.matchingReceive(request.matchingReceive())
.status(matchingStatus)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.postgraduate.domain.member.user.application.dto.res.UserPossibleResponse;
import com.postgraduate.domain.member.user.application.mapper.UserMapper;
import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.domain.entity.constant.Role;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -21,8 +20,7 @@ public UserInfoResponse getUserOriginInfo(User user) {
}

public UserPossibleResponse checkSenior(User user) {
Role role = user.getRole();
if (role.equals(Role.SENIOR))
if (user.isSenior())
return new UserPossibleResponse(true, user.getSocialId());
return new UserPossibleResponse(false, user.getSocialId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UserUtils {

@PostConstruct
public void init() {
archiveUser = new User(-100L, -100L, null, "알수없음", "탈퇴한회원", profile, 0, null, false, null, null, false, false, null);
archiveUser = new User(-100L, -100L, null, "알수없음", "탈퇴한회원", profile, 0, null, false, null, null, false, false);
}

public User getArchiveUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.postgraduate.domain.member.user.domain.entity;

import com.postgraduate.domain.member.user.domain.entity.constant.Role;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class MemberRole {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long roleId;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Role role;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.annotations.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static java.time.LocalDate.now;
Expand Down Expand Up @@ -46,10 +47,9 @@ public class User {
@Column(nullable = false)
private int point;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
@Builder.Default
private Role role = Role.USER;
private List<MemberRole> roles = new ArrayList<>();

@Column(nullable = false)
private Boolean marketingReceive;
Expand All @@ -69,23 +69,29 @@ public class User {
@Builder.Default
private boolean isDelete = false;

@OneToOne(mappedBy = "user")
private Wish wish;

public void addWish(Wish wish) {
this.wish = wish;
public boolean isJunior() {
return roles.stream()
.map(MemberRole::getRole)
.toList()
.contains(Role.USER);
}

public void updateWishDone() {
this.wish.updateDone();
public boolean isSenior() {
return roles.stream()
.map(MemberRole::getRole)
.toList()
.contains(Role.SENIOR);
}

public boolean isJunior() {
return this.wish != null;
public boolean isAdmin() {
return roles.stream()
.map(MemberRole::getRole)
.toList()
.contains(Role.ADMIN);
}

public void updateRole(Role role) {
this.role = role;
public void updateRole(MemberRole memberRole) {
roles.add(memberRole);
}

public void updateInfo(String profile, String nickName, String phoneNumber) {
Expand Down Expand Up @@ -143,8 +149,4 @@ public boolean isHardDelete() {
)
);
}

public boolean isSenior() {
return this.role.equals(Role.SENIOR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.postgraduate.domain.member.user.domain.repository;

import com.postgraduate.domain.member.user.domain.entity.MemberRole;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRoleRepository extends JpaRepository<MemberRole, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
package com.postgraduate.domain.member.user.domain.repository;

import com.postgraduate.domain.member.user.domain.entity.User;
import com.postgraduate.domain.member.user.domain.entity.Wish;

public interface UserDslRepository {
void saveJunior(User user, Wish wish);

void changeJunior(Wish wish);
void deleteWish(User user);
}
Loading

0 comments on commit aa6d611

Please sign in to comment.