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

Feature/#901 온보딩에서 활동 설정 시 관심태그도 함께 설정 #903

Open
wants to merge 4 commits into
base: backend-main
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
Expand Up @@ -8,7 +8,6 @@
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberActivityAddRequest;
import com.emmsale.member.application.dto.MemberActivityInitialRequest;
import com.emmsale.member.application.dto.MemberActivityResponse;
import com.emmsale.member.application.dto.MemberDetailResponse;
import com.emmsale.member.application.dto.MemberImageResponse;
import com.emmsale.member.domain.Member;
Expand Down Expand Up @@ -42,7 +41,7 @@ public ResponseEntity<Void> register(
final Member member,
@RequestBody final MemberActivityInitialRequest memberActivityInitialRequest
) {
memberActivityCommandService.registerActivities(member, memberActivityInitialRequest);
memberCommandService.initializeMember(member, memberActivityInitialRequest);
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public List<InterestTagResponse> findInterestTags(final Long memberId) {
return InterestTagResponse.convertAllFrom(interestTags);
}

public void initializeInterestTags(final Member member, final List<String> tagNames) {
final List<Tag> tags = tagRepository.findByNameIn(tagNames);
final List<InterestTag> interestTags = tags.stream()
.map(tag -> new InterestTag(member, tag))
.collect(Collectors.toList());
interestTagRepository.saveAll(interestTags);
}

public List<InterestTagResponse> addInterestTag(final Member member,
final InterestTagAddRequest request) {
final List<Long> tagIds = request.getTagIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.emmsale.activity.domain.ActivityRepository;
import com.emmsale.member.application.dto.MemberActivityAddRequest;
import com.emmsale.member.application.dto.MemberActivityInitialRequest;
import com.emmsale.member.application.dto.MemberActivityResponse;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberActivity;
import com.emmsale.member.domain.MemberActivityRepository;
Expand All @@ -26,28 +25,24 @@ public class MemberActivityCommandService {
private final MemberActivityRepository memberActivityRepository;
private final ActivityRepository activityRepository;

public void registerActivities(
public List<MemberActivity> registerActivities(
final Member member,
final MemberActivityInitialRequest memberActivityInitialRequest
) {
if (member.isOnboarded()) {
throw new MemberException(MemberExceptionType.ALREADY_ONBOARDING);
}
final List<Long> activityIds = memberActivityInitialRequest.getActivityIds();
saveMemberActivities(member, activityIds);

member.updateName(memberActivityInitialRequest.getName());
return saveMemberActivities(member, activityIds);
}

private void saveMemberActivities(final Member member, final List<Long> activityIds) {
private List<MemberActivity> saveMemberActivities(final Member member,
final List<Long> activityIds) {
final List<MemberActivity> memberActivities = activityRepository.findAllById(activityIds)
.stream()
.map(it -> new MemberActivity(it, member))
.collect(toUnmodifiableList());

validateAllActivityIdsExist(activityIds, memberActivities);

memberActivityRepository.saveAll(memberActivities);
return memberActivities;
}

private void validateAllActivityIdsExist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.emmsale.image.application.S3Client;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberActivityInitialRequest;
import com.emmsale.member.application.dto.MemberImageResponse;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberActivity;
import com.emmsale.member.domain.MemberRepository;
import com.emmsale.member.exception.MemberException;
import com.emmsale.member.exception.MemberExceptionType;
import java.util.List;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -19,8 +22,25 @@
public class MemberCommandService {

private final MemberRepository memberRepository;
private final MemberActivityCommandService memberActivityCommandService;
private final InterestTagService interestTagService;
private final S3Client s3Client;

public void initializeMember(final Member member, final MemberActivityInitialRequest request) {
if (member.isOnboarded()) {
throw new MemberException(MemberExceptionType.ALREADY_ONBOARDING);
}
final List<MemberActivity> memberActivities = memberActivityCommandService.registerActivities(
member, request);
final List<String> activityNames = memberActivities.stream()
.filter(MemberActivity::isJobActivity)
.map(MemberActivity::getActivityName)
.collect(Collectors.toList());
interestTagService.initializeInterestTags(member, activityNames);

member.updateName(request.getName());
}

public void updateDescription(final Member member, final DescriptionRequest descriptionRequest) {
final String description = descriptionRequest.getDescription();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.emmsale.member.domain;

import com.emmsale.activity.domain.Activity;
import com.emmsale.activity.domain.ActivityType;
import com.emmsale.base.BaseEntity;
import javax.persistence.Entity;
import javax.persistence.FetchType;
Expand Down Expand Up @@ -34,4 +35,12 @@ public MemberActivity(final Activity activity, final Member member) {
this.activity = activity;
this.member = member;
}

public String getActivityName() {
return activity.getName();
}

public Boolean isJobActivity() {
return activity.getActivityType() == ActivityType.JOB;
}
}
Loading
Loading