Skip to content

Commit

Permalink
feat: v0.4.3을 배포한다. (#486)
Browse files Browse the repository at this point in the history
* feat: DB에 인덱스를 적용한다 (#449)

* feat: 엔티티에 index 적용

* build: flyway 세팅 적용

* fix: flyway sql문 오타 수정

* chore: flyway 버전 및 파일명 변경

* feat: 불필요한 이메일 인덱싱 제거

* fix: 작성한 메시지 개수를 해당페이지 개수로만 가져오는 버그 수정 (#474)

* fix: 작성한 메시지 개수를 해당페이지 개수로만 가져오는 버그 수정 - 리팩터링 필요 (#477)

* fix: 작성한 메시지 개수를 해당페이지 개수로만 가져오는 버그 수정 - 리팩터링 필요 (#478)

* fix: 작성한 메시지 개수를 해당페이지 개수로만 가져오는 버그 수정 - 리팩터링 필요

* fix: 잘못된 querydsl JPQL로 임시로 변환 (#479)

* refactor: requestApi 함수 수정

* feat: error page 수정 (#481)

* fix: 멤버에게 롤링페이퍼 생성 페이지의 받는 사람 자동 완성 버그 수정

* fix: 오타 수정

Co-authored-by: TaeHyeon Kim <[email protected]>
Co-authored-by: SunHo Park <[email protected]>
Co-authored-by: seungpang <[email protected]>
Co-authored-by: yxxnghwan <[email protected]>
Co-authored-by: asebn1 <[email protected]>
  • Loading branch information
6 people authored Sep 23, 2022
1 parent 0fbb6cd commit cba53c6
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Table(name = "member")
@Table(name = "member", indexes = {
@Index(name = "member_oauth_index", columnList = "platform, platform_id")
})
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
Expand All @@ -19,7 +20,9 @@

@Entity
@Getter
@Table(name = "message")
@Table(name = "message", indexes = {
@Index(name = "message_rollingpaper_index", columnList = "rollingpaper_id")
})
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Message extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
Expand All @@ -18,6 +19,10 @@
@Entity
@Table(
name = "team_participation",
indexes = {
@Index(name = "team_participation_team_index", columnList = "team_id"),
@Index(name = "team_participation_member_index", columnList = "member_id")
},
uniqueConstraints = {
@UniqueConstraint(
name = "participate_duplicate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
Expand All @@ -21,7 +22,9 @@

@Entity
@Getter
@Table(name = "rollingpaper")
@Table(name = "rollingpaper", indexes = {
@Index(name = "rollingpaper_team_index", columnList = "team_id")
})
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Rollingpaper extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
package com.woowacourse.naepyeon.repository.message;

import com.woowacourse.naepyeon.domain.Message;
import com.woowacourse.naepyeon.service.dto.WrittenMessageResponseDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MessageRepository extends JpaRepository<Message, Long>, MessageRepositoryCustom {

@Query(value = "select distinct new com.woowacourse.naepyeon.service.dto.WrittenMessageResponseDto"
+ "(m.id, r.id, r.title, t.id, t.name, m.content, m.color, "
+ "case when r.recipient = com.woowacourse.naepyeon.domain.rollingpaper.Recipient.MEMBER then p.nickname "
+ "when r.recipient = com.woowacourse.naepyeon.domain.rollingpaper.Recipient.TEAM then t.name "
+ "else '' end) "
+ "from Message m"
+ ", Rollingpaper r"
+ ", Team t"
+ ", TeamParticipation p "
+ "where m.rollingpaper.id = r.id "
+ "and r.team.id = t.id "
+ "and p.team.id = t.id "
+ "and m.author.id = :authorId "
+ "and (p.member.id = r.member.id or r.member.id is null)")
Page<WrittenMessageResponseDto> findAllByAuthorId(@Param("authorId") final Long authorId,
final Pageable pageRequest);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.woowacourse.naepyeon.repository.message;

import com.woowacourse.naepyeon.domain.Message;
import com.woowacourse.naepyeon.service.dto.WrittenMessageResponseDto;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface MessageRepositoryCustom {

List<Message> findAllByRollingpaperId(final Long rollingpaperId);

Page<WrittenMessageResponseDto> findAllByAuthorId(final Long authorId, final Pageable pageRequest);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
package com.woowacourse.naepyeon.repository.message;

import static com.woowacourse.naepyeon.domain.QMessage.message;
import static com.woowacourse.naepyeon.domain.QTeamParticipation.teamParticipation;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.ConstructorExpression;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.woowacourse.naepyeon.domain.Message;
import com.woowacourse.naepyeon.domain.rollingpaper.Recipient;
import com.woowacourse.naepyeon.service.dto.WrittenMessageResponseDto;
import java.util.List;
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

@RequiredArgsConstructor
public class MessageRepositoryImpl implements MessageRepositoryCustom {
Expand All @@ -33,60 +23,10 @@ public List<Message> findAllByRollingpaperId(final Long rollingpaperId) {
.fetch();
}

@Override
public Page<WrittenMessageResponseDto> findAllByAuthorId(final Long authorId, final Pageable pageRequest) {
final JPAQuery<WrittenMessageResponseDto> query = getQueryWhenFindAllByAuthorId(authorId);

final List<WrittenMessageResponseDto> content = query
.offset(pageRequest.getOffset())
.limit(pageRequest.getPageSize())
.fetch();
final long total = query
.stream()
.count();

return new PageImpl<>(content, pageRequest, total);
}

private JPAQuery<WrittenMessageResponseDto> getQueryWhenFindAllByAuthorId(final Long authorId) {
return queryFactory
.select(makeProjections())
.from(message)
.join(teamParticipation).on(message.rollingpaper.team.id.eq(teamParticipation.team.id))
.where(isAuthorIdEq(authorId)
.and(message.rollingpaper.member.id.isNull()
.or(message.rollingpaper.member.id.eq(teamParticipation.member.id))
)
)
.distinct();
}

private ConstructorExpression<WrittenMessageResponseDto> makeProjections() {
return Projections.constructor(WrittenMessageResponseDto.class,
message.id,
message.rollingpaper.id,
message.rollingpaper.title,
message.rollingpaper.team.id,
message.rollingpaper.team.name,
message.content,
message.color,
new CaseBuilder()
.when(message.rollingpaper.recipient.eq(Recipient.MEMBER))
.then(teamParticipation.nickname)
.when(message.rollingpaper.recipient.eq(Recipient.TEAM))
.then(message.rollingpaper.team.name)
.otherwise("")
);
}

private BooleanBuilder isRollingpaperIdEq(final Long rollingpaperId) {
return nullSafeBuilder(() -> message.rollingpaper.id.eq(rollingpaperId));
}

private BooleanBuilder isAuthorIdEq(final Long authorId) {
return nullSafeBuilder(() -> message.author.id.eq(authorId));
}

private BooleanBuilder nullSafeBuilder(Supplier<BooleanExpression> f) {
try {
return new BooleanBuilder(f.get());
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ google:
client-secret: ${GOOGLE_CLIENT_SECRET}

logging:
config: classpath:log4j2.yml
config: classpath:log4j2.yml
9 changes: 9 additions & 0 deletions backend/src/main/resources/db/migration/V0.4.2__db_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE INDEX member_oauth_index ON member (platform, platform_id);

CREATE INDEX message_rollingpaper_index ON message (rollingpaper_id);

CREATE INDEX rollingpaper_team_index ON rollingpaper (team_id);

CREATE INDEX team_participation_team_index ON team_participation (team_id);

CREATE INDEX team_participation_member_index ON team_participation (member_id);
2 changes: 1 addition & 1 deletion backend/src/main/resources/log4j2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Configutation:
additivity: false
level: info
AppenderRef:
- ref: Console_Appender
- ref: Console_Appender
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,21 @@ class MessageRepositoryTest {
"#123456",
false
);
private final Team team2 = new Team(
"nae-pyeon2",
"테스트 모임입니다.",
"testEmoji",
"#123456",
false
);
private final Member member = new Member("member", "[email protected]", Platform.KAKAO, "1");
private final Member author = new Member("author", "[email protected]", Platform.KAKAO, "2");
private final Rollingpaper rollingpaper = new Rollingpaper("AlexAndKei", Recipient.MEMBER, team, member);

@BeforeEach
void setUp() {
teamRepository.save(team);
teamRepository.save(team2);
memberRepository.save(member);
memberRepository.save(author);
rollingpaperRepository.save(rollingpaper);
Expand Down Expand Up @@ -114,6 +122,10 @@ void findAllByMemberIdAndPageRequest() {
teamParticipationRepository.save(teamParticipation1);
final TeamParticipation teamParticipation2 = new TeamParticipation(team, author, "작성자");
teamParticipationRepository.save(teamParticipation2);
final TeamParticipation teamParticipation3 = new TeamParticipation(team2, member, "멤버");
teamParticipationRepository.save(teamParticipation3);
final TeamParticipation teamParticipation4 = new TeamParticipation(team2, author, "작성자");
teamParticipationRepository.save(teamParticipation4);

final Message message1 = createMessage();
messageRepository.save(message1);
Expand All @@ -125,18 +137,37 @@ void findAllByMemberIdAndPageRequest() {
messageRepository.save(message4);
final Message message5 = createMessage();
messageRepository.save(message5);
final Message message6 = createMessage();
messageRepository.save(message6);
final Message message7 = createMessage();
messageRepository.save(message7);
final Message message8 = createMessage();
messageRepository.save(message8);
final Message message9 = createMessage();
messageRepository.save(message9);
final Message message10 = createMessage();
messageRepository.save(message10);
final Message message11 = createMessage();
messageRepository.save(message11);
final Message message12 = createMessage();
messageRepository.save(message12);
final List<WrittenMessageResponseDto> expected = List.of(
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message3),
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message4)
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message6),
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message7),
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message8),
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message9),
WrittenMessageResponseDto.of(rollingpaper, team, "멤버", message10)
);

final Page<WrittenMessageResponseDto> writtenMessageResponseDtos =
messageRepository.findAllByAuthorId(author.getId(), PageRequest.of(1, 2));
messageRepository.findAllByAuthorId(author.getId(), PageRequest.of(1, 5));
final List<WrittenMessageResponseDto> actual = writtenMessageResponseDtos.getContent();

assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected);
assertAll(
() -> assertThat(writtenMessageResponseDtos.getTotalElements()).isEqualTo(12),
() -> assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected)
);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const App = () => {

return (
<PageContainer>
<ErrorBoundary fallback={<div>👻👻👻👻</div>}>
<ErrorBoundary fallback={<ErrorPage />}>
<UserProvider
initialData={
data && {
Expand Down
22 changes: 9 additions & 13 deletions frontend/src/api/googleOauth.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { appClient, requestApi } from "@/api";

import { ApiOptions } from "@/types/api";
import { postGoogleOauthRequest } from "@/types/apiRequest";

const postGoogleOauth = async (
{ authorizationCode, redirectUri }: postGoogleOauthRequest,
options?: ApiOptions
) =>
requestApi(
() =>
appClient.post("/oauth/google", {
authorizationCode,
redirectUri,
}),
options
const postGoogleOauth = async ({
authorizationCode,
redirectUri,
}: postGoogleOauthRequest) =>
requestApi(() =>
appClient.post("/oauth/google", {
authorizationCode,
redirectUri,
})
);

export { postGoogleOauth };
26 changes: 4 additions & 22 deletions frontend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,10 @@ const setAppClientHeaderAuthorization = (accessToken: string) => {
appClient.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
};

const requestApi = async (
request: () => Promise<any>,
options?: ApiOptions
) => {
try {
const { data } = await request();

return data;
} catch (error) {
const axiosError = error as AxiosError;

if (axiosError.response) {
const { errorCode, message } = axiosError.response
.data as ApiErrorResponse;

throw new ApiError({
errorCode,
message,
errorHandler: options?.onError,
});
}
}
const requestApi = async (request: () => Promise<any>) => {
const { data } = await request();

return data;
};

export { appClient, queryClient, setAppClientHeaderAuthorization, requestApi };
Loading

0 comments on commit cba53c6

Please sign in to comment.