Skip to content

Commit

Permalink
[refactor]: Refactor Wish Service
Browse files Browse the repository at this point in the history
- Query/Command Adapter 적용
- Private/Team Exception 추가
  • Loading branch information
oznchex committed Sep 20, 2024
1 parent 771887b commit 7c83835
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 200 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package liaison.linkit.profile.business;

public class ProfileMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package liaison.linkit.profile.exception;

import static liaison.linkit.common.consts.LinkitStatic.NOT_FOUND;

import java.lang.reflect.Field;
import java.util.Objects;
import liaison.linkit.common.annotation.ExplainError;
import liaison.linkit.common.exception.BaseErrorCode;
import liaison.linkit.common.exception.ErrorReason;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ProfileErrorCode implements BaseErrorCode {
PROFILE_NOT_FOUND(NOT_FOUND, "PROFILE_404_1", "프로필을 찾을 수 없습니다.");

private final Integer status;
private final String code;
private final String reason;

@Override
public ErrorReason getErrorReason() {
return ErrorReason.builder().reason(reason).code(code).status(status).build();
}

@Override
public String getExplainError() throws NoSuchFieldException {
Field field = this.getClass().getField(this.name());
ExplainError annotation = field.getAnnotation(ExplainError.class);
return Objects.nonNull(annotation) ? annotation.value() : this.getReason();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package liaison.linkit.profile.exception;

import liaison.linkit.common.exception.BaseCodeException;

public class ProfileNotFoundException extends BaseCodeException {
public static BaseCodeException EXCEPTION = new ProfileNotFoundException();

private ProfileNotFoundException() {
super(ProfileErrorCode.PROFILE_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package liaison.linkit.profile.implement;

public class ProfileCommandAdapter {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package liaison.linkit.profile.implement;

import liaison.linkit.common.annotation.Adapter;
import liaison.linkit.profile.domain.Profile;
import liaison.linkit.profile.domain.repository.profile.ProfileRepository;
import liaison.linkit.profile.exception.ProfileNotFoundException;
import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class ProfileQueryAdapter {
private final ProfileRepository profileRepository;

public Profile findById(final Long profileId) {
return profileRepository.findById(profileId)
.orElseThrow(() -> ProfileNotFoundException.EXCEPTION);
}

public Profile findByMemberId(final Long memberId) {
return profileRepository.findByMemberId(memberId)
.orElseThrow(() -> ProfileNotFoundException.EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ public MiniProfileResponse getPersonalMiniProfile(final Long memberId) {
final List<String> jobRoleNames = getJobRoleNames(memberId);
log.info("대상 객체의 희망 직무 및 역할을 조회하였습니다.");

return MiniProfileResponse.personalMiniProfile(miniProfile, miniProfileKeywordList, memberBasicInform.getMemberName(), jobRoleNames);
return MiniProfileResponse.personalMiniProfile(miniProfile, miniProfileKeywordList,
memberBasicInform.getMemberName(), jobRoleNames);
}

@Transactional(readOnly = true)
Expand All @@ -213,9 +214,11 @@ public MiniProfileResponse getBrowsePersonalMiniProfile(final Long memberId, fin
final List<String> jobRoleNames = getJobRoleNames(profile.getMember().getId());
log.info("대상 객체의 희망 직무 및 역할을 조회하였습니다.");

final boolean isPrivateSaved = privateWishRepository.findByMemberIdAndProfileId(memberId, miniProfile.getProfile().getId());
final boolean isPrivateSaved = privateWishRepository.existsByMemberIdAndProfileId(memberId,
miniProfile.getProfile().getId());

return MiniProfileResponse.personalBrowseMiniProfile(miniProfile, miniProfileKeywordList, memberBasicInform.getMemberName(), jobRoleNames, isPrivateSaved);
return MiniProfileResponse.personalBrowseMiniProfile(miniProfile, miniProfileKeywordList,
memberBasicInform.getMemberName(), jobRoleNames, isPrivateSaved);
}

private List<ProfileJobRole> getProfileJobRoleList(final Long profileId) {
Expand All @@ -228,12 +231,12 @@ private List<MiniProfileKeyword> getMiniProfileKeywords(final Long miniProfileId


private boolean getSavedImageUrl(final Profile profile) {
final MiniProfile miniProfile = getMiniProfile(profile.getId());
if (miniProfile.getMiniProfileImg() != null) {
return true;
} else {
return false;
}
final MiniProfile miniProfile = getMiniProfile(profile.getId());
if (miniProfile.getMiniProfileImg() != null) {
return true;
} else {
return false;
}
}

// 나중에 리팩토링 필요한 부분
Expand Down Expand Up @@ -282,7 +285,7 @@ public List<String> getJobRoleNames(final Long memberId) {

public boolean getIsPrivateSaved(final Long memberId, final Long profileId) {
final MiniProfile miniProfile = getMiniProfile(profileId);
return privateWishRepository.findByMemberIdAndProfileId(memberId, miniProfile.getProfile().getId());
return privateWishRepository.existsByMemberIdAndProfileId(memberId, miniProfile.getProfile().getId());
}

// 미니 프로필의 유효성 검증이 끝난 후 수정한다.
Expand Down
71 changes: 45 additions & 26 deletions src/main/java/liaison/linkit/search/service/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public Page<MiniProfileResponse> findPrivateMiniProfile(
log.info("cityName={}", cityName);
log.info("divisionName={}", divisionName);

final Long teamBuildingFieldCount = (teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long teamBuildingFieldCount =
(teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long jobRoleCount = (jobRoleName != null) ? (long) jobRoleName.size() : null;
final Long skillCount = (skillName != null) ? (long) skillName.size() : null;

Expand Down Expand Up @@ -121,7 +122,8 @@ public Page<BrowseMiniProfileResponse> findPrivateMiniProfileLogin(
String divisionName
) {

final Long teamBuildingFieldCount = (teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long teamBuildingFieldCount =
(teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long jobRoleCount = (jobRoleName != null) ? (long) jobRoleName.size() : null;
final Long skillCount = (skillName != null) ? (long) skillName.size() : null;

Expand Down Expand Up @@ -162,12 +164,12 @@ public Page<SearchTeamProfileResponse> findTeamMemberAnnouncementsWithTeamMiniPr
// 해당 팀원 공고들을 찾는다.
// 해당 팀원 공고와 연결된 팀 미니 프로필을 같이 반환한다.

final Long teamBuildingFieldCount = (teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long teamBuildingFieldCount =
(teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long jobRoleCount = (jobRoleName != null) ? (long) jobRoleName.size() : null;
final Long skillCount = (skillName != null) ? (long) skillName.size() : null;
final Long activityTagCount = (activityTagName != null) ? (long) activityTagName.size() : null;


// 해당되는 모든 팀원 공고를 조회한다.
Page<TeamMemberAnnouncement> teamMemberAnnouncements = teamMemberAnnouncementRepository.findAllByOrderByCreatedDateDesc(
teamBuildingFieldName,
Expand Down Expand Up @@ -198,7 +200,8 @@ public Page<SearchBrowseTeamProfileResponse> findTeamMemberAnnouncementsWithTeam
String divisionName,
final List<String> activityTagName
) {
final Long teamBuildingFieldCount = (teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long teamBuildingFieldCount =
(teamBuildingFieldName != null) ? (long) teamBuildingFieldName.size() : null;
final Long jobRoleCount = (jobRoleName != null) ? (long) jobRoleName.size() : null;
final Long skillCount = (skillName != null) ? (long) skillName.size() : null;
final Long activityTagCount = (activityTagName != null) ? (long) activityTagName.size() : null;
Expand All @@ -217,40 +220,54 @@ public Page<SearchBrowseTeamProfileResponse> findTeamMemberAnnouncementsWithTeam
activityTagCount,
pageable
);
return teamMemberAnnouncements.map(teamMemberAnnouncement -> convertToSearchTeamProfileResponseAfterLogin(teamMemberAnnouncement, memberId));
return teamMemberAnnouncements.map(
teamMemberAnnouncement -> convertToSearchTeamProfileResponseAfterLogin(teamMemberAnnouncement,
memberId));
}


private SearchTeamProfileResponse convertToSearchTeamProfileResponse(final TeamMemberAnnouncement teamMemberAnnouncement) {
private SearchTeamProfileResponse convertToSearchTeamProfileResponse(
final TeamMemberAnnouncement teamMemberAnnouncement) {
// 각각의 개별 팀원 공고를 찾아냈다.
final TeamMiniProfile teamMiniProfile = getTeamMiniProfileByTeamProfileId(teamMemberAnnouncement.getTeamProfile().getId());
final List<TeamMiniProfileKeyword> teamMiniProfileKeyword = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(teamMiniProfile.getId());

final TeamMemberAnnouncementJobRole teamMemberAnnouncementJobRole = getTeamMemberAnnouncementJobRole(teamMemberAnnouncement.getId());
final List<TeamMemberAnnouncementSkill> teamMemberAnnouncementSkillList = getTeamMemberAnnouncementSkills(teamMemberAnnouncement.getId());
final TeamMiniProfile teamMiniProfile = getTeamMiniProfileByTeamProfileId(
teamMemberAnnouncement.getTeamProfile().getId());
final List<TeamMiniProfileKeyword> teamMiniProfileKeyword = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(
teamMiniProfile.getId());

final TeamMemberAnnouncementJobRole teamMemberAnnouncementJobRole = getTeamMemberAnnouncementJobRole(
teamMemberAnnouncement.getId());
final List<TeamMemberAnnouncementSkill> teamMemberAnnouncementSkillList = getTeamMemberAnnouncementSkills(
teamMemberAnnouncement.getId());
final String teamName = teamMemberAnnouncement.getTeamProfile().getTeamMiniProfile().getTeamName();


return new SearchTeamProfileResponse(
TeamMiniProfileResponse.personalTeamMiniProfile(teamMiniProfile, teamMiniProfileKeyword),
TeamMemberAnnouncementResponse.of(
teamMiniProfile.getTeamLogoImageUrl(), teamMemberAnnouncement, teamName, teamMemberAnnouncementJobRole, teamMemberAnnouncementSkillList)
teamMiniProfile.getTeamLogoImageUrl(), teamMemberAnnouncement, teamName,
teamMemberAnnouncementJobRole, teamMemberAnnouncementSkillList)
);
}

private SearchBrowseTeamProfileResponse convertToSearchTeamProfileResponseAfterLogin(final TeamMemberAnnouncement teamMemberAnnouncement, final Long memberId) {
final TeamMiniProfile teamMiniProfile = getTeamMiniProfileByTeamProfileId(teamMemberAnnouncement.getTeamProfile().getId());
final List<TeamMiniProfileKeyword> teamMiniProfileKeyword = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(teamMiniProfile.getId());

final TeamMemberAnnouncementJobRole teamMemberAnnouncementJobRole = getTeamMemberAnnouncementJobRole(teamMemberAnnouncement.getId());
final List<TeamMemberAnnouncementSkill> teamMemberAnnouncementSkillList = getTeamMemberAnnouncementSkills(teamMemberAnnouncement.getId());
private SearchBrowseTeamProfileResponse convertToSearchTeamProfileResponseAfterLogin(
final TeamMemberAnnouncement teamMemberAnnouncement, final Long memberId) {
final TeamMiniProfile teamMiniProfile = getTeamMiniProfileByTeamProfileId(
teamMemberAnnouncement.getTeamProfile().getId());
final List<TeamMiniProfileKeyword> teamMiniProfileKeyword = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(
teamMiniProfile.getId());

final TeamMemberAnnouncementJobRole teamMemberAnnouncementJobRole = getTeamMemberAnnouncementJobRole(
teamMemberAnnouncement.getId());
final List<TeamMemberAnnouncementSkill> teamMemberAnnouncementSkillList = getTeamMemberAnnouncementSkills(
teamMemberAnnouncement.getId());
final String teamName = teamMemberAnnouncement.getTeamProfile().getTeamMiniProfile().getTeamName();
final boolean isTeamSaved = teamWishRepository.findByTeamMemberAnnouncementIdAndMemberId(teamMemberAnnouncement.getId(), memberId);
final boolean isTeamSaved = teamWishRepository.existsByTeamMemberAnnouncementIdAndMemberId(
teamMemberAnnouncement.getId(), memberId);
log.info("isTeamSaved={}", isTeamSaved);

return new SearchBrowseTeamProfileResponse(
TeamMiniProfileResponse.personalTeamMiniProfile(teamMiniProfile, teamMiniProfileKeyword),
TeamMemberAnnouncementResponse.afterLogin(teamMiniProfile.getTeamLogoImageUrl(), teamMemberAnnouncement, teamName, teamMemberAnnouncementJobRole, teamMemberAnnouncementSkillList, isTeamSaved)
TeamMemberAnnouncementResponse.afterLogin(teamMiniProfile.getTeamLogoImageUrl(), teamMemberAnnouncement,
teamName, teamMemberAnnouncementJobRole, teamMemberAnnouncementSkillList, isTeamSaved)
);
}

Expand Down Expand Up @@ -282,7 +299,8 @@ public Page<TeamMiniProfileResponse> findTeamMiniProfile(
}

private TeamMiniProfileResponse convertToTeamMiniProfileResponse(final TeamMiniProfile teamMiniProfile) {
List<String> teamKeywordNames = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(teamMiniProfile.getId()).stream()
List<String> teamKeywordNames = teamMiniProfileKeywordRepository.findAllByTeamMiniProfileId(
teamMiniProfile.getId()).stream()
.map(TeamMiniProfileKeyword::getTeamKeywordNames)
.toList();

Expand Down Expand Up @@ -327,7 +345,8 @@ private MiniProfileResponse convertToMiniProfileResponse(final MiniProfile miniP
);
}

private BrowseMiniProfileResponse convertToBrowseMiniProfileResponse(final MiniProfile miniProfile, final Long memberId) {
private BrowseMiniProfileResponse convertToBrowseMiniProfileResponse(final MiniProfile miniProfile,
final Long memberId) {
final String memberName = getMemberNameByMiniProfile(miniProfile.getId());
List<String> myKeywordNames = miniProfileKeywordRepository.findAllByMiniProfileId(miniProfile.getId()).stream()
.map(MiniProfileKeyword::getMyKeywordNames)
Expand All @@ -343,7 +362,8 @@ private BrowseMiniProfileResponse convertToBrowseMiniProfileResponse(final MiniP
.toList();

// privateWish -> 찾아야함 (내가 이 해당 미니 프로필을 찜해뒀는지?)
final boolean isPrivateWish = privateWishRepository.findByMemberIdAndProfileId(memberId, miniProfile.getProfile().getId());
final boolean isPrivateWish = privateWishRepository.existsByMemberIdAndProfileId(memberId,
miniProfile.getProfile().getId());

return new BrowseMiniProfileResponse(
miniProfile.getId(),
Expand Down Expand Up @@ -381,7 +401,6 @@ private Profile getProfileIdByMiniProfile(final Long miniProfileId) {
// 회원 기본 정보를 가져오는 메서드
private MemberBasicInform getMemberBasicInform(final Long memberId) {


return memberBasicInformRepository.findByMemberId(memberId)
.orElseThrow(() -> new BadRequestException(NOT_FOUND_MEMBER_BASIC_INFORM_BY_MEMBER_ID));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public PrivateWish toPrivate(final Profile profile, final Member member) {
public PrivateWishResponseDTO.AddPrivateWish toAddPrivateWish() {
return PrivateWishResponseDTO.AddPrivateWish.builder().build();
}

public PrivateWishResponseDTO.RemovePrivateWish toRemovePrivateWish() {
return PrivateWishResponseDTO.RemovePrivateWish.builder().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public TeamWish toTeam(final TeamMemberAnnouncement teamMemberAnnouncement, fina
public TeamWishResponseDTO.AddTeamWish toAddTeamWish() {
return TeamWishResponseDTO.AddTeamWish.builder().build();
}

public TeamWishResponseDTO.RemoveTeamWish toRemoveTeamWish() {
return TeamWishResponseDTO.RemoveTeamWish.builder()
.build();
}
}
Loading

0 comments on commit 7c83835

Please sign in to comment.