Skip to content

Commit

Permalink
Merge branch 'refactor/backend-issue353' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
younghoonkwon committed Oct 28, 2021
2 parents 4270a0a + f124c33 commit f09a92f
Show file tree
Hide file tree
Showing 31 changed files with 514 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,14 @@ private List<String> getUploadedImageUrls(List<ImageRequest> imageRequests) {
return imageUrls;
}

private List<Image> assignPostToImages(Post post, List<String> imageUrls) {
final List<Image> images = new ArrayList<>();
private void assignPostToImages(Post post, List<String> imageUrls) {
for (String imageUrl : imageUrls) {
final Image image = Image.builder()
.url(imageUrl)
.build();
image.assignPost(post);
imageRepository.save(image);
images.add(image);
}
return images;
}

@Transactional
Expand All @@ -108,7 +105,7 @@ public List<PostResponse> findByVaccineType(VaccinationType vaccinationType, Opt
}

public List<PostResponse> findByVaccineType(VaccinationType vaccinationType, int offset, int size, Sort sort, Optional<User> optionalUser) {
List<Post> posts = postRepository.findByVaccineType(vaccinationType, offset, size, Sort.toOrderSpecifier(sort));
List<Post> posts = postRepository.findByVaccineType(vaccinationType, offset, size, sort.getSort());
return PostResponse.toList(posts, optionalUser.orElse(null));
}

Expand Down Expand Up @@ -146,8 +143,7 @@ public void delete(Long id, Optional<User> optionalUser) {
User user = optionalUser.get();
Post post = findPostByPostId(id);
post.validateAuthor(user);
deleteImagesFromAwsS3(post.getS3PathsOfAllImages());
imageRepository.deleteAll(post.getAllImagesAsList());
deleteAllImagesInPost(post);
postRepository.deleteById(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void deleteComment() {
Post foundPost = postRepository.findById(this.post.getId()).get();
//then
assertThat(foundComment).isEmpty();
assertThat(foundPost.getCommentsAsList()).extracting("id").doesNotContain(commentResponse.getId());
assertThat(foundPost.getCommentsAsList()).isEmpty();
}

@DisplayName("댓글 삭제 - 실패 - 댓글을 찾을 수 없음")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void findByVaccineTypeNextPageAll() {
List<PostResponse> postResponses = postService.findByVaccineType(VaccinationType.ALL, 1, 1, Sort.CREATED_AT_DESC, optionalUser);
//then
assertThat(postResponses).size().isEqualTo(1);
assertThat(postResponses).extracting("content").containsExactlyElementsOf(Arrays.asList("Test 1"));
assertThat(postResponses).extracting("content").containsExactlyElementsOf(Collections.singletonList("Test 1"));
assertThat(postResponses).extracting("vaccinationType").filteredOn(vaccinationType -> vaccinationType instanceof VaccinationType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ void createWithImages() {
assertThat(postResponse.getImages()).containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL);

assertThat(foundPost).isNotNull();
assertThat(foundPost.hasImages()).isTrue();
assertThat(foundPost.getUser()).isNotNull();
assertThat(foundPost.getImages().getImages())
assertThat(foundPost.getAllImagesAsList())
.extracting("url").containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL);

verify(awsS3Uploader, times(3)).upload(any(String.class), any(File.class));
Expand Down Expand Up @@ -439,7 +440,7 @@ void updateWithImages() {
.orElseThrow(() -> new NotFoundException("게시글을 찾을 수 없음."));
//then
assertThat(updatedPost.getContent()).isEqualTo(updateRequest.getContent());
assertThat(updatedPost.getImages().getImages())
assertThat(updatedPost.getAllImagesAsList())
.extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL);
assertThat(imageRepository.findAll()).extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL);
verify(awsS3Uploader, times(3)).delete(any(String.class), any(String.class));
Expand Down
3 changes: 2 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ subprojects {
'**/Sort*',
'**/Filter*',
'**/ImageType*',
'**/JpaConfiguration*',
// domain-cvi-oauth-service
'**/KakaoProfile*',
'**/NaverProfile*',
Expand All @@ -109,7 +110,7 @@ subprojects {
// domain-cvi-publicdata-parser
"**/Parser.java, " +
// domain-cvi
"**/Sort.java, **/Filter.java, **/ImageType.java, " +
"**/Sort.java, **/Filter.java, **/ImageType.java, **/JpaConfiguration.java, " +
// domain-cvi-oauth-service
"**/KakaoProfile.java, **/NaverProfile.java, **/UserInformation.java, **/AuthRequest.java, **/OAuthConfig.java"
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public UserInformation requestUserInfo(SocialProvider provider, String code, Str

private Authorization extractAuthorization(SocialProvider provider) {
validateSocialProvider(provider);
String key = provider.convertToComponentName();
String key = provider.getProvider();
if (!authorizationMap.containsKey(key)) {
log.info(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key));
throw new InvalidOperationException(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public CommentRepositoryImpl(EntityManager em) {
@Override
public List<Comment> findByUserId(Long userId) {
return queryFactory.selectFrom(comment)
.leftJoin(comment.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(comment.createdAt.desc())
.fetch();
.leftJoin(comment.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(comment.createdAt.desc())
.fetch();
}

@Override
public List<Comment> findByUserId(Long userId, int offset, int size) {
return queryFactory.selectFrom(comment)
.leftJoin(comment.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(comment.createdAt.desc())
.offset(offset)
.limit(size)
.fetch();
.leftJoin(comment.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(comment.createdAt.desc())
.offset(offset)
.limit(size)
.fetch();
}

private BooleanExpression userIdEq(Long userId) {
Expand Down
15 changes: 5 additions & 10 deletions backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
import com.cvi.config.entity.BaseEntity;
import com.cvi.exception.NotFoundException;
import com.cvi.post.domain.model.Post;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Objects;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Objects;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ public LikeRepositoryImpl(EntityManager em) {
@Override
public List<Like> findByUserId(Long userId) {
return queryFactory.selectFrom(like)
.leftJoin(like.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(like.createdAt.desc())
.fetch();
.leftJoin(like.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(like.createdAt.desc())
.fetch();
}

@Override
public List<Like> findByUserId(Long userId, int offset, int size) {
return queryFactory.selectFrom(like)
.leftJoin(like.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(like.createdAt.desc())
.offset(offset)
.limit(size)
.fetch();
.leftJoin(like.user, user).fetchJoin()
.where(userIdEq(userId))
.orderBy(like.createdAt.desc())
.offset(offset)
.limit(size)
.fetch();
}

private BooleanExpression userIdEq(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import com.cvi.exception.NotFoundException;
import com.cvi.image.domain.Image;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.Embeddable;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Embeddable;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Embeddable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,16 @@
import com.cvi.image.domain.Image;
import com.cvi.like.domain.model.Like;
import com.cvi.user.domain.model.User;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotBlank;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Entity
Expand Down Expand Up @@ -62,7 +49,7 @@ public class Post extends BaseEntity {

@Builder
public Post(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, User user,
String content, int viewCount, VaccinationType vaccinationType) {
String content, int viewCount, VaccinationType vaccinationType) {
super(id, createdAt, lastModifiedAt);
this.user = user;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.cvi.post.domain.model;

import static com.cvi.post.domain.model.QPost.post;

import com.cvi.exception.InvalidInputException;
import com.querydsl.core.types.OrderSpecifier;
import java.util.Arrays;
import lombok.Getter;

import static com.cvi.post.domain.model.QPost.post;

@Getter
public enum Sort {
LIKE_COUNT_ASC(post.likes.likes.size().asc()),
Expand All @@ -23,16 +21,4 @@ public enum Sort {
Sort(OrderSpecifier sort) {
this.sort = sort;
}

public static OrderSpecifier toOrderSpecifier(Sort input) {
return Arrays.stream(values())
.filter(Sort::isSameTypeOf)
.findAny()
.map(sort -> input.getSort())
.orElseThrow(() -> new InvalidInputException("잘못된 정렬 형식입니다."));
}

private static boolean isSameTypeOf(Sort sort) {
return sort == sort;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.cvi.post.domain.repository;

import static com.cvi.comment.domain.model.QComment.comment;
import static com.cvi.like.domain.model.QLike.like;
import static com.cvi.post.domain.model.QPost.post;
import static com.cvi.user.domain.model.QUser.user;

import com.cvi.post.domain.model.Post;
import com.cvi.post.domain.model.QPost;
import com.cvi.post.domain.model.VaccinationType;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPQLQueryFactory;
import com.querydsl.jpa.impl.JPAQueryFactory;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.persistence.EntityManager;

import static com.cvi.comment.domain.model.QComment.comment;
import static com.cvi.like.domain.model.QLike.like;
import static com.cvi.post.domain.model.QPost.post;
import static com.cvi.user.domain.model.QUser.user;

public class PostRepositoryImpl implements PostQueryDsl {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.cvi.publicdata.domain.model;

import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;

@Getter
public enum RegionPopulation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class VaccinationStatistic extends PublicData {

@Builder
public VaccinationStatistic(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, RegionPopulation regionPopulation,
LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt,
long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) {
LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt,
long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) {
super(id, createdAt, lastModifiedAt, regionPopulation);
this.baseDate = baseDate;
this.firstCnt = firstCnt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.cvi.user.domain.model;

import lombok.Getter;

@Getter
public enum SocialProvider {
NAVER("naverAuthorization"),
KAKAO("kakaoAuthorization");
Expand All @@ -9,8 +12,4 @@ public enum SocialProvider {
SocialProvider(String provider) {
this.provider = provider;
}

public String convertToComponentName() {
return this.provider;
}
}
Loading

0 comments on commit f09a92f

Please sign in to comment.