diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/src/main/java/com/finfellows/domain/auth/application/KakaoService.java b/src/main/java/com/finfellows/domain/auth/application/KakaoService.java index 809fdd8..d913c5d 100644 --- a/src/main/java/com/finfellows/domain/auth/application/KakaoService.java +++ b/src/main/java/com/finfellows/domain/auth/application/KakaoService.java @@ -213,14 +213,7 @@ public AuthRes kakaoLogin(KakaoProfile kakaoProfile) { Token savedToken = tokenRepository.save(token); - // 쿠키 생성 및 설정 -// Cookie refreshTokenCookie = new Cookie("refreshToken", tokenMapping.getRefreshToken()); -// refreshTokenCookie.setMaxAge(14 * 24 * 60 * 60); // 유효기간 2주일 -// refreshTokenCookie.setHttpOnly(true); -// refreshTokenCookie.setPath("/"); -// refreshTokenCookie.setSecure(true); -// response.addCookie(refreshTokenCookie); return AuthRes.builder() @@ -230,6 +223,8 @@ public AuthRes kakaoLogin(KakaoProfile kakaoProfile) { .build(); } + + @Transactional public Message signOut(final RefreshTokenReq tokenRefreshRequest) { Token token = tokenRepository.findByRefreshToken(tokenRefreshRequest.getRefreshToken()) diff --git a/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java b/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java index 660997f..bec3271 100644 --- a/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java @@ -48,6 +48,7 @@ public class AuthController { // kakaoService.accessRequest(); // } + @Operation(summary = "유저 정보 확인", description = "현재 접속 중인 유저의 정보를 확인합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "유저 확인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = User.class) ) } ), diff --git a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java index 05491e9..c52c493 100644 --- a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java +++ b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java @@ -18,6 +18,7 @@ import com.finfellows.global.payload.Message; import com.finfellows.global.payload.ResponseCustom; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +32,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class FinancialProductBookmarkServiceImpl implements BookmarkService{ private final FinancialProductBookmarkRepository financialProductBookmarkRepository; private final UserRepository userRepository; @@ -144,11 +146,17 @@ public Message cmaDelete(UserPrincipal userPrincipal, Long cmaId) { CMA cma = cmaRepository.findById(cmaId) .orElseThrow(RuntimeException::new); + log.info(String.valueOf(user)); + log.info(String.valueOf(cma)); + + CmaBookmark cmaBookmark = CmaBookmark.builder() .user(user) .cma(cma) .build(); + log.info(cmaBookmark.toString()); + cmaBookmarkRepository.delete(cmaBookmark); return Message.builder() diff --git a/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java b/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java index 7c83f4c..d001dbe 100644 --- a/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java +++ b/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java @@ -1,100 +1,100 @@ -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; -import com.finfellows.domain.educontent.dto.response.EduContentResponse; -import com.finfellows.domain.post.domain.Post; -import com.finfellows.domain.post.domain.repository.PostRepository; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class EduContentService { - private final EduContentRepository eduContentRepository; - private final PostRepository postRepository; - private final EduContentBookmarkRepository eduContentBookmarkRepository; - - @Transactional - public EduContent createEduContent(EduContentRequest request) { - Post post = new Post(); - postRepository.save(post); - - // 빌더 패턴을 사용하여 EduContent 생성하면서 Post 엔터티를 설정 - EduContent eduContent = EduContent.builder() - .title(request.getTitle()) - .content(request.getContent()) - .post(post) // Post 엔터티를 설정 - .build(); - - // EduContent 저장 - EduContent savedContent = eduContentRepository.save(eduContent); - return savedContent; - } - - public Page getAllEduContents(Long userId, Pageable pageable) { - Page eduContentPage = eduContentRepository.findAll(pageable); - - List eduContentResponses = eduContentPage.getContent().stream() - .map(eduContent -> EduContentResponse.builder() - .id(eduContent.getId()) - .title(eduContent.getTitle()) - .content(eduContent.getContent()) - .bookmarked(checkBookmarked(userId, eduContent.getId())) - .build()) - .collect(Collectors.toList()); - - return new PageImpl<>(eduContentResponses, pageable, eduContentPage.getTotalElements()); - } - - public EduContentResponse getEduContent(Long id) { - EduContent eduContent = eduContentRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); - - return EduContentResponse.builder() - .id(eduContent.getId()) - .title(eduContent.getTitle()) - .content(eduContent.getContent()) - .build(); - } - - @Transactional - public void deleteEduContent(Long id) { - EduContent eduContent = eduContentRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); - - eduContentRepository.delete(eduContent); - } - - @Transactional - public EduContentResponse updateEduContent(Long id, EduContentRequest request) { - EduContent eduContent = eduContentRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); - - eduContent.updateContent(request.getTitle(), request.getContent()); - - EduContent updatedContent = eduContentRepository.save(eduContent); - - return EduContentResponse.builder() - .id(updatedContent.getId()) - .title(updatedContent.getTitle()) - .content(updatedContent.getContent()) - .build(); - } - - - private boolean checkBookmarked(Long userId, Long eduContentId) { - return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId); - } -} +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; +import com.finfellows.domain.educontent.dto.response.EduContentResponse; +import com.finfellows.domain.post.domain.Post; +import com.finfellows.domain.post.domain.repository.PostRepository; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class EduContentService { + private final EduContentRepository eduContentRepository; + private final PostRepository postRepository; + private final EduContentBookmarkRepository eduContentBookmarkRepository; + + @Transactional + public EduContent createEduContent(EduContentRequest request) { + Post post = new Post(); + postRepository.save(post); + + // 빌더 패턴을 사용하여 EduContent 생성하면서 Post 엔터티를 설정 + EduContent eduContent = EduContent.builder() + .title(request.getTitle()) + .content(request.getContent()) + .post(post) // Post 엔터티를 설정 + .build(); + + // EduContent 저장 + EduContent savedContent = eduContentRepository.save(eduContent); + return savedContent; + } + + public Page getAllEduContents(Long userId, Pageable pageable) { + Page eduContentPage = eduContentRepository.findAll(pageable); + + List eduContentResponses = eduContentPage.getContent().stream() + .map(eduContent -> EduContentResponse.builder() + .id(eduContent.getId()) + .title(eduContent.getTitle()) + .content(eduContent.getContent()) + .bookmarked(checkBookmarked(userId, eduContent.getId())) + .build()) + .collect(Collectors.toList()); + + return new PageImpl<>(eduContentResponses, pageable, eduContentPage.getTotalElements()); + } + + public EduContentResponse getEduContent(Long id) { + EduContent eduContent = eduContentRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); + + return EduContentResponse.builder() + .id(eduContent.getId()) + .title(eduContent.getTitle()) + .content(eduContent.getContent()) + .build(); + } + + @Transactional + public void deleteEduContent(Long id) { + EduContent eduContent = eduContentRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); + + eduContentRepository.delete(eduContent); + } + + @Transactional + public EduContentResponse updateEduContent(Long id, EduContentRequest request) { + EduContent eduContent = eduContentRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); + + eduContent.updateContent(request.getTitle(), request.getContent()); + + EduContent updatedContent = eduContentRepository.save(eduContent); + + return EduContentResponse.builder() + .id(updatedContent.getId()) + .title(updatedContent.getTitle()) + .content(updatedContent.getContent()) + .build(); + } + + + private boolean checkBookmarked(Long userId, Long eduContentId) { + return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId); + } +} diff --git a/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java b/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java index 77f37f6..06f2367 100644 --- a/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java +++ b/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java @@ -1,89 +1,89 @@ -package com.finfellows.domain.educontent.presentation; - -import com.finfellows.domain.educontent.application.EduContentService; -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; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/learn/edu") -@Tag(name = "EduContent", description = "EduContent API") -public class EduContentController { - private final EduContentService eduContentService; - - @Operation(summary = "교육콘텐츠 저장", description = "교육콘텐츠를 저장합니다.") - @ApiResponse(responseCode = "201", description = "교육콘텐츠 저장 성공", content = { - @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class))) - }) - @PostMapping("") - public ResponseEntity saveEduContent(@RequestBody EduContentRequest request) { - EduContent response = eduContentService.createEduContent(request); - return new ResponseEntity<>(response, HttpStatus.CREATED); - } - - @Operation(summary = "교육콘텐츠 전체 목록 조회", description = "교육콘텐츠 전체 목록을 조회합니다. 비로그인 시 북마크 여부는 null입니다.") - @ApiResponse(responseCode = "200", description = "교육콘텐츠 목록 조회 성공", content = { - @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class))) - }) - @GetMapping - public ResponseEntity> getAllEduContents(@CurrentUser UserPrincipal userPrincipal, Pageable pageable) { - Page responsePage; - - if (userPrincipal != null) { - responsePage = eduContentService.getAllEduContents(userPrincipal.getId(), pageable); - } else { - responsePage = eduContentService.getAllEduContents(null, pageable); - } - - // userPrincipal이 null이면 bookmarked를 null로 설정 - if (userPrincipal == null) { - responsePage.getContent().forEach(eduContentResponse -> eduContentResponse.setBookmarked(null)); - } - return new ResponseEntity<>(responsePage, HttpStatus.OK); - } - - @Operation(summary = "교육콘텐츠 상세 내용 조회", description = "교육콘텐츠 상세 내용을 조회합니다.") - @ApiResponse(responseCode = "200", description = "교육콘텐츠 조회 성공", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class)) - }) - @GetMapping("/{id}") - public ResponseEntity getEduContent(@PathVariable Long id) { - EduContentResponse response = eduContentService.getEduContent(id); - return new ResponseEntity<>(response, HttpStatus.OK); - } - - @Operation(summary = "교육콘텐츠 삭제", description = "교육콘텐츠를 삭제합니다.") - @ApiResponse(responseCode = "204", description = "교육콘텐츠 삭제 성공") - @DeleteMapping("/{id}") - public ResponseEntity deleteEduContent(@PathVariable Long id) { - eduContentService.deleteEduContent(id); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Operation(summary = "교육콘텐츠 수정", description = "교육콘텐츠를 수정합니다.") - @ApiResponse(responseCode = "200", description = "교육콘텐츠 수정 성공", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class)) - }) - @PatchMapping("/{id}") - public ResponseEntity updateEduContent(@PathVariable Long id, @RequestBody EduContentRequest request) { - EduContentResponse updatedContent = eduContentService.updateEduContent(id, request); - return new ResponseEntity<>(updatedContent, HttpStatus.OK); - } +package com.finfellows.domain.educontent.presentation; + +import com.finfellows.domain.educontent.application.EduContentService; +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; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/learn/edu") +@Tag(name = "EduContent", description = "EduContent API") +public class EduContentController { + private final EduContentService eduContentService; + + @Operation(summary = "교육콘텐츠 저장", description = "교육콘텐츠를 저장합니다.") + @ApiResponse(responseCode = "201", description = "교육콘텐츠 저장 성공", content = { + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class))) + }) + @PostMapping("") + public ResponseEntity saveEduContent(@RequestBody EduContentRequest request) { + EduContent response = eduContentService.createEduContent(request); + return new ResponseEntity<>(response, HttpStatus.CREATED); + } + + @Operation(summary = "교육콘텐츠 전체 목록 조회", description = "교육콘텐츠 전체 목록을 조회합니다. 비로그인 시 북마크 여부는 null입니다.") + @ApiResponse(responseCode = "200", description = "교육콘텐츠 목록 조회 성공", content = { + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class))) + }) + @GetMapping + public ResponseEntity> getAllEduContents(@CurrentUser UserPrincipal userPrincipal, Pageable pageable) { + Page responsePage; + + if (userPrincipal != null) { + responsePage = eduContentService.getAllEduContents(userPrincipal.getId(), pageable); + } else { + responsePage = eduContentService.getAllEduContents(null, pageable); + } + + // userPrincipal이 null이면 bookmarked를 null로 설정 + if (userPrincipal == null) { + responsePage.getContent().forEach(eduContentResponse -> eduContentResponse.setBookmarked(null)); + } + return new ResponseEntity<>(responsePage, HttpStatus.OK); + } + + @Operation(summary = "교육콘텐츠 상세 내용 조회", description = "교육콘텐츠 상세 내용을 조회합니다.") + @ApiResponse(responseCode = "200", description = "교육콘텐츠 조회 성공", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class)) + }) + @GetMapping("/{id}") + public ResponseEntity getEduContent(@PathVariable Long id) { + EduContentResponse response = eduContentService.getEduContent(id); + return new ResponseEntity<>(response, HttpStatus.OK); + } + + @Operation(summary = "교육콘텐츠 삭제", description = "교육콘텐츠를 삭제합니다.") + @ApiResponse(responseCode = "204", description = "교육콘텐츠 삭제 성공") + @DeleteMapping("/{id}") + public ResponseEntity deleteEduContent(@PathVariable Long id) { + eduContentService.deleteEduContent(id); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Operation(summary = "교육콘텐츠 수정", description = "교육콘텐츠를 수정합니다.") + @ApiResponse(responseCode = "200", description = "교육콘텐츠 수정 성공", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class)) + }) + @PatchMapping("/{id}") + public ResponseEntity updateEduContent(@PathVariable Long id, @RequestBody EduContentRequest request) { + EduContentResponse updatedContent = eduContentService.updateEduContent(id, request); + return new ResponseEntity<>(updatedContent, HttpStatus.OK); + } } \ No newline at end of file diff --git a/src/main/java/com/finfellows/domain/post/domain/Content.java b/src/main/java/com/finfellows/domain/post/domain/Content.java index def321d..ea0fcb7 100644 --- a/src/main/java/com/finfellows/domain/post/domain/Content.java +++ b/src/main/java/com/finfellows/domain/post/domain/Content.java @@ -1,54 +1,54 @@ - -package com.finfellows.domain.post.domain; - -import com.finfellows.domain.common.BaseEntity; -import com.finfellows.domain.common.Status; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.Where; - -import java.time.LocalDate; - -@Entity -@Table(name="Content") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -@Where(clause = "status = 'ACTIVE'") -public class Content extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", updatable = false) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="post_id") - private Post post_id; - - @Column(name="title") - private String title; - - @Column(name="content") - private String content; - - @Enumerated(EnumType.STRING) - @Column(name="contentType") - private ContentType contentType; - - - @Builder - public Content(Post post_id, String title, String content){ - this.post_id=post_id; - this.title=title; - this.content=content; - this.contentType = ContentType.CONTENT; - - } - - public void updateContent(String title, String content) { - this.title = title; - this.content = content; - } + +package com.finfellows.domain.post.domain; + +import com.finfellows.domain.common.BaseEntity; +import com.finfellows.domain.common.Status; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; + +import java.time.LocalDate; + +@Entity +@Table(name="Content") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Where(clause = "status = 'ACTIVE'") +public class Content extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="post_id") + private Post post_id; + + @Column(name="title") + private String title; + + @Column(name="content") + private String content; + + @Enumerated(EnumType.STRING) + @Column(name="contentType") + private ContentType contentType; + + + @Builder + public Content(Post post_id, String title, String content){ + this.post_id=post_id; + this.title=title; + this.content=content; + this.contentType = ContentType.CONTENT; + + } + + public void updateContent(String title, String content) { + this.title = title; + this.content = content; + } } \ No newline at end of file diff --git a/src/main/java/com/finfellows/domain/post/domain/repository/ContentRepository.java b/src/main/java/com/finfellows/domain/post/domain/repository/ContentRepository.java index 859487e..fe60dec 100644 --- a/src/main/java/com/finfellows/domain/post/domain/repository/ContentRepository.java +++ b/src/main/java/com/finfellows/domain/post/domain/repository/ContentRepository.java @@ -1,9 +1,9 @@ -package com.finfellows.domain.post.domain.repository; - -import com.finfellows.domain.post.domain.Content; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ContentRepository extends JpaRepository { -} +package com.finfellows.domain.post.domain.repository; + +import com.finfellows.domain.post.domain.Content; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ContentRepository extends JpaRepository { +} diff --git a/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java b/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java index 29940fb..c6c8569 100644 --- a/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java +++ b/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java @@ -18,7 +18,7 @@ public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins(allowedOrigins) .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") - .allowedHeaders("*") +// .allowedHeaders("*") .allowCredentials(true) .maxAge(MAX_AGE_SECS); }