Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
[FIX]: NewContent, EduContnet reponse 수정 (#69)
Browse files Browse the repository at this point in the history
* [FEAT] #3 ChatGPT 응답

단답 확인 과정 테스트

* [FIX] #3 SecurityConfig permitAll 추가

* [FEAT] #3 ChatgptRequest 추가

GPT Request DTO format

* [FIX] #3 Chatgpt dependencies 추가

* [FEAT] #14 EduContent DTO 생성

* [FIX] #14 Post AccessLevel 수정

* [FEAT] #14 educontent 저장 api 구현

* [FEAT] #14 educontent 조회/상세조회/수정/삭제 api 구현

* [FEAT] #15 newscontent 저장/조회/상세조회/수정/삭제 api 구현

* [FEAT] #19 content 저장/조회/상세조회/수정/삭제 api 구현

* [FEAT] #19 swagger 설정 추가

* [FEAT] #19 readOnly를 위한 Transactional 어노테이션 추가

* [FEAT] #39 chatbot, comment 파일 추가

* fix: chat gpt 수정

* [FIX] #19 Transactional annotation readOnly default 수정

* Revert "[FIX] #19 Transactional annotation readOnly default 수정"

This reverts commit 4a18b0ebce60ff41bdacac044fd6c365adf49ca4.

* [FIX] #19 Transactional annotation readOnly default 수정

* [FEAT] #39 챗봇 질의응답 기능 개발

인사말 추가, 질의응답, 조회 기능

* [FEAT] educontent created_at 요청/응답 필드 추가

* [FIX] #39 챗봇 요청/응답값 UserId 부분 수정

* [FIX] #39 챗봇 요청/응답값 UserId 부분 수정

* [FIX] #39 swagger 코드 추가

* [FIX] #52 Post Entity enum type 추가

* [FIX] #54 금융 배우자 북마크 여부 Response 추가

---------

Co-authored-by: 박세진 <[email protected]>
Co-authored-by: Sejin Park <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2024
1 parent ab0ed07 commit d25e22f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.finfellows.domain.bookmark.domain.repository;

import com.finfellows.domain.bookmark.domain.EduContentBookmark;
import com.finfellows.domain.bookmark.domain.FinancialProductBookmark;
import com.finfellows.domain.educontent.domain.EduContent;
import com.finfellows.domain.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface EduContentBookmarkRepository extends JpaRepository<EduContentBookmark, Long> {
Optional<EduContentBookmark> findByUserAndEduContent(User user, EduContent eduContent);

List<EduContentBookmark> findAllByUser(User user);

boolean existsByUser_IdAndEduContent_Id(Long userId, Long id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.finfellows.domain.educontent.application;

import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository;
import com.finfellows.domain.educontent.domain.EduContent;
import com.finfellows.domain.educontent.domain.repository.EduContentRepository;
import com.finfellows.domain.educontent.dto.request.EduContentRequest;
Expand All @@ -20,6 +21,7 @@
public class EduContentService {
private final EduContentRepository eduContentRepository;
private final PostRepository postRepository;
private final EduContentBookmarkRepository eduContentBookmarkRepository;

@Transactional
public EduContent createEduContent(EduContentResponse request) {
Expand All @@ -38,13 +40,14 @@ public EduContent createEduContent(EduContentResponse request) {
return savedContent;
}

public List<EduContentResponse> getAllEduContents() {
public List<EduContentResponse> getAllEduContents(Long userId) {
List<EduContent> eduContents = eduContentRepository.findAll();
return eduContents.stream()
.map(eduContent -> EduContentResponse.builder()
.id(eduContent.getId())
.title(eduContent.getTitle())
.content(eduContent.getContent())
.bookmarked(checkBookmarked(userId, eduContent.getId()))
.build())
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -83,4 +86,9 @@ public EduContentResponse updateEduContent(Long id, EduContentRequest request) {
.content(updatedContent.getContent())
.build();
}


private boolean checkBookmarked(Long userId, Long eduContentId) {
return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class EduContentResponse {
private LocalDateTime created_at;
private String title;
private String content;
private boolean bookmarked;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.finfellows.domain.educontent.domain.EduContent;
import com.finfellows.domain.educontent.dto.request.EduContentRequest;
import com.finfellows.domain.educontent.dto.response.EduContentResponse;
import com.finfellows.global.config.security.token.CurrentUser;
import com.finfellows.global.config.security.token.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -39,8 +41,8 @@ public ResponseEntity<EduContent> saveEduContent(@RequestBody EduContentResponse
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class)))
})
@GetMapping
public ResponseEntity<List<EduContentResponse>> getAllEduContents() {
List<EduContentResponse> responseList = eduContentService.getAllEduContents();
public ResponseEntity<List<EduContentResponse>> getAllEduContents(@CurrentUser UserPrincipal userPrincipal) {
List<EduContentResponse> responseList = eduContentService.getAllEduContents(userPrincipal.getId());
return new ResponseEntity<>(responseList, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.finfellows.domain.newscontent.application;

import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository;
import com.finfellows.domain.educontent.domain.EduContent;
import com.finfellows.domain.newscontent.domain.NewsContent;
import com.finfellows.domain.newscontent.domain.repository.NewsContentRepository;
import com.finfellows.domain.newscontent.dto.request.NewsContentRequest;
import com.finfellows.domain.newscontent.dto.response.NewsContentResponse;
import com.finfellows.domain.post.domain.Post;
import com.finfellows.domain.post.domain.repository.PostRepository;
import com.finfellows.domain.user.domain.repository.UserRepository;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,6 +23,7 @@
public class NewsContentService {
private final NewsContentRepository newsContentRepository;
private final PostRepository postRepository;
private final EduContentBookmarkRepository eduContentBookmarkRepository;

@Transactional
public NewsContent createNewsContent(NewsContentResponse request) {
Expand All @@ -38,13 +42,14 @@ public NewsContent createNewsContent(NewsContentResponse request) {
return savedContent;
}

public List<NewsContentResponse> getAllNewsContents() {
public List<NewsContentResponse> getAllNewsContents(Long userId) {
List<NewsContent> newsContents = newsContentRepository.findAll();
return newsContents.stream()
.map(newsContent -> NewsContentResponse.builder()
.id(newsContent.getId())
.title(newsContent.getTitle())
.content(newsContent.getContent())
.bookmarked(checkBookmarked(userId, newsContent.getId())) // 북마크 여부 확인
.build())
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -83,4 +88,9 @@ public NewsContentResponse updateNewsContent(Long id, NewsContentRequest request
.content(updatedContent.getContent())
.build();
}

// 특정 뉴스 콘텐츠에 대한 북마크 여부 확인
private boolean checkBookmarked(Long userId, Long newsContentId) {
return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, newsContentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class NewsContentResponse {
private Long id;
private String title;
private String content;
private boolean bookmarked;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.finfellows.domain.newscontent.domain.NewsContent;
import com.finfellows.domain.newscontent.dto.request.NewsContentRequest;
import com.finfellows.domain.newscontent.dto.response.NewsContentResponse;
import com.finfellows.global.config.security.token.CurrentUser;
import com.finfellows.global.config.security.token.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -39,8 +41,8 @@ public ResponseEntity<NewsContent> saveNewsContent(@RequestBody NewsContentRespo
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = NewsContentResponse.class)))
})
@GetMapping
public ResponseEntity<List<NewsContentResponse>> getAllNewsContents() {
List<NewsContentResponse> responseList = newsContentService.getAllNewsContents();
public ResponseEntity<List<NewsContentResponse>> getAllNewsContents(@CurrentUser UserPrincipal userPrincipal) {
List<NewsContentResponse> responseList = newsContentService.getAllNewsContents(userPrincipal.getId());
return new ResponseEntity<>(responseList, HttpStatus.OK);
}

Expand Down

0 comments on commit d25e22f

Please sign in to comment.