Skip to content

Commit

Permalink
Merge pull request #75 from SMWU-POCHAK/develop
Browse files Browse the repository at this point in the history
애플로그인 버그 수정 버전 배포
  • Loading branch information
5jisoo authored Sep 30, 2024
2 parents 99fbab7 + 24d1ecb commit f7b7ff6
Show file tree
Hide file tree
Showing 34 changed files with 630 additions and 242 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ application-API-KEY.tar
application-OAUTH.tar
application-JWT.tar

### Qclass ###
/src/main/generated/

### STS ###
.apt_generated
.classpath
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM openjdk:17-jdk
WORKDIR /app
COPY build/libs/*.jar app.jar
EXPOSE 3000
ENV SPRING_PROFILES_ACTIVE=DEV
ARG SPRING_PROFILES_ACTIVE
ENV SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-DEV}

CMD java -jar -Duser.timezone=Asia/Seoul app.jar
27 changes: 24 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'

implementation 'com.h2database:h2'
runtimeOnly 'com.h2database:h2'

asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'

testImplementation("org.springframework.boot:spring-boot-starter-test"){
exclude group: "com.vaadin.external.google", module:"android-json"
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module: "android-json"
}

testImplementation 'org.springframework.security:spring-security-test'
Expand All @@ -63,6 +65,12 @@ dependencies {
implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.30.1'

implementation group: 'org.json', name: 'json', version: '20090211'

// QueryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

ext {
Expand Down Expand Up @@ -108,7 +116,20 @@ jar {
enabled = false
}


build {
dependsOn copyDocument
}

def generated = 'src/main/generated'

clean {
delete file(generated)
}

tasks.withType(JavaCompile) {
options.generatedSourceOutputDirectory = file(generated)
}

sourceSets {
main.java.srcDirs += "$projectDir/build/generated"
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CommentElements getComments(
final Pageable pageable
) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Post post = postRepository.findPublicPostById(postId, loginMember);
final Post post = postRepository.findPublicPostById(postId);
final Page<Comment> commentList = commentRepository.findParentCommentByPost(post, loginMember, pageable);
return new CommentElements(loginMember, commentList);
}
Expand All @@ -68,7 +68,7 @@ public void saveComment(
final CommentUploadRequest request
) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Post post = postRepository.findPublicPostById(postId, loginMember);
final Post post = postRepository.findPublicPostById(postId);

if (request.checkChildComment()) {
saveChildComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import lombok.Getter;
import org.springframework.http.HttpStatus;

import java.security.NoSuchAlgorithmException;

import static org.springframework.http.HttpStatus.*;

@Getter
Expand Down Expand Up @@ -78,6 +76,7 @@ public enum ErrorStatus implements BaseErrorCode {
EXCEED_TAG_LIMIT(BAD_REQUEST, "POST4004", "최대 멤버 태그 수를 초과하였습니다."),
TAGGED_ONESELF(BAD_REQUEST, "POST4005", "자기 자신을 태그하였습니다."),
INVALID_TAG_INFO(BAD_REQUEST, "POST4006", "태그된 멤버의 정보가 확인되지 않습니다."),
BLOCKED_POST(BAD_REQUEST, "POST4007", "확인할 수 없는 게시물입니다."),

// Tag
INVALID_TAG_ID(BAD_REQUEST, "TAG4001", "유효하지 않은 태그 아이디입니다."),
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/apps/pochak/global/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.apps.pochak.global.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class QuerydslConfig {
private final EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/apps/pochak/like/service/LikeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void likePost(
final Long postId
) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Post post = postRepository.findPostById(postId, loginMember);
final Post post = postRepository.findPostById(postId);

final Optional<LikeEntity> optionalLike = likeRepository.findByLikeMemberAndLikedPost(loginMember, post);
if (optionalLike.isPresent()) {
Expand Down Expand Up @@ -76,7 +76,7 @@ public LikeElements getMemberLikedPost(
final Long postId
) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Post likedPost = postRepository.findPostById(postId, loginMember);
final Post likedPost = postRepository.findPostById(postId);

final List<LikeElement> likeElements = likeRepository.findLikesAndIsFollow(
loginMember.getId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.apps.pochak.post.domain.repository;

import com.apps.pochak.global.BaseEntityStatus;
import com.apps.pochak.global.api_payload.exception.GeneralException;
import com.apps.pochak.post.domain.Post;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Optional;

import static com.apps.pochak.block.domain.QBlock.block;
import static com.apps.pochak.global.api_payload.code.status.ErrorStatus.BLOCKED_POST;
import static com.apps.pochak.post.domain.QPost.post;
import static com.apps.pochak.tag.domain.QTag.tag;

@Repository
@RequiredArgsConstructor
public class PostCustomRepository {
private final JPAQueryFactory query;

public Post findPostByIdWithoutBlockPost(
final Long postId,
final Long loginMemberId
) {
return findByIdWithoutBlockPost(postId, loginMemberId).orElseThrow(() -> new GeneralException(BLOCKED_POST));
}

public Optional<Post> findByIdWithoutBlockPost(
final Long postId,
final Long loginMemberId
) {
return Optional.ofNullable(
query.selectFrom(post)
.join(post.owner).fetchJoin()
.join(tag).on(tag.post.eq(post))
.leftJoin(block).on(
checkOwnerOrTaggedMemberBlockLoginMember(loginMemberId)
.or(checkLoginMemberBlockOwnerOrTaggedMember(loginMemberId))
)
.groupBy(post)
.having(block.id.count().eq(0L))
.where(
post.id.eq(postId),
post.status.eq(BaseEntityStatus.ACTIVE)
)
.fetchOne()
);
}

private BooleanExpression checkOwnerOrTaggedMemberBlockLoginMember(final Long loginMemberId) {
return (block.blocker.eq(tag.member).or(block.blocker.eq(post.owner)))
.and(block.blockedMember.id.eq(loginMemberId));
}

private BooleanExpression checkLoginMemberBlockOwnerOrTaggedMember(final Long loginMemberId) {
return (block.blocker.id.eq(loginMemberId))
.and(block.blockedMember.eq(tag.member).or(block.blockedMember.eq(post.owner)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,14 @@

public interface PostRepository extends JpaRepository<Post, Long> {

@Query("""
select p from Post p
join fetch p.owner
where p.id = :postId and p.status = 'ACTIVE'
and p.owner not in (select b.blockedMember from Block b where b.blocker = :loginMember)
and :loginMember not in (select b.blockedMember from Block b where b.blocker = p.owner)
and not exists (select t.member from Tag t where t.post = p intersect select b.blockedMember from Block b where b.blocker = :loginMember)
and :loginMember not in (select b.blockedMember from Block b where b.blocker in (select t.member from Tag t where t.post = p))
""")
Optional<Post> findById(
@Param("postId") final Long postId,
@Param("loginMember") final Member loginMember
);
Optional<Post> findById(final Long id);

default Post findPostById(
final Long postId,
final Member loginMember
) {
return findById(postId, loginMember).orElseThrow(() -> new GeneralException(INVALID_POST_ID));
default Post findPostById(final Long postId) {
return findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID));
}

default Post findPublicPostById(
final Long postId,
final Member loginMember
) {
final Post post = findById(postId, loginMember).orElseThrow(() -> new GeneralException(INVALID_POST_ID));
default Post findPublicPostById(final Long postId) {
final Post post = findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID));
if (post.isPrivate()) {
throw new GeneralException(PRIVATE_POST);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/apps/pochak/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.apps.pochak.member.domain.Member;
import com.apps.pochak.member.domain.repository.MemberRepository;
import com.apps.pochak.post.domain.Post;
import com.apps.pochak.post.domain.repository.PostCustomRepository;
import com.apps.pochak.post.domain.repository.PostRepository;
import com.apps.pochak.post.dto.PostElements;
import com.apps.pochak.post.dto.request.PostUploadRequest;
Expand All @@ -38,6 +39,7 @@
@RequiredArgsConstructor
public class PostService {
private final PostRepository postRepository;
private final PostCustomRepository postCustomRepository;
private final MemberRepository memberRepository;
private final FollowRepository followRepository;
private final TagRepository tagRepository;
Expand Down Expand Up @@ -66,7 +68,7 @@ public PostDetailResponse getPostDetail(
final Long postId
) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Post post = postRepository.findPostById(postId, loginMember);
final Post post = postCustomRepository.findPostByIdWithoutBlockPost(postId, accessor.getMemberId());
final List<Tag> tagList = tagRepository.findTagsByPost(post);
if (post.isPrivate()) {
throw new GeneralException(PRIVATE_POST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void saveReport(
final ReportUploadRequest request
) {
final Member reporter = memberRepository.findMemberById(accessor.getMemberId());
final Post reportedPost = postRepository.findPostById(request.getPostId(), reporter);
final Post reportedPost = postRepository.findPostById(request.getPostId());

Report report = request.toEntity(reporter, reportedPost);
reportRepository.save(report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ void deleteTagByMemberOrPostList(
Long countByPost_PostStatusAndPost_OwnerAndMember(PostStatus postStatus, Member owner, Member member);

@Query("""
select count(t) from Tag t
join t.member m
join t.post p
where p.postStatus = 'PUBLIC'
and p.status = 'ACTIVE'
and ((m = :member and p.owner = :loginMember)
or (m = :loginMember and p.owner = :member))
order by p.allowedDate desc
select count(t1) from Tag t1
join Tag t2 on t1.post = t2.post
where t1.post.postStatus = 'PUBLIC'
and t1.post.status = 'ACTIVE'
and (t1.member = :loginMember and t2.member = :member)
""")
Long countByMember(@Param("loginMember") Member loginMember, @Param("member")Member member);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.apps.pochak.alarm.controller;

import com.apps.pochak.alarm.domain.Alarm;
import com.apps.pochak.alarm.domain.TagAlarm;
import com.apps.pochak.alarm.dto.response.AlarmElements;
import com.apps.pochak.alarm.service.AlarmService;
import com.apps.pochak.auth.domain.Accessor;
Expand All @@ -24,8 +25,8 @@
import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse;
import static com.apps.pochak.global.api_payload.code.status.SuccessStatus.SUCCESS_CHECK_ALARM;
import static com.apps.pochak.global.converter.ListToPageConverter.toPage;
import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1;
import static com.apps.pochak.tag.fixture.TagFixture.WAITING_TAG;
import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1;
import static com.apps.pochak.tag.fixture.TagFixture.STATIC_WAITING_TAG;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;
Expand All @@ -45,13 +46,14 @@
@MockBean(JpaMetamodelMappingContext.class)
class AlarmControllerTest extends ControllerTest {

private static final Member MEMBER = MEMBER1;
private static final Member MEMBER = STATIC_MEMBER1;
private static final TagAlarm TAG_ALARM = STATIC_TAG_ALARM;

private static final List<Alarm> ALARM_LIST = List.of(
COMMENT_REPLY_ALARM,
FOLLOW_ALARM,
TAGGED_LIKE_ALARM,
TAG_ALARM
STATIC_COMMENT_REPLY_ALARM,
STATIC_FOLLOW_ALARM,
STATIC_TAGGED_LIKE_ALARM,
STATIC_TAG_ALARM
);

@MockBean
Expand Down Expand Up @@ -184,7 +186,7 @@ void getPreviewPostTest() throws Exception {

when(postService.getPreviewPost(any(), any()))
.thenReturn(
new PostPreviewResponse(TAG_ALARM.getTag().getPost(), List.of(WAITING_TAG))
new PostPreviewResponse(TAG_ALARM.getTag().getPost(), List.of(STATIC_WAITING_TAG))
);

this.mockMvc.perform(
Expand Down
Loading

0 comments on commit f7b7ff6

Please sign in to comment.