Skip to content

Commit

Permalink
Merge pull request #137 from My-Own-Weapon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
moonxxpower authored Jul 25, 2024
2 parents 82adef3 + 534b0e3 commit 9e16467
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.chimaera.wagubook.dto.request.PostUpdateRequest;
import com.chimaera.wagubook.dto.response.PostAIResponse;
import com.chimaera.wagubook.dto.response.PostResponse;
import com.chimaera.wagubook.dto.response.PostUpdateCheckResponse;
import com.chimaera.wagubook.dto.response.StorePostResponse;
import com.chimaera.wagubook.exception.CustomException;
import com.chimaera.wagubook.exception.ErrorCode;
Expand Down Expand Up @@ -130,6 +131,14 @@ public ResponseEntity<String> deletePost(@PathVariable Long postId, HttpSession
return new ResponseEntity<>(postId + "번 포스트가 삭제되었습니다.", HttpStatus.OK);
}

@GetMapping("/posts/{postId}/check")
@Operation(summary = "포스트 수정 가능 여부 확인")
public ResponseEntity<PostUpdateCheckResponse> checkUpdatePost(@PathVariable Long postId, HttpSession session) {
Long memberId = (Long) session.getAttribute("memberId");
checkValidByMemberId(memberId);
return new ResponseEntity<>(postService.checkUpdatePost(postId, memberId), HttpStatus.OK);
}

// 회원 검증
private void checkValidByMemberId(Long memberId) {
if (memberId == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.chimaera.wagubook.dto.response;

import lombok.Data;

@Data
public class PostUpdateCheckResponse {
private boolean isUpdate;

public PostUpdateCheckResponse(boolean isUpdate) {
this.isUpdate = isUpdate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ public String requestText(String menuName, String categoryName) throws IOExcepti
// 요청할 데이터 설정
Map<String, Object> requestData = new HashMap<>();
requestData.put("model", apiModel);
requestData.put("max_tokens", 150);
requestData.put("max_tokens", 500);
requestData.put("messages", Arrays.asList(
Map.of("role", "user", "content", String.format("주어진 음식 이미지를 분석해서 이에 대한 긍정적인 리뷰를 100글자 내외로 남겨줘" +
Map.of("role", "user", "content", String.format("주어진 음식 이름에 대한 긍정적인 리뷰를 600글자 내외로 남겨줘" +
"해당 음식은 이름이 %s이고, 카테고리가 %s인 음식이야." +
"이때 숫자, 시간, 날짜 관련 표현은 제외해줘." +
"또한 사용자가 기록을 남기는 어투로 작성해줘야 하고, 반드시 완성형 문장이어야 해!" +
"형태는 맛, 분위기, 한줄평으로 단락을 나누어서 출력해줘." +
"예시를 들어줄게 [맛]\n -(내용) \n\n[분위기]\n -(내용)\n\n[한줄평]\n -(내용) 이런 형태로 내용 부분을 채워넣어줘." +
"그리고 리뷰에 적절한 이모지도 함께 넣어줘." +
"마지막으로 출력은 리뷰만 해줘.", menuName, categoryName))
));

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/chimaera/wagubook/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.chimaera.wagubook.dto.request.PostUpdateRequest;
import com.chimaera.wagubook.dto.response.PostAIResponse;
import com.chimaera.wagubook.dto.response.PostResponse;
import com.chimaera.wagubook.dto.response.PostUpdateCheckResponse;
import com.chimaera.wagubook.dto.response.StorePostResponse;
import com.chimaera.wagubook.entity.*;
import com.chimaera.wagubook.exception.CustomException;
Expand Down Expand Up @@ -258,6 +259,7 @@ public PostResponse getPostById(Long postId, Long memberId) {
public PostResponse updatePost(Long postId, List<MultipartFile> images, PostUpdateRequest postUpdateRequest, Long memberId) throws IOException {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_MEMBER));
Post post = postRepository.findByIdAndMemberId(postId, member.getId()).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_POST));
// todo: 포스트, 회원 검증 로직 추가 -> 위의 내용 삭제

// 전체에 있어 식당은 하나만 저장한다.
// 사용자가 이미 한번 생성한 식당은 포스트를 새로 생성할 수 없다.
Expand Down Expand Up @@ -350,11 +352,24 @@ public PostResponse updatePost(Long postId, List<MultipartFile> images, PostUpda
public void deletePost(Long postId, Long memberId) {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_MEMBER));
Post post = postRepository.findByIdAndMemberId(postId, member.getId()).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_POST));
// todo: 포스트, 회원 검증 로직 추가 -> 위의 내용 삭제

List<Menu> menus = post.getMenus();
for (Menu menu : menus) {
String url = menu.getMenuImage().getUrl();
s3ImageService.deleteImageFromS3(url);
}
postRepository.delete(post);
}

public PostUpdateCheckResponse checkUpdatePost(Long postId, Long memberId) {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_MEMBER));
Post post = postRepository.findById(postId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_POST));

if (member.getId() != post.getMember().getId()) {
return new PostUpdateCheckResponse(false);
} else {
return new PostUpdateCheckResponse(true);
}
}
}

0 comments on commit 9e16467

Please sign in to comment.