Skip to content

Commit

Permalink
Merge pull request #59 from ssu-student-union/feat/54-onBoarding
Browse files Browse the repository at this point in the history
[fix] : OnBoarding 관련 메소드 수정
  • Loading branch information
Jeoongu authored Aug 16, 2024
2 parents b9f5138 + b602d3a commit 2bf1315
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public class OnBoardingService {

@Transactional
public void saveUserOnBoarding(Long userId, OnBoardingRequest request){
User user = userReader.getUserWithId(userId);
// User user = userReader.getUserWithId(userId);
String studentId = request.getStudentId();
// studentCsvReader.getStudentWithStudentId(Long.valueOf(studentId), request)
// .orElseThrow(() -> new GeneralException(USER_NOT_FOUND));

userModifier.updateOnBoardingUser(request);
memberAppender.saveMember(Member.of(null, false,
request.getMemberCode(), request.getMajorCode(),
userId, null));
Member member = Member.createMember(false, request.getMemberCode(), request.getMajorCode(), userId);
memberAppender.saveMember(member);
}

public void sendEmail(OnBoardingEmailRequest onBoardingEmailRequest) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ussum/homepage/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public static Member of(Long id, Boolean isAdmin, String memberCode, String majo
.build();
}

public static Member createMember(Boolean isAdmin, String memberCode, String majorCode, Long userId) {
return Member.builder()
.isAdmin(isAdmin)
.memberCode(memberCode)
.majorCode(majorCode)
.userId(userId)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
public interface MemberRepository {
Optional<Member> findByUserId(Long userId);
Optional<Member> findCentralOperationCommitteeMember(Long userId);
Member save(Member member);
void save(Member member);
}
14 changes: 12 additions & 2 deletions src/main/java/ussum/homepage/infra/jpa/member/MemberMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ public Member toDomain(MemberEntity memberEntity) {
String.valueOf(memberEntity.getMemberCode()),
String.valueOf(memberEntity.getMajorCode()),
memberEntity.getUserEntity().getId(),
memberEntity.getGroupEntity().getId()
memberEntity.getGroupEntity() == null ? null : memberEntity.getGroupEntity().getId()
);
}

public MemberEntity toEntity(Member member) {
// if(member.getGroupId() == null) {
// return MemberEntity.nullGroup(
// member.getId(),
// member.getIsAdmin(),
// MemberCode.getEnumMemberCodeFromStringMemberCode(member.getMemberCode()),
// MajorCode.getEnumMajorCodeFromStringMajorCode(member.getMajorCode()),
// UserEntity.from(member.getUserId())
// );
// }

return MemberEntity.of(
member.getId(),
member.getIsAdmin(),
MemberCode.getEnumMemberCodeFromStringMemberCode(member.getMemberCode()),
MajorCode.getEnumMajorCodeFromStringMajorCode(member.getMajorCode()),
UserEntity.from(member.getUserId()),
GroupEntity.from(member.getGroupId())
member.getGroupId() == null ? null : GroupEntity.from(member.getGroupId())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Optional<Member> findCentralOperationCommitteeMember(Long userId) {
}

@Override
public Member save(Member member) {
return memberMapper.toDomain(memberJpaRepository.save(memberMapper.toEntity(member)));
public void save(Member member) {
memberJpaRepository.save(memberMapper.toEntity(member));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ussum.homepage.infra.jpa.member.entity;

import jakarta.persistence.*;
import lombok.*;
import ussum.homepage.infra.jpa.BaseEntity;
import ussum.homepage.infra.jpa.group.entity.GroupEntity;
import ussum.homepage.infra.jpa.user.entity.UserEntity;


@Entity
@Table(name = "member")
@Getter
Expand All @@ -28,15 +28,18 @@ public class MemberEntity extends BaseEntity {
@JoinColumn(name = "user_id")
private UserEntity userEntity;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) // 일단 cascade = CascadeType.PERSIST 추가, 영속화 문제 해결
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "groups_id")
private GroupEntity groupEntity;

public static MemberEntity of(Long id, Boolean isAdmin, MemberCode memberCode, MajorCode majorCode, UserEntity userEntity, GroupEntity groupEntity) {
return new MemberEntity(id, isAdmin, memberCode, majorCode, userEntity, groupEntity);
} // ?
}
public static MemberEntity nullGroup(Long id, Boolean isAdmin, MemberCode memberCode, MajorCode majorCode, UserEntity userEntity) {
return new MemberEntity(id, isAdmin, memberCode, majorCode, userEntity, null);
}

public static MemberEntity from(Long id) {
return new MemberEntity(id, null, null, null, null, null);
} // ?
}
}

0 comments on commit 2bf1315

Please sign in to comment.