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

[fix] : bookmark 카운트가 bookmark한 대상에게 증가하는 버그 수정 #399

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -65,6 +65,8 @@ internal class GalleryServiceTest(

describe("getGalleries 메소드는") {
beforeEach {
galleryRepository.deleteAll()

galleryService.registerGallery(oldDesignerGallery)
galleryService.registerGallery(midDeveloperGallery)
galleryService.registerGallery(latestPmGallery)
Expand Down Expand Up @@ -150,6 +152,33 @@ internal class GalleryServiceTest(
}
}
}

describe("increaseBookmarkCount 메소드는") {
context("targetId를 입력받으면,") {
galleryService.registerGallery(defaultGallery)
galleryService.increaseBookmarkCount(EXIST_TARGET_ID)

it("targetId에 해당하는 target gallery의 bookmarked count를 증가시킨다.") {
val gallery = galleryService.getGalleryByTargetId(EXIST_TARGET_ID)

gallery.getBookmarkedCount() shouldBeEqual 1
}
}
}

describe("decreaseBookmarkCount 메소드는") {
context("targetId를 입력받으면,") {
galleryService.registerGallery(defaultGallery)
galleryService.increaseBookmarkCount(EXIST_TARGET_ID)
galleryService.decreaseBookmarkCount(EXIST_TARGET_ID)

it("targetId에 해당하는 target gallery의 bookmarked count를 감소 시킨다.") {
val gallery = galleryService.getGalleryByTargetId(EXIST_TARGET_ID)

gallery.getBookmarkedCount() shouldBeEqual 0
}
}
}
}) {

companion object {
Expand All @@ -162,6 +191,15 @@ internal class GalleryServiceTest(
val bookmarkPage: PageRequest =
PageRequest.of(0, 5, Sort.by("survey.bookmarkedCount").descending())

val defaultGallery = gallery(
id = EXIST_GALLERY_ID,
targetId = EXIST_TARGET_ID,
surveyId = EXIST_SURVEY_ID,
job = Job.DESIGNER,
updateOrder = TimeUtil.toInstant().minus(1, ChronoUnit.DAYS),
bookmarkedCount = 0
)

val oldDesignerGallery = gallery(
id = 1,
targetId = 101,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import lombok.RequiredArgsConstructor;
import me.nalab.survey.application.exception.SurveyDoesNotExistException;
import me.nalab.survey.application.exception.TargetDoesNotHasSurveyException;
import me.nalab.survey.application.port.in.web.bookmark.SurveyBookmarkUseCase;
import me.nalab.survey.application.port.out.persistence.bookmark.SurveyBookmarkListenPort;
import me.nalab.survey.application.port.out.persistence.bookmark.SurveyBookmarkPort;
import me.nalab.survey.application.port.out.persistence.findfeedback.SurveyExistCheckPort;
import me.nalab.survey.application.port.out.persistence.findtarget.TargetFindPort;
import me.nalab.survey.application.port.out.persistence.findtarget.TargetIdFindPort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -15,6 +17,7 @@
public class SurveyBookmarkService implements SurveyBookmarkUseCase {

private final TargetFindPort targetFindPort;
private final TargetIdFindPort targetIdFindPort;
private final SurveyExistCheckPort surveyExistCheckPort;
private final SurveyBookmarkPort surveyBookmarkPort;
private final SurveyBookmarkListenPort surveyBookmarkListener;
Expand All @@ -28,10 +31,13 @@ public void bookmark(Long targetId, Long surveyId) {
throw new SurveyDoesNotExistException(surveyId);
}

target.bookmark(surveyId);
var bookmarkSuccess = target.bookmark(surveyId);
if (bookmarkSuccess) {
var bookmarkTargetId = targetIdFindPort.findTargetIdBySurveyId(surveyId)
.orElseThrow(() -> new TargetDoesNotHasSurveyException(surveyId));
surveyBookmarkListener.increaseBookmarked(bookmarkTargetId);
}
surveyBookmarkPort.updateBookmark(target);

surveyBookmarkListener.increaseBookmarked(targetId);
}

@Override
Expand All @@ -43,9 +49,12 @@ public void cancelBookmark(Long targetId, Long surveyId) {
throw new SurveyDoesNotExistException(surveyId);
}

target.cancelBookmark(surveyId);
var cancelSuccess = target.cancelBookmark(surveyId);
if (cancelSuccess) {
var bookmarkTargetId = targetIdFindPort.findTargetIdBySurveyId(surveyId)
.orElseThrow(() -> new TargetDoesNotHasSurveyException(surveyId));
surveyBookmarkListener.decreaseBookmarked(bookmarkTargetId);
}
surveyBookmarkPort.updateBookmark(target);
dojinyou marked this conversation as resolved.
Show resolved Hide resolved

surveyBookmarkListener.decreaseBookmarked(targetId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.LongSupplier;
import lombok.Builder;
Expand Down Expand Up @@ -42,15 +41,21 @@ public void setPosition(String position) {
this.position = position;
}

public void bookmark(Long surveyId) {
public boolean bookmark(Long surveyId) {
var bookmark = new SurveyBookmark(surveyId);
if (bookmarkedSurveys.contains(bookmark)) {
return false;
}
bookmarkedSurveys.add(bookmark);
return true;
}

public void cancelBookmark(Long surveyId) {
bookmarkedSurveys.stream()
.filter(surveyBookmark -> Objects.equals(surveyBookmark.surveyId(), surveyId))
.findFirst()
.ifPresent(bookmarkedSurveys::remove);
public boolean cancelBookmark(Long surveyId) {
var canceledBookmark = new SurveyBookmark(surveyId);
if (bookmarkedSurveys.contains(canceledBookmark)) {
bookmarkedSurveys.remove(canceledBookmark);
return true;
}
return false;
}
}
Loading