Skip to content

Commit

Permalink
Feat: CHAT-231-BE-일기상세조회-캐릭터인덱스추가 (#46)
Browse files Browse the repository at this point in the history
* Feat: CHAT-231-BE-일기상세조회-이미지추가

응답에 조회일에 가장 채팅을 많이한 캐릭터의 인덱스 추가 (DADA:1, CHICHI: 2, LULU:3)

* Fix: photo의 imageUrl, Member의 email 타입을 text로 변경

응답에 조회일에 가장 채팅을 많이한 캐릭터의 인덱스 추가 (DADA:1, CHICHI: 2, LULU:3)

* Fix: 리뷰 반영

같은 수의 채팅이 있을경우, 최근 채팅 캐릭터 인덱스 반환.
없는 일기 조회시 오류 생성

* Fix: 다이어리는 있지만 태그는 없을때 나눠서 구현

* Fix: 다이어리 존재하지 않을때 404오류 발생

* Fix: @column(columnDefinition = "TEXT") 삭제

TEXT형식이 아니라 varchar로 생성됩니다.
  • Loading branch information
dainshon authored Feb 10, 2024
1 parent b504edd commit 8b95fb2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DiaryController {


@GetMapping("/detail")
public ResponseEntity<DiaryShowDetailResponseDTO> showDiary(@RequestParam(name="user_id") Long userId, @RequestParam(name="diary_date") Date diaryDate) throws ParseException, ParseException {
public ResponseEntity<DiaryShowDetailResponseDTO> showDiary(@RequestParam(name="user_id") Long userId, @RequestParam(name="diary_date") Date diaryDate) throws Exception {
log.info("[DiaryController.showDiary]");

return ResponseEntity.ok().body(diaryService.showDiary(userId,diaryDate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class DiaryShowDetailResponseDTO {

private String title;

//private String imgUrl;
private List<String> imgUrl;

private String content;

//private String tagName;
private List<String> tagName;

private Long CharacterIndex;

}
24 changes: 22 additions & 2 deletions src/main/java/com/kuit/chatdiary/repository/DiaryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Repository;
import org.springframework.web.server.ResponseStatusException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -22,7 +26,7 @@ public class DiaryRepository {

private final EntityManager em;

public DiaryShowDetailResponseDTO showDiaryDetail (Long userId, java.sql.Date diaryDate) {
public DiaryShowDetailResponseDTO showDiaryDetail (Long userId, java.sql.Date diaryDate) throws Exception {

log.info("[DiaryRepository.showDiaryDetail]");

Expand All @@ -33,12 +37,17 @@ public DiaryShowDetailResponseDTO showDiaryDetail (Long userId, java.sql.Date di
List<Object[]> resultList = em.createQuery("SELECT d.diaryId, d.title, d.content FROM diary d WHERE d.member.userId = :user_id AND d.diaryDate = :diary_date")
.setParameter("user_id", userId).setParameter("diary_date", diaryDate).getResultList();

if(resultList.size()==0){
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}

for(Object[] result : resultList){
diaryId = (Long) result[0];
title = (String) result[1];
content = (String) result[2];
}


List<String> imageUrlList = em.createQuery("SELECT p.imageUrl FROM diaryphoto dp LEFT OUTER JOIN dp.photo p"+
" WHERE dp.diary.diaryId = :diary_id").setParameter("diary_id", diaryId).getResultList();

Expand All @@ -47,8 +56,18 @@ public DiaryShowDetailResponseDTO showDiaryDetail (Long userId, java.sql.Date di
" WHERE dt.diary.id = :diary_id")
.setParameter("diary_id", diaryId).getResultList();

List<Object[]> senderCounts = em.createQuery("SELECT c.sender, MAX(c.createAt) AS latest_created_at, COUNT(*) AS cnt FROM chat c"+
" WHERE DATE(c.createAt) = : diary_date AND c.sender NOT IN :user"+
" GROUP BY c.sender ORDER BY cnt DESC, latest_created_at DESC")
.setParameter("diary_date", diaryDate).setParameter("user", Sender.USER).getResultList();

if(senderCounts.size()==0){
return new DiaryShowDetailResponseDTO(diaryDate, title, imageUrlList, content, tagNameList, null);
}

Sender sender = (Sender) senderCounts.get(0)[0];
return new DiaryShowDetailResponseDTO(diaryDate, title, imageUrlList, content, tagNameList, (long) sender.getIndex());

return new DiaryShowDetailResponseDTO(diaryDate, title, imageUrlList, content, tagNameList);

}

Expand All @@ -64,6 +83,7 @@ public Long findDiaryId(DiaryModifyRequestDTO diaryModifyRequestDTO) throws Pars
List<Long> resultList = em.createQuery("SELECT d.diaryId FROM diary d WHERE d.member.userId = :user_id AND d.diaryDate = :diary_date")
.setParameter("user_id", diaryModifyRequestDTO.getUserId()).setParameter("diary_date",diaryDate).getResultList();


for(Long result : resultList){
diaryId = result;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/kuit/chatdiary/service/DiaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.kuit.chatdiary.repository.DiaryRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -32,7 +33,7 @@ public class DiaryService {

private final S3Uploader s3Uploader;

public DiaryShowDetailResponseDTO showDiary(Long userId, Date diaryDate) throws ParseException {
public DiaryShowDetailResponseDTO showDiary(Long userId, Date diaryDate) throws Exception {
log.info("[DiaryService.showDiary]");
return diaryRepository.showDiaryDetail(userId, diaryDate);
}
Expand Down

0 comments on commit 8b95fb2

Please sign in to comment.