Skip to content

Commit

Permalink
feat : jpa bulk insert setting, query logger setting, controller leve…
Browse files Browse the repository at this point in the history
…l fix (#53)
  • Loading branch information
CodingLeeSeungHoon committed May 8, 2024
1 parent a8e58f5 commit 907fbc3
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NEOJwtAuthenticationFilter extends OncePerRequestFilter {
private final NEOUserRepository userRepository;
private final GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
private final NEOServletResponseWriter servletResponseWriter;
private static final String[] NO_CHECK_URLS = {"/login", "/oauth2/authorization/", "/docs/neo-api-guide.html", "/api/v1/oauth2/", "/favicon.ico", "/test"};
private static final String[] NO_CHECK_URLS = {"/login", "/oauth2/authorization/", "/docs/neo-api-guide.html", "/api/v1/oauth2/", "/favicon.ico", "/test", "/api/v1/post/"};

private static final String RE_ISSUE_ACCESS_TOKEN_URL = "/api/v1/token/reissue";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neo.needeachother.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -22,6 +23,7 @@ public class NEOJacksonConfig {
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
// objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
FilterProvider filters = new SimpleFilterProvider()
.addFilter("NEOResponseJsonFilter", new NEOResponseJsonFilter())
.addFilter("NEOInfoDtoJsonFilter", new NEOInfoDtoJsonFilter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/login", "/oauth2/authorization/**", "/api/v1/oauth2/**").permitAll()
// API 개발 문서 URL 모두 허가
.requestMatchers("/docs/**").permitAll()
.requestMatchers("/api/v1/post/**").permitAll()
// 나머지 URL
.anyRequest().authenticated())
.addFilterAfter(jwtAuthenticationProcessingFilter(), LogoutFilter.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neo.needeachother.post.application;

import com.neo.needeachother.category.domain.CategoryId;
import com.neo.needeachother.post.application.dto.PostDetailDto;
import com.neo.needeachother.post.domain.*;
import com.neo.needeachother.post.domain.repository.PostRepository;
import com.neo.needeachother.post.domain.domainservice.CreatePostByCategoryService;
Expand All @@ -19,43 +20,42 @@ public class WritePostService {
private final CreatePostByCategoryService createPostByCategoryService;

@Transactional
public void writeCommonPost(String title, String authorName, String authorEmail, String categoryId, List<CommonPostParagraphRequest> paragraphs) {
CommonPost createdCommonPost = createPostByCategoryService.createCommonPost(
title,
Author.of(authorName, authorEmail),
CategoryId.of(categoryId),
paragraphs.stream()
.map(paragraph -> CommonPostParagraph.of(paragraph.getBody(), paragraph.getParagraphType()))
.toList());
postRepository.save(createdCommonPost);
public PostDetailDto writeCommonPost(String title, String authorName, String authorEmail, String categoryId, List<CommonPostParagraphRequest> paragraphs) {
CommonPost createAndSaveCommonPost = postRepository.save(
createPostByCategoryService.createCommonPost(title, Author.of(authorName, authorEmail), CategoryId.of(categoryId),
paragraphs.stream()
.map(paragraph -> CommonPostParagraph.of(paragraph.getBody(), paragraph.getParagraphType()))
.toList()));

return createAndSaveCommonPost.toPostDetailDto();
}

@Transactional
public void writeAlbumPost(String title, String authorName, String authorEmail, String categoryId, String imagePath) {
AlbumPost createdAlbumPost = createPostByCategoryService.createAlbumPost(
title, Author.of(authorName, authorEmail), AlbumImage.of(imagePath), CategoryId.of(categoryId));
postRepository.save(createdAlbumPost);
public PostDetailDto writeAlbumPost(String title, String authorName, String authorEmail, String categoryId, String imagePath) {
AlbumPost createAndSaveAlbumPost = postRepository.save(createPostByCategoryService.createAlbumPost(
title, Author.of(authorName, authorEmail), AlbumImage.of(imagePath), CategoryId.of(categoryId)));

return createAndSaveAlbumPost.toPostDetailDto();
}

@Transactional
public void writeGoldBalancePost(String title, String authorName, String authorEmail, String categoryId, String question,
public PostDetailDto writeGoldBalancePost(String title, String authorName, String authorEmail, String categoryId, String question,
String leftExample, String rightExample) {
GoldBalancePost createdGoldBalancePost = createPostByCategoryService.createGoldBalancePost(
title, Author.of(authorName, authorEmail), question, leftExample, rightExample, CategoryId.of(categoryId));
postRepository.save(createdGoldBalancePost);
GoldBalancePost createAndSaveGoldBalancePost = postRepository.save(createPostByCategoryService.createGoldBalancePost(
title, Author.of(authorName, authorEmail), question, leftExample, rightExample, CategoryId.of(categoryId)));

return createAndSaveGoldBalancePost.toPostDetailDto();
}

@Transactional
public void writeVotePost(String title, String authorName, String authorEmail, String categoryId, String question,
public PostDetailDto writeVotePost(String title, String authorName, String authorEmail, String categoryId, String question,
int timeToLive, List<String> voteOptionNameList) {

List<VoteItem> voteItemList = voteOptionNameList.stream()
.map(VoteItem::of)
.toList();

VotePost createdVotePost = createPostByCategoryService.createVotePost(
title, Author.of(authorName, authorEmail), question, timeToLive, voteItemList, CategoryId.of(categoryId));
VotePost createAndSaveVotePost = postRepository.save(createPostByCategoryService.createVotePost(
title, Author.of(authorName, authorEmail), question, timeToLive, voteOptionNameList.stream()
.map(VoteItem::of)
.toList(), CategoryId.of(categoryId)));

postRepository.save(createdVotePost);
return createAndSaveVotePost.toPostDetailDto();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.neo.needeachother.post.application.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,6 +16,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class PostDetailDto {

private Long postId;
Expand All @@ -22,7 +26,13 @@ public class PostDetailDto {
private String status;
private int likeCount;
private boolean hostHeart;

@JsonFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime createdAt;

@JsonFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime exposureAt;

private String postType;

/* common & image post data */
Expand All @@ -33,5 +43,7 @@ public class PostDetailDto {

/* GoldBalance, Vote post data */
private String question;

@JsonProperty(value = "options")
private Map<String, VoteAblePostOptionDetailDto> options;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.neo.needeachother.post.application.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class VoteAblePostOptionDetailDto {
private String optionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public PostDetailDto toPostDetailDto() {
.status(this.getStatus().name())
.likeCount(this.getLikeCount())
.hostHeart(this.isHostHeart())
.createdAt(this.getCreatedAt())
.exposureAt(this.getExposureAt())
.postType(this.getPostType().name())
.representativeImage(this.image.getPath())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.neo.needeachother.post.domain;

import com.neo.needeachother.category.domain.CategoryId;
import com.neo.needeachother.category.domain.ContentType;
import com.neo.needeachother.post.application.dto.PostDetailDto;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand All @@ -10,7 +9,6 @@

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

@Getter
@Entity
Expand Down Expand Up @@ -55,6 +53,7 @@ public PostDetailDto toPostDetailDto() {
.status(this.getStatus().name())
.likeCount(this.getLikeCount())
.hostHeart(this.isHostHeart())
.createdAt(this.getCreatedAt())
.exposureAt(this.getExposureAt())
.postType(this.getPostType().name())
.paragraph(this.commonPostContents.stream().map(CommonPostParagraph::toDto).toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public GoldBalancePost(CategoryId categoryId, String title, Author author, PostS
@Override
public PostDetailDto toPostDetailDto() {
Map<String, VoteAblePostOptionDetailDto> voteOptionMap = new HashMap<>();

voteOptionMap.put("left", new VoteAblePostOptionDetailDto(this.leftDetail.getLeftExample(),
this.leftDetail.getLeftAnswersCount(), this.leftRightRate.getLeftRate()));
voteOptionMap.put("right", new VoteAblePostOptionDetailDto(this.rightDetail.getRightExample(),
this.rightDetail.getRightAnswersCount(), this.leftRightRate.getRightRate()));

return PostDetailDto.builder()
.postId(this.getId())
.categoryId(this.getCategoryId().getValue())
Expand All @@ -54,6 +56,7 @@ public PostDetailDto toPostDetailDto() {
.status(this.getStatus().name())
.likeCount(this.getLikeCount())
.hostHeart(this.isHostHeart())
.createdAt(this.getCreatedAt())
.exposureAt(this.getExposureAt())
.postType(this.getPostType().name())
.question(this.getQuestion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public PostDetailDto toPostDetailDto() {
.status(this.getStatus().name())
.likeCount(this.getLikeCount())
.hostHeart(this.isHostHeart())
.createdAt(this.getCreatedAt())
.exposureAt(this.getExposureAt())
.postType(this.getPostType().name())
.question(this.getQuestion())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package com.neo.needeachother.post.domain.dto;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@AllArgsConstructor
public class StarPagePostHeadlineDto {
private final String categoryId;
private final String categoryTitle;
private final Long postId;
private final int likeCount;
private final String authorName;
private final String postTitle;
private final LocalDateTime createdAt;
private final boolean hostHearted;
private final String postType;
private final String status;
private final boolean isChanged;

private String categoryId;

private String categoryTitle;

private Long postId;

private int likeCount;

private String authorName;

private String postTitle;

@JsonFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime createdAt;

private boolean hostHearted;

private String postType;

private String status;

private boolean isChanged;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public Page<StarPagePostHeadlineDto> searchPostHeadlineByCategoryIdWithPaging(Ca
.offset(pageable.getOffset())
.fetch();

content.forEach(headLine -> {
headLine.setPostType(PostType.convertToPostType(headLine.getPostType()).name());
headLine.setStatus(PostStatus.convertToPostStatus(headLine.getStatus()).name());
});

JPAQuery<Long> countQuery =
jpaQueryFactory.select(starPagePost.count())
.from(starPagePost)
Expand Down Expand Up @@ -111,6 +116,11 @@ public Slice<StarPagePostHeadlineDto> searchPostHeadlineByCategoryIdWithNoOffset
.offset(pageable.getOffset())
.fetch();

content.forEach(headLine -> {
headLine.setPostType(PostType.convertToPostType(headLine.getPostType()).name());
headLine.setStatus(PostStatus.convertToPostStatus(headLine.getStatus()).name());
});

boolean hasNext = false;
if (content.size() > pageable.getPageSize()) {
hasNext = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ResponseEntity<Page<StarPagePostHeadlineDto>> demandGetPostPageByCategory
}

@GetMapping("/{post_id}")
public ResponseEntity<PostDetailDto> demandGetPostDetail(@PathVariable("post_id") Long postId, @RequestParam String type){
public ResponseEntity<PostDetailDto> demandGetPostDetail(@PathVariable("post_id") Long postId, @RequestParam("type") String type){
PostDetailDto foundPostDetail = postDetailViewService.getPostDetailView(type, postId);
return ResponseEntity.ok(foundPostDetail);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.neo.needeachother.post.presentation;

import com.neo.needeachother.post.application.WritePostService;
import com.neo.needeachother.post.domain.CommonPostParagraph;
import com.neo.needeachother.post.application.dto.PostDetailDto;
import com.neo.needeachother.post.presentation.dto.WriteAlbumPostRequest;
import com.neo.needeachother.post.presentation.dto.WriteCommonPostRequest;
import com.neo.needeachother.post.presentation.dto.WriteGoldBalancePostRequest;
import com.neo.needeachother.post.presentation.dto.WriteVotePostRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.net.URI;

@RestController
@RequiredArgsConstructor
Expand All @@ -22,30 +23,36 @@ public class PostWriteController {
private final WritePostService writePostService;

@PostMapping("/common")
public void demandWriteCommonPost(@RequestBody WriteCommonPostRequest writeCommonPostRequest){
writePostService.writeCommonPost(
public ResponseEntity<PostDetailDto> demandWriteCommonPost(@RequestBody WriteCommonPostRequest writeCommonPostRequest){
PostDetailDto resultPostDetail = writePostService.writeCommonPost(
writeCommonPostRequest.getTitle(),
writeCommonPostRequest.getAuthorName(),
writeCommonPostRequest.getAuthorEmail(),
writeCommonPostRequest.getCategoryId(),
writeCommonPostRequest.getParagraphs()
);

return ResponseEntity.created(URI.create("/api/v1/post/" + resultPostDetail.getPostId()))
.body(resultPostDetail);
}

@PostMapping("/album")
public void demandWriteAlbumPost(@RequestBody WriteAlbumPostRequest writeAlbumPostRequest){
writePostService.writeAlbumPost(
public ResponseEntity<PostDetailDto> demandWriteAlbumPost(@RequestBody WriteAlbumPostRequest writeAlbumPostRequest){
PostDetailDto resultPostDetail = writePostService.writeAlbumPost(
writeAlbumPostRequest.getTitle(),
writeAlbumPostRequest.getAuthorName(),
writeAlbumPostRequest.getAuthorEmail(),
writeAlbumPostRequest.getCategoryId(),
writeAlbumPostRequest.getImagePath()
);

return ResponseEntity.created(URI.create("/api/v1/post/" + resultPostDetail.getPostId()))
.body(resultPostDetail);
}

@PostMapping("/gold_balance")
public void demandWriteGoldBalancePost(@RequestBody WriteGoldBalancePostRequest writeGoldBalancePostRequest){
writePostService.writeGoldBalancePost(
public ResponseEntity<PostDetailDto> demandWriteGoldBalancePost(@RequestBody WriteGoldBalancePostRequest writeGoldBalancePostRequest){
PostDetailDto resultPostDetail = writePostService.writeGoldBalancePost(
writeGoldBalancePostRequest.getTitle(),
writeGoldBalancePostRequest.getAuthorName(),
writeGoldBalancePostRequest.getAuthorEmail(),
Expand All @@ -54,11 +61,14 @@ public void demandWriteGoldBalancePost(@RequestBody WriteGoldBalancePostRequest
writeGoldBalancePostRequest.getLeftExample(),
writeGoldBalancePostRequest.getRightExample()
);

return ResponseEntity.created(URI.create("/api/v1/post/" + resultPostDetail.getPostId()))
.body(resultPostDetail);
}

@PostMapping("/vote")
public void demandWriteVotePost(@RequestBody WriteVotePostRequest writeVotePostRequest){
writePostService.writeVotePost(
public ResponseEntity<PostDetailDto> demandWriteVotePost(@RequestBody WriteVotePostRequest writeVotePostRequest){
PostDetailDto resultPostDetail = writePostService.writeVotePost(
writeVotePostRequest.getTitle(),
writeVotePostRequest.getAuthorName(),
writeVotePostRequest.getAuthorEmail(),
Expand All @@ -67,5 +77,8 @@ public void demandWriteVotePost(@RequestBody WriteVotePostRequest writeVotePostR
writeVotePostRequest.getTimeToLive(),
writeVotePostRequest.getOptionTextList()
);

return ResponseEntity.created(URI.create("/api/v1/post/" + resultPostDetail.getPostId()))
.body(resultPostDetail);
}
}
Loading

0 comments on commit 907fbc3

Please sign in to comment.