Skip to content

Commit

Permalink
GETP-185 fix: 피플 프로필이 미등록 상태임에도 등록할 수 없는 오류 수정 (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
scv1702 committed Aug 13, 2024
1 parent f305f1c commit 0245bfe
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import es.princip.getp.infra.support.QueryDslSupport;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

Expand All @@ -22,7 +23,9 @@ public Long countByLikedId(Long likedId) {

@Override
public Map<Long, Long> countByLikedIds(Long... likedIds) {
return queryFactory.select(peopleLike.likedId, peopleLike.count())
final Map<Long, Long> counts = Arrays.stream(likedIds)
.collect(toMap(id -> id, id -> 0L));
final Map<Long, Long> result = queryFactory.select(peopleLike.likedId, peopleLike.count())
.from(peopleLike)
.where(peopleLike.likedId.in(likedIds))
.groupBy(peopleLike.likedId)
Expand All @@ -35,5 +38,7 @@ public Map<Long, Long> countByLikedIds(Long... likedIds) {
.orElse(0L)
)
);
counts.putAll(result);
return counts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import es.princip.getp.infra.support.QueryDslSupport;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

Expand All @@ -23,7 +24,9 @@ public Long countByLikedId(final Long projectId) {

@Override
public Map<Long, Long> countByLikedIds(final Long... likedIds) {
return queryFactory.select(projectLike.likedId, projectLike.count())
final Map<Long, Long> counts = Arrays.stream(likedIds)
.collect(toMap(id -> id, id -> 0L));
final Map<Long, Long> result = queryFactory.select(projectLike.likedId, projectLike.count())
.from(projectLike)
.where(projectLike.likedId.in(likedIds))
.groupBy(projectLike.likedId)
Expand All @@ -36,5 +39,7 @@ public Map<Long, Long> countByLikedIds(final Long... likedIds) {
.orElse(0L)
)
);
counts.putAll(result);
return counts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import es.princip.getp.domain.like.command.domain.Likeable;
import es.princip.getp.domain.member.command.domain.model.Email;
import es.princip.getp.domain.people.exception.AlreadyRegisteredPeopleProfileException;
import es.princip.getp.domain.people.exception.NotRegisteredPeopleProfileException;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
Expand Down Expand Up @@ -60,10 +61,13 @@ public void registerProfile(final PeopleProfileData data) {
}

public boolean isProfileRegistered() {
return this.profile != null;
return this.profile != null && this.profile.isRegistered();
}

public void editProfile(final PeopleProfileData data) {
if (!isProfileRegistered()) {
throw new NotRegisteredPeopleProfileException();
}
this.profile = buildProfile(data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ public List<TechStack> getTechStacks() {
public List<Portfolio> getPortfolios() {
return Collections.unmodifiableList(portfolios);
}

public boolean isRegistered() {
return this.introduction != null || this.activityArea != null || this.education != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class NotRegisteredPeopleProfileException extends BusinessLogicException {

private static final String code = "NOT_REGISTERED_PEOPLE_PROFILE";
private static final String message = "프로젝트에 지원하려면 피플 프로필을 등록해야 합니다.";
private static final String message = "프로필을 먼저 등록해주세요.";

public NotRegisteredPeopleProfileException() {
super(ErrorDescription.of(code, message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import es.princip.getp.domain.like.query.infra.PeopleLikeDaoConfig;
import es.princip.getp.infra.support.DaoTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
Expand All @@ -24,16 +23,13 @@ public PeopleLikeDaoTest() {
@Autowired
private PeopleLikeDao peopleLikeDao;


@Test
@DisplayName("피플이 받은 좋아요 수를 조회한다.")
void countByLikedId() {
void 피플_ID_대해_피플이_받은_좋아요_수를_조회한다() {
assertThat(peopleLikeDao.countByLikedId(1L)).isEqualTo(TEST_SIZE);
}

@Test
@DisplayName("피플이 받은 좋아요 수를 조회한다.")
void countByLikedIds() {
void 여러개의_피플_ID_대해_피플이_받은_좋아요_수를_조회한다() {
final Long[] peopleIds = LongStream.rangeClosed(1, TEST_SIZE)
.boxed()
.toArray(Long[]::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package es.princip.getp.domain.like.query.dao;

import es.princip.getp.domain.like.query.infra.PeopleLikeDaoConfig;
import es.princip.getp.infra.support.DaoTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;

import java.util.Map;
import java.util.stream.LongStream;

import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
@Import(PeopleLikeDaoConfig.class)
public class ZeroTestSizePeopleLikeDaoTest extends DaoTest {

public ZeroTestSizePeopleLikeDaoTest() {
super(0);
}

@Autowired
private PeopleLikeDao peopleLikeDao;

@Test
void 피플_ID_대해_피플이_받은_좋아요_수를_조회한다() {
assertThat(peopleLikeDao.countByLikedId(1L)).isEqualTo(0);
}

@Test
void 여러개의_피플_ID_대해_피플이_받은_좋아요_수를_조회한다() {
final Long[] peopleIds = LongStream.rangeClosed(1, 10)
.boxed()
.toArray(Long[]::new);
final Map<Long, Long> likesCounts = peopleLikeDao.countByLikedIds(peopleIds);
assertThat(likesCounts).hasSize(peopleIds.length)
.containsOnlyKeys(peopleIds)
.containsValues(Long.valueOf(0));
}
}

0 comments on commit 0245bfe

Please sign in to comment.