Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
mikekks authored Sep 22, 2024
2 parents 4fbf37a + 2219c36 commit 7369ea5
Show file tree
Hide file tree
Showing 34 changed files with 976 additions and 692 deletions.
1 change: 1 addition & 0 deletions main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.postgresql:postgresql:42.3.0'

// jsonb 타입 핸들링 위함
implementation 'io.hypersistence:hypersistence-utils-hibernate-62:3.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import org.sopt.makers.crew.main.entity.comment.Comment;
import org.sopt.makers.crew.main.entity.user.User;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.querydsl.core.annotations.QueryProjection;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;

@Getter
Expand Down Expand Up @@ -54,9 +52,14 @@ public class CommentDto {
@NotNull
private final List<ReplyDto> replies;

@Schema(description = "차단여부", example = "false")
@Getter(AccessLevel.NONE)
@NotNull
private final boolean isBlockedComment;

@QueryProjection
public CommentDto(Integer id, String contents, CommentWriterDto user, LocalDateTime createdDate, int likeCount,
boolean isLiked, boolean isWriter, int order, List<ReplyDto> replies) {
boolean isLiked, boolean isWriter, int order, List<ReplyDto> replies, boolean isBlockedComment) {
this.id = id;
this.contents = contents;
this.user = user;
Expand All @@ -66,9 +69,11 @@ public CommentDto(Integer id, String contents, CommentWriterDto user, LocalDateT
this.isWriter = isWriter;
this.order = order;
this.replies = replies;
this.isBlockedComment = isBlockedComment;
}

public static CommentDto of(Comment comment, boolean isLiked, boolean isWriter, List<ReplyDto> replies) {
public static CommentDto of(Comment comment, boolean isLiked, boolean isWriter, List<ReplyDto> replies,
boolean isBlockedComment) {
Integer userId = comment.getUser() == null ? null : comment.getUser().getId();
Integer orgId = comment.getUser() == null ? null : comment.getUser().getOrgId();
String userName = comment.getUser() == null ? null : comment.getUser().getName();
Expand All @@ -77,6 +82,10 @@ public static CommentDto of(Comment comment, boolean isLiked, boolean isWriter,
return new CommentDto(comment.getId(), comment.getContents(),
new CommentWriterDto(userId, orgId, userName,
profileImage), comment.getCreatedDate(), comment.getLikeCount(),
isLiked, isWriter, comment.getOrder(), replies);
isLiked, isWriter, comment.getOrder(), replies, isBlockedComment);
}

public boolean getIsBlockedComment() {
return isBlockedComment;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.sopt.makers.crew.main.comment.v2.dto.response;

import java.time.LocalDateTime;

import org.sopt.makers.crew.main.entity.comment.Comment;

import com.querydsl.core.annotations.QueryProjection;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;

@Getter
Expand Down Expand Up @@ -43,9 +47,14 @@ public class ReplyDto {
@NotNull
private final int order;

@Schema(description = "차단여부", example = "false")
@Getter(AccessLevel.NONE)
@NotNull
private final boolean isBlockedComment;

@QueryProjection
public ReplyDto(Integer id, String contents, CommentWriterDto user, LocalDateTime createdDate, int likeCount,
Boolean isLiked, Boolean isWriter, int order) {
Boolean isLiked, Boolean isWriter, int order, boolean isBlockedComment) {
this.id = id;
this.contents = contents;
this.user = user;
Expand All @@ -54,12 +63,17 @@ public ReplyDto(Integer id, String contents, CommentWriterDto user, LocalDateTim
this.isLiked = isLiked;
this.isWriter = isWriter;
this.order = order;
this.isBlockedComment = isBlockedComment;
}

public static ReplyDto of(Comment comment, boolean isLiked, boolean isWriter) {
public static ReplyDto of(Comment comment, boolean isLiked, boolean isWriter, boolean isBlockedComment) {
return new ReplyDto(comment.getId(), comment.getContents(),
new CommentWriterDto(comment.getUser().getId(), comment.getUser().getOrgId(), comment.getUser().getName(),
comment.getUser().getProfileImage()), comment.getCreatedDate(), comment.getLikeCount(),
isLiked, isWriter, comment.getOrder());
isLiked, isWriter, comment.getOrder(), isBlockedComment);
}

public boolean getIsBlockedComment() {
return isBlockedComment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sopt.makers.crew.main.entity.report.ReportRepository;
import org.sopt.makers.crew.main.entity.user.User;
import org.sopt.makers.crew.main.entity.user.UserRepository;
import org.sopt.makers.crew.main.external.playground.service.MemberBlockService;
import org.sopt.makers.crew.main.internal.notification.PushNotificationService;
import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -60,6 +61,8 @@ public class CommentV2ServiceImpl implements CommentV2Service {
private final ReportRepository reportRepository;
private final LikeRepository likeRepository;

private final MemberBlockService memberBlockService;

private final PushNotificationService pushNotificationService;

private final CommentMapper commentMapper;
Expand Down Expand Up @@ -168,21 +171,42 @@ public CommentV2GetCommentsResponseDto getComments(Integer postId, Integer page,

List<Comment> comments = commentRepository.findAllByPostIdOrderByCreatedDate(postId);

User user = userRepository.findByIdOrThrow(userId);
Long orgId = user.getOrgId().longValue();

Map<Long, Boolean> blockedUsers = memberBlockService.getBlockedUsers(orgId);

MyLikes myLikes = new MyLikes(likeRepository.findAllByUserIdAndCommentIdNotNull(userId));

Map<Integer, List<ReplyDto>> replyMap = new HashMap<>();
comments.stream()
.filter(comment -> !comment.isParentComment())
.forEach(
comment -> replyMap.computeIfAbsent(comment.getParentId(), k -> new ArrayList<>())
.add(ReplyDto.of(comment, myLikes.isLikeComment(comment.getId()),
comment.isWriter(userId))));
comment -> {
boolean isBlockedComment = false;
if (comment.getUserId() != null) {
isBlockedComment = blockedUsers.getOrDefault(comment.getUser().getOrgId().longValue(),
false);
}

replyMap.computeIfAbsent(comment.getParentId(), k -> new ArrayList<>())
.add(ReplyDto.of(comment, myLikes.isLikeComment(comment.getId()),
comment.isWriter(userId), isBlockedComment));
});

List<CommentDto> commentDtos = comments.stream()
.filter(Comment::isParentComment)
.map(comment -> CommentDto.of(comment, myLikes.isLikeComment(comment.getId()),
comment.isWriter(userId),
replyMap.get(comment.getId())))
.map(comment -> {
boolean isBlockedComment = false;
if (comment.getUserId() != null) {
isBlockedComment = blockedUsers.getOrDefault(comment.getUser().getOrgId().longValue(),
false);
}

return CommentDto.of(comment, myLikes.isLikeComment(comment.getId()),
comment.isWriter(userId),
replyMap.get(comment.getId()), isBlockedComment);
})
.toList();

PageMetaDto pageMetaDto = new PageMetaDto(new PageOptionsDto(1, 12), 30);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
package org.sopt.makers.crew.main.common.config;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import jakarta.persistence.EntityManagerFactory;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
basePackages = "org.sopt.makers.crew.main.entity", // 첫번째 DB가 있는 패키지(폴더) 경로
entityManagerFactoryRef = "primaryEntityManagerFactory", // EntityManager의 이름
transactionManagerRef = "primaryTransactionManager" // 트랜잭션 매니저의 이름
)
@Profile({"local", "dev", "prod"})
@Profile({"local", "dev", "prod", "test"})
public class CrewDatabaseConfig {

@Bean
Expand All @@ -52,10 +59,13 @@ public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory() {

Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.put("hibernate.hbm2ddl.auto", "validate");
properties.put("hibernate.format_sql", true);
properties.put("hibernate.physical_naming_strategy", "org.sopt.makers.crew.main.common.config.CamelCaseNamingStrategy");
properties.put("hibernate.globally_quoted_identifiers", true);

String[] activeProfiles = {"local", "dev", "prod"};
if (Arrays.stream(activeProfiles).anyMatch(profile -> profile.equals(System.getProperty("spring.profiles.active")))) {
properties.put("hibernate.hbm2ddl.auto", "validate");
}
em.setJpaPropertyMap(properties);

return em;
Expand All @@ -68,4 +78,27 @@ public PlatformTransactionManager primaryTransactionManager(
) {
return new JpaTransactionManager(Objects.requireNonNull(localContainerEntityManagerFactoryBean.getObject()));
}

private final ResourceLoader resourceLoader;

public CrewDatabaseConfig(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

@Bean
@Profile("test")
public CommandLineRunner init(@Qualifier("primaryEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return args -> executeSchemaSql();
}

private void executeSchemaSql() {
Resource resource = resourceLoader.getResource("classpath:schema.sql");
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(resource);
try {
databasePopulator.populate(primaryDatasourceProperties().getConnection());
} catch (Exception e) {
System.out.println(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package org.sopt.makers.crew.main.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import com.querydsl.jpa.JPQLTemplates;
import com.querydsl.jpa.impl.JPAQueryFactory;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@Configuration
public class JpaAuditingConfig {
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory queryFactory() {
return new JPAQueryFactory(JPQLTemplates.DEFAULT, entityManager);
}
@PersistenceContext(unitName = "primaryEntityManagerFactory")
private EntityManager primaryEntityManager;

@PersistenceContext(unitName = "secondEntityManagerFactory")
private EntityManager playgroundEntityManager;

@Bean(name = "primaryQueryFactory")
@Primary
public JPAQueryFactory primaryQueryFactory() {
return new JPAQueryFactory(JPQLTemplates.DEFAULT, primaryEntityManager);
}

@Bean(name = "playgroundQueryFactory")
public JPAQueryFactory playgroundQueryFactory() {
return new JPAQueryFactory(JPQLTemplates.DEFAULT, playgroundEntityManager);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.makers.crew.main.common.config;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -26,7 +27,7 @@
entityManagerFactoryRef = "secondEntityManagerFactory",
transactionManagerRef = "secondTransactionManager"
)
@Profile({"local", "dev", "prod"})
@Profile({"local", "dev", "prod", "test"})
public class PlaygroundDataSourceConfig {
@Bean
@ConfigurationProperties("spring.playground-datasource")
Expand All @@ -48,10 +49,14 @@ public LocalContainerEntityManagerFactoryBean secondEntityManagerFactory() {

Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.put("hibernate.hbm2ddl.auto", "validate");
properties.put("hibernate.format_sql", true);
properties.put("hibernate.physical_naming_strategy", "org.sopt.makers.crew.main.common.config.CamelCaseNamingStrategy");
properties.put("hibernate.globally_quoted_identifiers", true);

String[] activeProfiles = {"local", "dev", "prod"};
if (Arrays.stream(activeProfiles).anyMatch(profile -> profile.equals(System.getProperty("spring.profiles.active")))) {
properties.put("hibernate.hbm2ddl.auto", "validate");
}

em.setJpaPropertyMap(properties);

return em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.sopt.makers.crew.main.common.constant;

public abstract class CrewConst {
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
* 매 기수 시작하기 전에 수정 필요
* */
public static final Integer ACTIVE_GENERATION = 34;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CrewConst {

public static final String DAY_START_TIME = " 00:00:00";
public static final String DAY_END_TIME = " 23:59:59";
/**
* 매 기수 시작하기 전에 수정 필요
* */
public static final Integer ACTIVE_GENERATION = 35;

public static final String DAY_FORMAT = "yyyy.MM.dd";
public static final String DAY_TIME_FORMAT = "yyyy.MM.dd HH:mm:ss";
public static final String DAY_START_TIME = " 00:00:00";
public static final String DAY_END_TIME = " 23:59:59";

public static final String ORDER_ASC = "asc";
public static final String ORDER_DESC = "desc";
public static final String DAY_FORMAT = "yyyy.MM.dd";
public static final String DAY_TIME_FORMAT = "yyyy.MM.dd HH:mm:ss";

public static final String ORDER_ASC = "asc";
public static final String ORDER_DESC = "desc";
}
Loading

0 comments on commit 7369ea5

Please sign in to comment.