Skip to content

Commit

Permalink
FEAT 일기 수정 api구현 (#77)
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)

---------

Co-authored-by: Wang HoEun <[email protected]>
Co-authored-by: Wang Hoeun <[email protected]>
  • Loading branch information
3 people authored May 14, 2024
1 parent 267916f commit dc69c91
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
import org.kau.kkoolbeeServer.domain.diary.Diary;
import org.kau.kkoolbeeServer.domain.diary.Feeling;
import org.kau.kkoolbeeServer.domain.diary.dto.request.FeelingListRequestDto;
import org.kau.kkoolbeeServer.domain.diary.dto.response.CalenderDiaryResponseDto;
import org.kau.kkoolbeeServer.domain.diary.dto.response.*;
import org.kau.kkoolbeeServer.domain.diary.dto.request.CurrentDateRequestDto;
import org.kau.kkoolbeeServer.domain.diary.dto.request.DiaryContentRequestDto;
import org.kau.kkoolbeeServer.domain.diary.dto.response.DiaryContentResponseDto;
import org.kau.kkoolbeeServer.domain.diary.dto.response.FeelingListResponseDto;
import org.kau.kkoolbeeServer.domain.diary.dto.response.SlowTypeCreateResponseDto;
import org.kau.kkoolbeeServer.domain.diary.service.DiaryService;
import org.kau.kkoolbeeServer.domain.member.Member;
import org.kau.kkoolbeeServer.domain.member.service.MemberService;
Expand All @@ -36,6 +33,7 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -259,6 +257,59 @@ public ResponseEntity<ApiResponse<?>> createSlowTypeDiary(@RequestHeader(value =
}
}

@PatchMapping("/api/diary/update")
public ResponseEntity<?> updateDiary(
@RequestHeader(value = "Authorization") String authHeader,
@RequestPart(value = "imageUrl", required = false) MultipartFile imageFile,
@RequestPart(value="diaryId") Long diaryId,
@RequestPart(value = "diaryTitle") String diaryTitle,
@RequestPart(value = "diaryContent") String diaryContent) {


try{

String accessToken = null;
if (authHeader != null && authHeader.startsWith("Bearer ")) {
accessToken = authHeader.substring(7);
Long memberID= jwtProvider.getUserFromJwt(accessToken);
Diary diary=diaryService.findDiaryById(diaryId).orElseThrow(()->new NoSuchElementException("해당 ID의 일기를 찾을 수 없습니다."));
if(diary.getMember().getId()!=memberID){

return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.error(ErrorType.NOT_YOUR_DIARY));
}
}
else{
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.error(ErrorType.INVALID_HTTP_REQUEST_ERROR));

}
String imageUrl=null;
if (imageFile!=null && !imageFile.isEmpty()){
imageUrl=s3UploaderService.upload(imageFile);

UpdateDiaryResponseDto responseDto=diaryService.updateDiary(diaryId,diaryContent,diaryTitle,imageUrl);
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED,responseDto));

}
else{
UpdateDiaryResponseDto responseDto=diaryService.updateDiaryWithoutImage(diaryId,diaryContent,diaryTitle);
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED,responseDto));


}


}
catch (Exception e){
e.printStackTrace();

return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR,e.getMessage()));
}




}




Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.kau.kkoolbeeServer.domain.diary.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class UpdateDiaryResponseDto {
private Long diaryId;
private String diaryContent;
private String diaryTitle;
private String imageurl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import org.kau.kkoolbeeServer.domain.diary.Diary;
import org.kau.kkoolbeeServer.domain.diary.Feeling;
import org.kau.kkoolbeeServer.domain.diary.dto.response.UpdateDiaryResponseDto;
import org.kau.kkoolbeeServer.domain.diary.repository.DiaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.text.html.Option;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -54,5 +58,53 @@ public Diary saveDiary(Diary diary){
return diaryRepository.save(diary);
}

public UpdateDiaryResponseDto updateDiary(Long diaryId,String diaryContent,String diaryTitle,String imageUrl){
Diary diary=findDiaryById(diaryId).orElseThrow(()->new NoSuchElementException("해당 ID의 일기를 찾을 수 없습니다."));
diary.setImageurl(imageUrl);
if(!diary.getContent().equals(diaryContent)){
diary.setFeeling(null);
diary.setAdvice(null);
diary.setContent(diaryContent);
}
if(diary.getTitle()!=diaryTitle){
diary.setTitle(diaryTitle);
}
ZonedDateTime kstNow = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
LocalDateTime now = kstNow.toLocalDateTime();
diary.setWritedAt(now);


Diary savedDiary=diaryRepository.save(diary);
return new UpdateDiaryResponseDto(diaryId,savedDiary.getContent(),savedDiary.getTitle(),
savedDiary.getImageurl());




}

public UpdateDiaryResponseDto updateDiaryWithoutImage(Long diaryId,String diaryContent,String diaryTitle){
Diary diary=findDiaryById(diaryId).orElseThrow(()->new NoSuchElementException("해당 ID의 일기를 찾을 수 없습니다."));
if(!diary.getContent().equals(diaryContent)){
diary.setFeeling(null);
diary.setAdvice(null);
diary.setContent(diaryContent);
}
if(diary.getTitle()!=diaryTitle){
diary.setTitle(diaryTitle);
}

ZonedDateTime kstNow = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
LocalDateTime now = kstNow.toLocalDateTime();
diary.setWritedAt(now);
Diary savedDiary=diaryRepository.save(diary);
return new UpdateDiaryResponseDto(diaryId,savedDiary.getContent(),savedDiary.getTitle(),
savedDiary.getImageurl());




}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum ErrorType {
NOT_FOUND_MEMBER_ERROR(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."),
ADVICE_NOT_FOUND(HttpStatus.NOT_FOUND, "요청하신 Diary에 맞는 Advice가 없습니다."),
NOT_FOUND_REFRESH_TOKEN_ERROR(HttpStatus.NOT_FOUND, "존재하지 않는 리프레시 토큰입니다."),
NOT_YOUR_DIARY(HttpStatus.NOT_FOUND,"해당 Diary에 접근할 수 있는 권한이 없습니다."),

/**
* 500 INTERNAL SERVER ERROR
Expand Down

0 comments on commit dc69c91

Please sign in to comment.