Skip to content
Merged
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
@@ -1,6 +1,7 @@
package umc.th.juinjang.api.limjang.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -63,13 +64,34 @@ public UserNotesShareableGetResponse findNotesShareable(Member member) {
List<Limjang> filteredSharedNotes = findUnsharedSharableNotes(member);
List<Image> imageList = imageFinder.findAllFirstCreatedImagePerNote(filteredSharedNotes);

// 예상 리워드 판별
Map<Long, Long> mapToExpectedReward = mapInCalculateReward(filteredSharedNotes);

return UserNotesShareableGetResponse.of(filteredSharedNotes, mapToNoteIdAndImageId(imageList),
mapToNoteScrapStatus(filteredSharedNotes));
mapToNoteScrapStatus(filteredSharedNotes), mapToExpectedReward);
}

private Map<Long, Long> mapInCalculateReward(List<Limjang> notes) {
Set<Long> noteIdsWithPastSharedHistory =
sharedNoteFinder.findLimjangIdsByDeletedAtIsNotNullAndLimjang(notes);

Map<Long, Long> mapToExpectedRewardPencil = new HashMap<>();
for (Limjang note : notes) {
mapToExpectedRewardPencil.put(note.getLimjangId(), calculateReward(note, noteIdsWithPastSharedHistory));
}
return mapToExpectedRewardPencil;
}

private Long calculateReward(Limjang note, Set<Long> previouslySharedNoteIds) {
if (previouslySharedNoteIds.contains(note.getLimjangId()))
return null;
return note.getImageList().isEmpty() ? 2L : 7L;
}

private List<Limjang> findUnsharedSharableNotes(Member member) {
List<Limjang> notes = noteFinder.getAllByMemberWithAddressAndNotePriceWhereIsSharableIsTrueAndDeletedIsFalseAndAddressBcodeIsNotNull(
member);
// 이미 공유 중인 임장들 필터링
Set<Long> noteIdInSharedNotes = sharedNoteFinder.findLimjangIdsByDeletedAtIsNullAndLimjang(notes);

return notes.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ record UserNoteShareableResponse(
String monthlyRent,
Integer pyong,
String floor,
String shortAddress
String shortAddress,
Long rewardPencil
) {

static UserNoteShareableResponse of(Limjang limjang, String imageUrl, boolean isScraped) {
static UserNoteShareableResponse of(Limjang limjang, String imageUrl, boolean isScraped, Long rewardPencil) {
return new UserNoteShareableResponse(
limjang.getLimjangId(), limjang.getPurpose(), limjang.getPropertyType(), limjang.getPriceType(),
limjang.getNickname(),
Expand All @@ -39,17 +40,18 @@ static UserNoteShareableResponse of(Limjang limjang, String imageUrl, boolean is
null,
limjang.getPyong(),
limjang.getFloor(),
limjang.getAddressEntity().getShortAddress()
limjang.getAddressEntity().getShortAddress(),
rewardPencil
);
}
}

public static UserNotesShareableGetResponse of(List<Limjang> limjangs, Map<Long, String> imageUrl,
Map<Long, Boolean> isScraped) {
Map<Long, Boolean> isScraped, Map<Long, Long> expectedReward) {
return new UserNotesShareableGetResponse(
limjangs.stream()
.map(it -> UserNoteShareableResponse.of(it, imageUrl.get(it.getLimjangId()),
isScraped.get(it.getLimjangId())))
isScraped.get(it.getLimjangId()), expectedReward.get(it.getLimjangId())))
.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ public boolean existsByDeletedAtIsNullAndLimjang(Limjang limjang) {
public Set<Long> findLimjangIdsByDeletedAtIsNullAndLimjang(List<Limjang> notes) {
return sharedNoteRepository.findLimjangIdsByDeletedAtIsNullAndLimjang(notes);
}

public Set<Long> findLimjangIdsByDeletedAtIsNotNullAndLimjang(List<Limjang> notes) {
return sharedNoteRepository.findLimjangIdsByDeletedAtIsNotNullAndLimjang(notes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public interface SharedNoteRepository extends JpaRepository<SharedNote, Long>, S

@Query("SELECT s.limjang.limjangId FROM SharedNote s WHERE s.limjang in :limjangs AND s.deletedAt is null")
Set<Long> findLimjangIdsByDeletedAtIsNullAndLimjang(@Param("limjangs") List<Limjang> limjangs);

@Query("SELECT s.limjang.limjangId FROM SharedNote s WHERE s.limjang in :limjangs AND s.deletedAt is not null")
Set<Long> findLimjangIdsByDeletedAtIsNotNullAndLimjang(@Param("limjangs") List<Limjang> limjangs);
}