Skip to content

Commit

Permalink
Merge pull request #45 from WE-ARE-RACCOONS/RAC-153
Browse files Browse the repository at this point in the history
RAC-153 refactor : DB수정 및 요구사항 변경에 따른 리팩토링
  • Loading branch information
ywj9811 authored Nov 17, 2023
2 parents cd74e73 + f8611fb commit e33e3a7
Show file tree
Hide file tree
Showing 82 changed files with 1,446 additions and 935 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.postgraduate.domain.account.application.mapper;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.senior.application.dto.req.SeniorAccountRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;

public class AccountMapper {
public static Account mapToAccount(Senior senior, SeniorAccountRequest accountRequest) {
return Account.builder()
.senior(senior)
.accountNumber(accountRequest.getAccountNumber())
.accountHolder(accountRequest.getAccountHolder())
.bank(accountRequest.getBank())
.name(accountRequest.getName())
.rrn(accountRequest.getRrn())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.postgraduate.domain.account.domain.entity;

import com.postgraduate.domain.senior.application.dto.req.SeniorAccountRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

@Column(nullable = false)
private String accountNumber;

@Column(nullable = false)
private String bank;

@Column(nullable = false)
private String accountHolder;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String rrn;

@OneToOne
private Senior senior;

public void updateAccount(SeniorAccountRequest accountRequest) {
this.accountNumber = accountRequest.getAccountNumber();
this.bank = accountRequest.getBank();
this.accountHolder = accountRequest.getAccountHolder();
this.name = accountRequest.getName();
this.rrn = accountRequest.getRrn();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.postgraduate.domain.account.domain.repository;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.senior.domain.entity.Senior;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface AccountRepository extends JpaRepository<Account, Long> {
Optional<Account> findBySenior(Senior senior);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.postgraduate.domain.account.domain.service;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.account.domain.repository.AccountRepository;
import com.postgraduate.domain.senior.domain.entity.Senior;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
public class AccountGetService {
private final AccountRepository accountRepository;

public Optional<Account> bySenior(Senior senior) {
return accountRepository.findBySenior(senior);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.postgraduate.domain.account.domain.service;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.account.domain.repository.AccountRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AccountSaveService {
private final AccountRepository accountRepository;

public void saveAccount(Account account) {
accountRepository.save(account);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.postgraduate.domain.account.domain.service;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.senior.application.dto.req.SeniorAccountRequest;
import org.springframework.stereotype.Service;

@Service
public class AccountUpdateService {
public void updateAccount(Account account, SeniorAccountRequest accountRequest) {
account.updateAccount(accountRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ public static CertificationResponse mapToCertification(Senior senior) {
.build();
}

public static UserResponse mapToUserResponse(User user) {
return UserResponse.builder()
.userId(user.getUserId())
.nickName(user.getNickName())
.marketingReceive(user.getMarketingReceive())
.matchingReceive(user.getHope().getMatchingReceive())
.createdAt(user.getCreatedAt())
.build();
}
// public static UserResponse mapToUserResponse(User user) {
// return UserResponse.builder()
// .userId(user.getUserId())
// .nickName(user.getNickName())
// .marketingReceive(user.getMarketingReceive())
// .matchingReceive(user.getHope().getMatchingReceive())
// .createdAt(user.getCreatedAt())
// .build();
// }

public static UserWithSeniorResponse mapToUserWithSeniorResponse(User user, Long seniorId) {
return UserWithSeniorResponse.builder()
.userId(user.getUserId())
.nickName(user.getNickName())
.marketingReceive(user.getMarketingReceive())
.matchingReceive(user.getHope().getMatchingReceive())
.createdAt(user.getCreatedAt())
.seniorId(seniorId)
.build();
}
// public static UserWithSeniorResponse mapToUserWithSeniorResponse(User user, Long seniorId) {
// return UserWithSeniorResponse.builder()
// .userId(user.getUserId())
// .nickName(user.getNickName())
// .marketingReceive(user.getMarketingReceive())
// .matchingReceive(user.getHope().getMatchingReceive())
// .createdAt(user.getCreatedAt())
// .seniorId(seniorId)
// .build();
// }

public static SeniorResponse mapToSeniorResponse(Senior senior) {
return SeniorResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@RequiredArgsConstructor
public class MentoringManageByAdminUseCase {
private final MentoringGetService mentoringGetService;
public List<MentoringResponse> getMentorings() {
List<Mentoring> mentorings = mentoringGetService.all();
return mentorings.stream().map(AdminMapper::mapToMentoringResponse).toList();
}
// public List<MentoringResponse> getMentorings() {
// List<Mentoring> mentorings = mentoringGetService.all();
// return mentorings.stream().map(AdminMapper::mapToMentoringResponse).toList();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
public class UserManageByAdminUseCase {
private final UserGetService userGetService;
private final SeniorGetService seniorGetService;
public List<UserResponse> getUsers() {
List<User> users = userGetService.all();
List<UserResponse> userResponses = new ArrayList<>();
users.forEach(user -> {
if (user.getRole() == Role.SENIOR) {
Senior senior = seniorGetService.byUser(user);
userResponses.add(AdminMapper.mapToUserWithSeniorResponse(user, senior.getSeniorId()));
}
userResponses.add(AdminMapper.mapToUserResponse(user));
});
return userResponses;
}
// public List<UserResponse> getUsers() {
// List<User> users = userGetService.all();
// List<UserResponse> userResponses = new ArrayList<>();
// users.forEach(user -> {
// if (user.getRole() == Role.SENIOR) {
// Senior senior = seniorGetService.byUser(user);
// userResponses.add(AdminMapper.mapToUserWithSeniorResponse(user, senior.getSeniorId()));
// }
// userResponses.add(AdminMapper.mapToUserResponse(user));
// });
// return userResponses;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public ResponseDto updateSeniorStatus(@PathVariable Long seniorId, @RequestBody
return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_STATUS.getMessage());
}

@GetMapping("/users")
@Operation(summary = "[관리자] 후배 정보 목록", description = "대학생 후배 정보 목록을 조회합니다.")
public ResponseDto<List<UserResponse>> getUsers() {
List<UserResponse> users = userManageUseCase.getUsers();
return ResponseDto.create(USER_FIND.getCode(), GET_USER_LIST_INFO.getMessage(), users);
}
// @GetMapping("/users")
// @Operation(summary = "[관리자] 후배 정보 목록", description = "대학생 후배 정보 목록을 조회합니다.")
// public ResponseDto<List<UserResponse>> getUsers() {
// List<UserResponse> users = userManageUseCase.getUsers();
// return ResponseDto.create(USER_FIND.getCode(), GET_USER_LIST_INFO.getMessage(), users);
// }

@GetMapping("/seniors")
@Operation(summary = "[관리자] 선배 정보 목록", description = "대학원생 선배 정보 목록을 조회합니다.")
Expand All @@ -70,12 +70,12 @@ public ResponseDto<List<SeniorResponse>> getSeniors() {
return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), seniors);
}

@GetMapping("/mentorings")
@Operation(summary = "[관리자] 매칭 정보 목록", description = "매칭 정보 목록을 조회합니다.")
public ResponseDto<List<MentoringResponse>> getMentorings() {
List<MentoringResponse> mentorings = mentoringManageUseCase.getMentorings();
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentorings);
}
// @GetMapping("/mentorings")
// @Operation(summary = "[관리자] 매칭 정보 목록", description = "매칭 정보 목록을 조회합니다.")
// public ResponseDto<List<MentoringResponse>> getMentorings() {
// List<MentoringResponse> mentorings = mentoringManageUseCase.getMentorings();
// return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentorings);
// }

@GetMapping("/payments")
@Operation(summary = "[관리자] 결제 정보 목록", description = "결제 정보 목록을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SeniorChangeRequest {
@NotNull
private String major;
@NotNull
private String postgradu;
@NotNull
private String professor;
@NotNull
private String lab;
@NotNull
private String field;
@NotNull
private String keyword;
@NotNull
private String certification;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.postgraduate.domain.senior.application.dto.req;
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand All @@ -10,7 +10,13 @@
@NoArgsConstructor
public class SeniorSignUpRequest {
@NotNull
private String college;
private Long socialId;
@NotNull
private String phoneNumber;
@NotNull
private String nickName;
@NotNull
private Boolean marketingReceive;
@NotNull
private String major;
@NotNull
Expand All @@ -22,11 +28,7 @@ public class SeniorSignUpRequest {
@NotNull
private String field;
@NotNull
private String certification;
private String keyword;
@NotNull
private String account;
@NotNull
private String bank;
@NotNull
private String rrn;
private String certification;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public class SignUpRequest {
private Boolean marketingReceive;
private String major;
private String field;
@NotNull
private Boolean matchingReceive;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.postgraduate.domain.auth.application.usecase;

import com.postgraduate.domain.auth.application.dto.req.SeniorChangeRequest;
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.auth.application.dto.req.SignUpRequest;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorSaveService;
import com.postgraduate.domain.user.application.mapper.UserMapper;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.domain.user.domain.service.UserSaveService;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import com.postgraduate.domain.wish.application.mapper.WishMapper;
import com.postgraduate.domain.wish.domain.entity.Wish;
import com.postgraduate.domain.wish.domain.service.WishSaveService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
@RequiredArgsConstructor
public class SignUpUseCase {
private final UserSaveService userSaveService;
private final UserUpdateService userUpdateService;
private final UserGetService userGetService;
private final WishSaveService wishSaveService;
private final SeniorSaveService seniorSaveService;

public User userSignUp(SignUpRequest request) {
User user = UserMapper.mapToUser(request);
Wish wish = WishMapper.mapToWish(user, request);
wishSaveService.saveWish(wish);
userSaveService.saveUser(user);
return user;
}

public User seniorSignUp(SeniorSignUpRequest request) {
User user = UserMapper.mapToUser(request);
userSaveService.saveUser(user);
Senior senior = SeniorMapper.mapToSenior(user, request);
seniorSaveService.saveSenior(senior);
return senior.getUser();
}


public User changeSenior(User user, SeniorChangeRequest changeRequest) {
Senior senior = SeniorMapper.mapToSenior(user, changeRequest); //todo : 예외 처리
seniorSaveService.saveSenior(senior);
userUpdateService.updateRole(user.getUserId(), Role.SENIOR);
return userGetService.getUser(user.getUserId());
}
}
Loading

0 comments on commit e33e3a7

Please sign in to comment.