1313import com .example .log4u .domain .diary .dto .PopularDiaryDto ;
1414import com .example .log4u .domain .diary .entity .Diary ;
1515import com .example .log4u .domain .diary .service .DiaryService ;
16+ import com .example .log4u .domain .diary .service .DiaryGeohashService ;
1617import com .example .log4u .domain .hashtag .service .HashtagService ;
1718import com .example .log4u .domain .like .service .LikeService ;
1819import com .example .log4u .domain .map .service .MapService ;
@@ -33,6 +34,7 @@ public class DiaryFacade {
3334 private final LikeService likeService ;
3435 private final HashtagService hashtagService ;
3536 private final UserService userService ;
37+ private final DiaryGeohashService diaryGeohashService ;
3638
3739 /**
3840 * 다이어리 생성 use case
@@ -41,23 +43,30 @@ public class DiaryFacade {
4143 * 2. diaryService: 다이어리 생성<br>
4244 * 2. mediaService: 해당 다이어리의 이미지 저장<br>
4345 * 3. mapService: 해당 구역 카운트 증가
46+ * 4. diaryGeohashService: 해당 다이어리 위치가 포함되어있는 geoHash 문자열 저장
4447 * */
4548 @ Transactional
4649 public void createDiary (Long userId , DiaryRequestDto request ) {
4750 String thumbnailUrl = mediaService .extractThumbnailUrl (request .mediaList ());
4851 Diary diary = diaryService .saveDiary (userId , request , thumbnailUrl );
4952 mediaService .saveMedia (diary .getDiaryId (), request .mediaList ());
5053 hashtagService .saveOrUpdateHashtag (diary .getDiaryId (), request .hashtagList ());
51- mapService .increaseRegionDiaryCount (request .location ().latitude (), request .location ().longitude ());
54+
55+ double lat = request .location ().latitude ();
56+ double lon = request .location ().longitude ();
57+ mapService .increaseRegionDiaryCount (lat , lon );
58+ diaryGeohashService .saveGeohash (diary .getDiaryId (), lat , lon );
5259 }
5360
5461 /**
5562 * 다이어리 삭제 use case
5663 * <ul><li>호출 과정</li></ul>
5764 * 1. diaryService: 다이어리 검증
5865 * 2. mediaService: 해당 다이어리 이미지 삭제<br>
59- * 3. diaryService: 다이어리 삭제<br>
60- * 4. mapService: 해당 구역 카운트 감소
66+ * 3. mapService: 해당 구역 카운트 감소
67+ * 4. diaryGeohashService: 캐싱 되어있는 id, 데이터 삭제
68+ * 5. diaryService: 다이어리 삭제<br>
69+ *
6170 * */
6271 @ Transactional
6372 public void deleteDiary (Long userId , Long diaryId ) {
@@ -66,6 +75,7 @@ public void deleteDiary(Long userId, Long diaryId) {
6675 hashtagService .deleteHashtagsByDiaryId (diaryId );
6776 mapService .decreaseRegionDiaryCount (diary .getLocation ().getLatitude (), diary .getLocation ().getLongitude ());
6877
78+ diaryGeohashService .deleteGeohashAndCache (diaryId );
6979 diaryService .deleteDiary (diary );
7080 }
7181
0 commit comments