Skip to content

Commit d10d42e

Browse files
Merge pull request #407 from Juinjang/fix/#406
[fix/#406] 조회수 NPE fix
2 parents 0796d68 + 5953760 commit d10d42e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/java/umc/th/juinjang/api/note/shared/service/ViewCountService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public Long getRedisViewCount(long sharedNoteId) {
5454

5555
if (value == null) {
5656
Long viewCountFromDb = sharedNoteFinder.findViewCountById(sharedNoteId);
57+
58+
if (viewCountFromDb == null) {
59+
log.warn("DB의 sharedNote 조회수가 null sharedNoteId={}", sharedNoteId);
60+
viewCountFromDb = 0L;
61+
}
62+
5763
redisTemplate.opsForValue().set(key, viewCountFromDb.toString());
5864
return viewCountFromDb;
5965
}

src/main/java/umc/th/juinjang/domain/note/shared/model/SharedNote.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ public static SharedNote toSharedNote(Member member, Limjang limjang, SharedNote
8383
.month(dto.month())
8484
.period(dto.period())
8585
.isImageShared(dto.isImageShared())
86+
.viewCount(0L)
8687
.build();
8788
}
8889

8990
public void updatePrice(long price) {
9091
this.price = price;
9192
}
93+
9294
public void updateDeletedAt(Timestamp deletedAt) {
9395
this.deletedAt = deletedAt;
9496
}

0 commit comments

Comments
 (0)