Skip to content

Commit

Permalink
FEAT: #115-검색API구현 (#117)
Browse files Browse the repository at this point in the history
* chore: 환경변수 세팅

* chore: aws secret manager 설정

* [chore] CI/CD settings (#13)

* chore: common 폴더 구조 변경

* chore: 환경변수 파일 분리 (local/dev)

* feat: 서버 profile 확인용 api 추가

* chore: 무중단 배포시 실행할 스크립트 작성

* chore: Github Actions 스크립트 작성 (임시 trigger 설정)

* chore: CI/CD trigger 재설정

* chore: 인덴트 오류 수정

* chore: CodeDeploy 옵션 문자열 오류 수정

* chore: Spring Security 및 Redis 임시 주석 처리

* chore: trigger 시점 develop 으로 변경

* chore: profile 조회 엔드포인트 수정

* style: CD 브랜치 trigger 시점 임시 변경

* fix: trigger 시점 develop 으로 원상 복귀

---------

Co-authored-by: Wang HoEun <[email protected]>

* feat/14-entity develop브랜치에 merge

* Feat/#14 entity (#15)

* 엔티티 첫 커밋

* diary엔티티에 멤버와의 관계추가

* feat : diary엔티티에 summary추가

* refactor: entity에 감정,조언 분리

* refactor:수정완료

* refactor: feeling클래스 감정추가

* feat: summary엔티티따로생성 후 member와 다대일양방향관계생성

* worried 스펠링수정

* feat: 카카오 로그인 구현+s3서버 세팅 (#31)

* feat: 카카오 로그인 구현+s3서버 세팅

* fix: build gradle 수정

---------

Co-authored-by: Wang HoEun <[email protected]>

* fix: build.gradle 파일 최신화

* Feat/#30 slowtype save api (#32)

* diary-content-api구현 및 테스트성공

* json필드  이름변경

* refactor:ApiResponse초기세팅 필드이름변경status

* api명세서 변경으로인한 초기세팅 변경

* succes type에서  오타로 인한 커밋

* feat: list-calender api구현 but 테스트는 아직

* api테스트완료 but 시간대 문제발생

* 애플리케이션 timezone을 utc로 설정하여 임시해결

* refactor /#24 json필드명 오류발견후수정

* index on feat/#26-list-calender: b531010 refactor /#24 json필드명 오류발견후수정

* feat-feelinglist 1차구현

* try catch구문 삭제 및 exceptionhandler수정, apiresponse수정

* entity 수정

* feat:apiresponse수정 및 s3설정파일 임시구현

* feat:S3연결제외 api구현

* refactor: imageurl추가에따른 컨텐트 api 살짝수정

* refactor: diarycontent반환값에 title추가

* refactor: s3연결전까지 코든짠것

* success type 추가

* refactor : successtype변경

* develop pull 마무리

* refactor : application.yml이랑 value값맞추기성공

* feat: api구현 및 테스트 완료

* refactor:content,advice길이수정

* fix: bootstarp 파일이 없는 오류 해결

* refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 (#36)

Co-authored-by: Wang HoEun <[email protected]>

* [refactor] kakao login 기존 프론트가 토큰 가져오는 방식으로 수정 (#38)

* refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정

* fix: 다시 login 되돌려두기

---------

Co-authored-by: Wang HoEun <[email protected]>

* Refactor/#40 slow type diary retry (#41)

* 수정전 commit

* Principal객체사용한 memberId기반 api전체 수정

* refactor : slowtype api principal제외

* Refactor/#40 slow type diary retry (#44)

* 수정전 commit

* Principal객체사용한 memberId기반 api전체 수정

* refactor : slowtype api principal제외

* refactor:오류수정을 위한 임시파일경로생성

* Update DiaryController.java 오타해결

* refactor 충돌해결

* Refactor/#46 choose diary type api retry (#47)

* Develop (#45)

* chore: 환경변수 세팅

* chore: aws secret manager 설정

* [chore] CI/CD settings (#13)

* chore: common 폴더 구조 변경

* chore: 환경변수 파일 분리 (local/dev)

* feat: 서버 profile 확인용 api 추가

* chore: 무중단 배포시 실행할 스크립트 작성

* chore: Github Actions 스크립트 작성 (임시 trigger 설정)

* chore: CI/CD trigger 재설정

* chore: 인덴트 오류 수정

* chore: CodeDeploy 옵션 문자열 오류 수정

* chore: Spring Security 및 Redis 임시 주석 처리

* chore: trigger 시점 develop 으로 변경

* chore: profile 조회 엔드포인트 수정

* style: CD 브랜치 trigger 시점 임시 변경

* fix: trigger 시점 develop 으로 원상 복귀

---------

Co-authored-by: Wang HoEun <[email protected]>

* feat/14-entity develop브랜치에 merge

* Feat/#14 entity (#15)

* 엔티티 첫 커밋

* diary엔티티에 멤버와의 관계추가

* feat : diary엔티티에 summary추가

* refactor: entity에 감정,조언 분리

* refactor:수정완료

* refactor: feeling클래스 감정추가

* feat: summary엔티티따로생성 후 member와 다대일양방향관계생성

* worried 스펠링수정

* feat: 카카오 로그인 구현+s3서버 세팅 (#31)

* feat: 카카오 로그인 구현+s3서버 세팅

* fix: build gradle 수정

---------

Co-authored-by: Wang HoEun <[email protected]>

* fix: build.gradle 파일 최신화

* Feat/#30 slowtype save api (#32)

* diary-content-api구현 및 테스트성공

* json필드  이름변경

* refactor:ApiResponse초기세팅 필드이름변경status

* api명세서 변경으로인한 초기세팅 변경

* succes type에서  오타로 인한 커밋

* feat: list-calender api구현 but 테스트는 아직

* api테스트완료 but 시간대 문제발생

* 애플리케이션 timezone을 utc로 설정하여 임시해결

* refactor /#24 json필드명 오류발견후수정

* index on feat/#26-list-calender: b531010 refactor /#24 json필드명 오류발견후수정

* feat-feelinglist 1차구현

* try catch구문 삭제 및 exceptionhandler수정, apiresponse수정

* entity 수정

* feat:apiresponse수정 및 s3설정파일 임시구현

* feat:S3연결제외 api구현

* refactor: imageurl추가에따른 컨텐트 api 살짝수정

* refactor: diarycontent반환값에 title추가

* refactor: s3연결전까지 코든짠것

* success type 추가

* refactor : successtype변경

* develop pull 마무리

* refactor : application.yml이랑 value값맞추기성공

* feat: api구현 및 테스트 완료

* refactor:content,advice길이수정

* fix: bootstarp 파일이 없는 오류 해결

* refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 (#36)

Co-authored-by: Wang HoEun <[email protected]>

* [refactor] kakao login 기존 프론트가 토큰 가져오는 방식으로 수정 (#38)

* refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정

* fix: 다시 login 되돌려두기

---------

Co-authored-by: Wang HoEun <[email protected]>

* Refactor/#40 slow type diary retry (#41)

* 수정전 commit

* Principal객체사용한 memberId기반 api전체 수정

* refactor : slowtype api principal제외

* Refactor/#40 slow type diary retry (#44)

* 수정전 commit

* Principal객체사용한 memberId기반 api전체 수정

* refactor : slowtype api principal제외

* refactor:오류수정을 위한 임시파일경로생성

* Update DiaryController.java 오타해결

* refactor 충돌해결

---------

Co-authored-by: Wang HoEun <[email protected]>
Co-authored-by: Wang Hoeun <[email protected]>

* requestHeader를 사용한 코드수정 및 diarytyperequestDto추가

---------

Co-authored-by: Wang HoEun <[email protected]>
Co-authored-by: Wang Hoeun <[email protected]>

* feeling별 diary list조회 api수정 (#50)

* refactor:content api코드수정및 responseDto 수정 (#53)

* Refactor/#55 list calendar api retry (#56)

* refactor: calendar api코드수정 및 diary생성시 writedAt필드 설정코드추가

* refactor:writedAt필드 현재시간값가져오기로 수정

* calendarapi수정

* refactor:content api에서 advice와 feeling값 null값허용 (#59)

* Refactor/#58 diary content api exception retry (#61)

* refactor:content api에서 advice와 feeling값 null값허용

* diary엔티티 content칼럼 Longtext로수정및 slowtype api 이미지파일없어도가능하게

* FeelingListResponseDto의 imageUrl필드추가 (#64)

* CalendarDiaryResponseDto의 ImageUrl필드추가 (#67)

* feeling list,slowtype생성 request오류 추가

* refactor:ZonedDatetime추가 (#70)

* refactor: imageFile 안줘도 가능하게 코드수정 (#73)

* feat: 수정 api구현 (#76)

* refactor: logging추가 (#80)

* refactor-requestpart대신 modelattribute (#83)

* refactor:s3파일중복체크후 업로드하는 로직 추가 (#86)

* feat: 일기삭제api구현 및 에러타입추가,slowtypeapi요청값대문자로수정 (#88)

* refactor:imageurl LONGTEXT로변경

* refactor:slowtyperesponseDto에 createdDate필드추가 (#92)

* refactor:이미지생성api구현 및 중복코드제거 (#95)

* feag:카카오톡공유하기api구현 (#98)

* refacotr:requestpart로 변경 (#101)

* refactor:createdDate추가 (#104)

* refactor:프롬프트수정 (#107)

* [FEAT]-109 payment (#110)

* feat: iampory필요한 환경세팅

* feat:결제검증로직추가

* feat:discord 웹훅 구현 (#113)

* feat: 검색api 1차 구현 (#116)

---------

Co-authored-by: Wang HoEun <[email protected]>
Co-authored-by: Wang Hoeun <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 66a448e commit 4824f5e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,56 @@ public ResponseEntity<?> diaryShare(@RequestParam("diaryId") Long diaryId){

}

@GetMapping("/api/diary/search")

public ResponseEntity<?>diarySearch(@RequestHeader(value = "Authorization") String authHeader,@RequestBody SearchRequestDto requestDto){

try{
Long memberId=extractMemberIdFromRequestHeader(authHeader);
String searchKeyword= requestDto.getSearchKeyword();
List<Diary> diaries = diaryService.searchDiaries(memberId, searchKeyword);

if (diaries.isEmpty()) {
return ResponseEntity.status(ErrorType.REQUEST_VALIDATION_ERROR.getHttpStatus())
.body(ApiResponse.error(ErrorType.REQUEST_VALIDATION_ERROR, "해당 검색어에 대한 일기가 존재하지 않습니다."));
}
List<DiarySearchResponseDto> diaryList = diaries.stream()
.map(diary -> {
String excerptContent = getFirstExcerpt(diary.getContent(), searchKeyword);




return new DiarySearchResponseDto(diary.getId(), diary.getWritedAt(),diary.getTitle(), diary.getImageurl(),excerptContent , searchKeyword);
})
.collect(Collectors.toList());

Map<String,List<DiarySearchResponseDto>> responseMap=Map.of("diaryList", diaryList);



return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED,responseMap));



} catch (IllegalArgumentException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.error(ErrorType.INVALID_HTTP_REQUEST_ERROR));
}
catch(Exception e){
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR));




}


}



public Long extractMemberIdFromRequestHeader(String authHeader) {
if (authHeader != null && authHeader.startsWith("Bearer ")) {
String accessToken = authHeader.substring(7);
Expand All @@ -330,6 +380,21 @@ public Long extractMemberIdFromRequestHeader(String authHeader) {
}


private String getFirstExcerpt(String content, String keyword) {
// content에 keyword가 없을 경우 null 반환
if (!content.contains(keyword)) {
return null; // 키워드가 없으면 null 반환
}

int index = content.indexOf(keyword);
int start = Math.max(0, index - 3); // 앞쪽 3자
int end = Math.min(content.length(), index + keyword.length() + 3); // 키워드 끝까지 + 3자

return content.substring(start, end); // 정해진 범위의 내용 반환
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.kau.kkoolbeeServer.domain.diary.dto.request;

import lombok.Getter;

@Getter
public class SearchRequestDto {
private String searchKeyword;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.kau.kkoolbeeServer.domain.diary.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;

@AllArgsConstructor
@Getter
public class DiarySearchResponseDto {
private Long diaryId;
private LocalDateTime createdDate;
private String diaryTitle;
private String imageUrl;

private String diaryContent;

private String keyWord;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface DiaryRepository extends JpaRepository<Diary,Long> {

List<Diary> findByMemberIdAndFeeling(Long memberId,Feeling feeling);

List<Diary> findByMemberIdAndTitleContainingOrContentContaining(Long memberId, String titleKeyword, String contentKeyword);

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ private String formatPromptForImageGeneration(String diaryContent) {
}


public List<Diary> searchDiaries(Long memberId, String searchKeyword) {
return diaryRepository.findByMemberIdAndTitleContainingOrContentContaining(memberId, searchKeyword, searchKeyword);
}




}

0 comments on commit 4824f5e

Please sign in to comment.