Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

데벨업 v1.0.3 Release #567

Merged
merged 8 commits into from
Sep 27, 2024
2 changes: 1 addition & 1 deletion backend/src/main/java/develup/api/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public WebConfig(AuthArgumentResolver authArgumentResolver, OAuthProviderConvert

@Override
public void addCorsMappings(CorsRegistry registry) {
Set<String> clientHostSet = new HashSet<>(List.of(clientHost, apiHost, "http://localhost:3000"));
Set<String> clientHostSet = new HashSet<>(List.of(clientHost, apiHost, "https://devel-up.co.kr", "http://localhost:3000"));
String[] corsHosts = clientHostSet.toArray(new String[0]);

registry.addMapping("/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public Member getMember() {
}

public String getMissionTitle() {
if (mission == null) return "";
return mission.getTitle();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ public interface DiscussionRepository extends JpaRepository<Discussion, Long> {
@Query("""
SELECT d
FROM Discussion d
JOIN FETCH d.mission m
JOIN FETCH d.discussionHashTags.hashTags dhts
JOIN FETCH dhts.hashTag ht
LEFT JOIN FETCH d.mission m
LEFT JOIN FETCH d.discussionHashTags.hashTags dhts
LEFT JOIN FETCH dhts.hashTag ht
WHERE
(LOWER(:mission) = 'all' OR m.title = :mission)
((:mission = null) OR LOWER(:mission) = 'all' OR m.title = :mission)
AND
(LOWER(:hashTag) = 'all' OR EXISTS (
((:hashTag = null) OR LOWER(:hashTag) = 'all' OR EXISTS (
SELECT 1
FROM DiscussionHashTag dht
JOIN dht.hashTag sht
WHERE dht.discussion.id = d.id
AND sht.name = :hashTag
))
ORDER BY d.id DESC
""")
List<Discussion> findAllByMissionAndHashTagName(
@Param("mission") String mission,
Expand Down Expand Up @@ -61,6 +62,7 @@ d.id, count(dc)
FROM Discussion d
JOIN FETCH DiscussionComment dc
ON dc.discussion.id = d.id
WHERE dc.deletedAt IS NULL
GROUP BY d.id
""")
List<DiscussionCommentCount> findDiscussionCommentCounts();
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ VALUES (1, 1, '1', NULL, NULL, '2024-08-16 13:40:00'),
INSERT INTO discussion (title, content, mission_id, member_id, created_at)
VALUES ('객체지향이 뭘까요?', '객체지향에 대해 토론해봅시다.', 1, 1, '2024-09-09 15:30:00'),
('디자인패턴 적용한 거 말해봐요', '저는 빌더 패턴 적용해봤어요', 2, 2, '2024-09-09 15:30:00');
INSERT INTO discussion (title, content, mission_id, member_id, created_at)
VALUES ('객체지향이 뭘까요?', '객체지향에 대해 토론해봅시다.', null, 1, '2024-09-09 15:30:00');

INSERT INTO discussion_hash_tag (discussion_id, hash_tag_id)
VALUES (1, 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import develup.support.data.HashTagTestData;
import develup.support.data.MemberTestData;
import develup.support.data.MissionTestData;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Function;
import develup.domain.discussion.comment.DiscussionComment;
Expand Down Expand Up @@ -166,7 +167,7 @@ private void createDiscussion(Mission mission, HashTag hashTag) {
}

@Test
@DisplayName("디스커션에 달린 댓글의 개수를 조회한다.")
@DisplayName("디스커션에 달린 댓글의 개수를 조회한다. 삭제된 댓글은 제외한다")
@Transactional
void findDiscussionCommentCounts() {
Member member = memberRepository.save(MemberTestData.defaultMember().build());
Expand All @@ -176,6 +177,7 @@ void findDiscussionCommentCounts() {
Discussion savedDiscussion = getSavedDiscussion(mission, member, hashTag);

saveDiscussionComment(savedDiscussion, member);
saveDeletedDiscussionComment(savedDiscussion, member);

DiscussionCommentCounts discussionCommentCounts = new DiscussionCommentCounts(discussionRepository.findDiscussionCommentCounts());
Long count = discussionCommentCounts.getCount(savedDiscussion);
Expand All @@ -199,4 +201,13 @@ private void saveDiscussionComment(Discussion savedDiscussion, Member member) {
.build();
discussionCommentRepository.save(discussionComment);
}

private void saveDeletedDiscussionComment(Discussion savedDiscussion, Member member) {
DiscussionComment discussionComment = DiscussionCommentTestData.defaultDiscussionComment()
.withDiscussion(savedDiscussion)
.withMember(member)
.build();
discussionComment.delete();
discussionCommentRepository.save(discussionComment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ export const HeaderTitleWrapper = styled.div`
export const HeaderTitle = styled.h1`
${(props) => props.theme.font.heading1}
`;

export const NoContentText = styled.h1`
margin-top: 20rem;
text-align: center;
${(props) => props.theme.font.heading2}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ interface DiscussionListContentProps {
export default function DiscussionListContent({ discussions }: DiscussionListContentProps) {
return (
<S.ContentContainer>
{!discussions.length && (
<S.NoContentText>해당 태그에 관련한 디스커션이 존재하지 않아요!</S.NoContentText>
)}
{discussions.map((discussion) => (
<Link key={discussion.id} to={`/discussions/${discussion.id}`}>
<DiscussionListItem
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/common/Error/ErrorFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { HTTP_ERROR_MESSAGE } from '@/constants/api';
import Button from '../Button/Button';
import * as S from './ErrorFallback.styled';
import { ROUTES } from '@/constants/routes';

export interface ErrorFallbackProps {
statusCode: number;
resetError?: () => void;
}

const generateHTTPErrorMessage = (statusCode: number) => {
Expand All @@ -13,15 +12,15 @@ const generateHTTPErrorMessage = (statusCode: number) => {
return errorMessage ?? HTTP_ERROR_MESSAGE.unknown;
};

const ErrorFallback = ({ statusCode, resetError }: ErrorFallbackProps) => {
const ErrorFallback = ({ statusCode }: ErrorFallbackProps) => {
const { heading, body, button } = generateHTTPErrorMessage(statusCode);

return (
<S.Container>
<S.Wrapper>{heading}</S.Wrapper>
<S.Wrapper>{body}</S.Wrapper>
<S.Wrapper>
<Button onClick={resetError}>{button}</Button>
<a href={ROUTES.main}>{button}</a>
</S.Wrapper>
</S.Container>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/common/Error/QueryErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function QueryErrorBoundary({ children }: PropsWithChildren) {
<ErrorBoundary
onReset={reset}
fallbackRender={(props) => {
const { error, resetErrorBoundary } = props;
return <ErrorFallback statusCode={error.statusCode} resetError={resetErrorBoundary} />;
const { error } = props;
return <ErrorFallback statusCode={error.statusCode} />;
}}
>
{children}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/common/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import useUserInfo from '@/hooks/useUserInfo';
import type { PropsWithChildren } from 'react';
import { Navigate } from 'react-router-dom';
import LoadingSpinner from './LoadingSpinner/LoadingSpinner';

interface PrivateRouteProps extends PropsWithChildren {
redirectTo: string;
}

export default function PrivateRoute({ redirectTo, children }: PrivateRouteProps) {
const { data: userInfo } = useUserInfo();
const { data: userInfo, isLoading } = useUserInfo();

if (isLoading) {
return <LoadingSpinner />;
}

return userInfo ? <>{children}</> : <Navigate to={redirectTo} />;
}
Loading