Skip to content

Commit

Permalink
회원 가입 시 스페이스 생성 기능 구현 완료 (#193)
Browse files Browse the repository at this point in the history
* feat : AddSpaceRepository에 saveAll 메서드 추가 (#192)

* feat : 회원 가입 시 사용자의 개인 스페이스와 단체 스페이스를 자동으로 생성하는 기능을 추가 (#192)

- 새로운 회원 정보를 저장한 후, 해당 회원의 개인 스페이스와 단체 스페이스 정보를 SpaceSaveRequest 객체 생성
- SpaceSaveRequest 객체들을 AddSpace 엔티티로 변환하고 저장

* refactor : SpaceSaveRequest 생성 로직 메서드로 분리 (#192)

* refactor : 회원가입한 사용자 스페이스 생성 로직 메서드 분리 (#192)

* refactor : 스페이 저장 로직 메서드 분리 (#192)

* refactor : 스페이스 초기화 및 저장 메서드 통합 (#192)

- 회원가입 과정에서 새로운 회원을 위한 스페이스를 초기화하고 저장하는 로직을 한 메서드에서 처리하도록 변경
  • Loading branch information
dpdmstjs authored Oct 24, 2023
1 parent 1f6f5e1 commit 9c30e56
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
40 changes: 39 additions & 1 deletion src/main/java/com/javajober/member/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.javajober.member.service;


import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import javax.transaction.Transactional;

Expand All @@ -19,20 +21,26 @@
import com.javajober.core.refreshToken.repository.RefreshTokenRepository;
import com.javajober.core.security.JwtTokenizer;
import com.javajober.core.refreshToken.domain.RefreshToken;
import com.javajober.space.domain.AddSpace;
import com.javajober.space.domain.SpaceType;
import com.javajober.space.dto.request.SpaceSaveRequest;
import com.javajober.space.repository.AddSpaceRepository;

@Service
public class MemberService {
private final MemberRepository memberRepository;
private final PasswordEncoder passwordEncoder;
private final JwtTokenizer jwtTokenizer;
private final RefreshTokenRepository refreshTokenRepository;
private final AddSpaceRepository addSpaceRepository;

public MemberService(MemberRepository memberRepository, PasswordEncoder passwordEncoder, JwtTokenizer jwtTokenizer,
RefreshTokenRepository refreshTokenRepository) {
RefreshTokenRepository refreshTokenRepository, AddSpaceRepository addSpaceRepository) {
this.memberRepository = memberRepository;
this.passwordEncoder = passwordEncoder;
this.jwtTokenizer = jwtTokenizer;
this.refreshTokenRepository = refreshTokenRepository;
this.addSpaceRepository = addSpaceRepository;
}

@Transactional
Expand All @@ -47,9 +55,39 @@ public MemberSignupResponse signup(MemberSignupRequest memberSignupRequest) {
member.setPassword(passwordEncoder.encode(memberSignupRequest.getPassword()));
Member saveMember = memberRepository.save(member);

initializeAndSaveNewMemberSpaces(member);

return new MemberSignupResponse(saveMember);
}

private void initializeAndSaveNewMemberSpaces(Member member) {

SpaceSaveRequest personalSpaceRequest = createSpaceSaveRequest(member.getMemberName(), SpaceType.PERSONAL.getEngTitle(), member.getMemberName());
SpaceSaveRequest organizationSpaceRequest = createSpaceSaveRequest(member.getMemberName(), SpaceType.ORGANIZATION.getEngTitle(), "임시회사명");

Set<AddSpace> spaces = new HashSet<>();

AddSpace personalSpace = SpaceSaveRequest.toEntity(personalSpaceRequest, member);
spaces.add(personalSpace);

AddSpace organizationSpace = SpaceSaveRequest.toEntity(organizationSpaceRequest, member);
spaces.add(organizationSpace);

saveSpaces(spaces);
}

private SpaceSaveRequest createSpaceSaveRequest(String spaceTitle, String spaceType, String representativeName) {
return SpaceSaveRequest.builder()
.spaceTitle(spaceTitle)
.spaceType(spaceType)
.representativeName(representativeName)
.build();
}

private void saveSpaces(Set<AddSpace> spaces) {
addSpaceRepository.saveAll(spaces);
}

@Transactional
public MemberLoginResponse login(MemberLoginRequest loginDto) {
Member member = memberRepository.findMember(loginDto.getEmail()).orElseThrow(()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.javajober.member.domain.Member;
import com.javajober.space.domain.AddSpace;
import com.javajober.space.domain.SpaceType;

import lombok.Builder;
import lombok.Getter;

@Getter
Expand All @@ -13,7 +15,15 @@ public class SpaceSaveRequest {
private String representativeName;
private String spaceType;

public SpaceSaveRequest() {
private SpaceSaveRequest() {
}

@Builder
public SpaceSaveRequest(Long memberId, String spaceTitle, String representativeName, String spaceType) {
this.memberId = memberId;
this.spaceTitle = spaceTitle;
this.representativeName = representativeName;
this.spaceType = spaceType;
}

public static AddSpace toEntity(SpaceSaveRequest request, Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;

import com.javajober.core.exception.ApiStatus;
import com.javajober.core.exception.ApplicationException;
Expand All @@ -26,6 +27,8 @@ public interface AddSpaceRepository extends Repository<AddSpace, Long> {
@Query("SELECT s.id FROM AddSpace s WHERE s.spaceType = :spaceType AND s.member.id = :memberId")
List<Long> findAddSpaceIdBySpaceTypeAndMemberId(@Param("spaceType") final SpaceType spaceType, @Param("memberId") final Long memberId);

Set<AddSpace> saveAll(final Iterable<AddSpace> addSpaces);

default AddSpace findAddSpace (final Long id) {
return findById(id)
.orElseThrow(() -> new ApplicationException(ApiStatus.NOT_FOUND, "존재하지 않는 스페이스입니다."));
Expand Down

0 comments on commit 9c30e56

Please sign in to comment.