Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/amcamp/domain/team/api/TeamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -78,6 +79,7 @@ public TeamAdminResponse teamFindAdmin(@PathVariable Long teamId) {
return teamService.findTeamAdmin(teamId);
}

@Deprecated
@Operation(summary = "팀 목록 조회", description = "회원이 참여한 팀 목록을 조회합니다.")
@GetMapping("/list")
public Slice<TeamInfoResponse> teamFindAll(
Expand All @@ -88,4 +90,10 @@ public Slice<TeamInfoResponse> teamFindAll(
int pageSize) {
return teamService.findAllTeam(lastTeamId, pageSize);
}

@Operation(summary = "팀 목록 조회 V2", description = "회원이 참여한 팀 목록을 조회합니다.")
@GetMapping("/list/all")
public List<TeamInfoResponse> teamFindAll() {
return teamService.findAllTeam();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.amcamp.global.util.MemberUtil;
import com.amcamp.global.util.RandomUtil;
import com.amcamp.global.util.RedisUtil;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Slice;
Expand Down Expand Up @@ -179,6 +180,12 @@ public Slice<TeamInfoResponse> findAllTeam(Long lastTeamId, int pageSize) {
return teamRepository.findAllTeamByMemberId(currentMember.getId(), lastTeamId, pageSize);
}

@Transactional(readOnly = true)
public List<TeamInfoResponse> findAllTeam() {
Member currentMember = memberUtil.getCurrentMember();
return teamRepository.findAllTeamByMemberId(currentMember.getId());
}

@Transactional(readOnly = true)
public TeamAdminResponse findTeamAdmin(Long teamId) {
Member member = memberUtil.getCurrentMember();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.amcamp.domain.team.dao;

import com.amcamp.domain.team.dto.response.TeamInfoResponse;
import java.util.List;
import org.springframework.data.domain.Slice;

public interface TeamRepositoryCustom {
Slice<TeamInfoResponse> findAllTeamByMemberId(Long memberId, Long lastTeamId, int pageSize);

List<TeamInfoResponse> findAllTeamByMemberId(Long memberId);
}
37 changes: 24 additions & 13 deletions src/main/java/com/amcamp/domain/team/dao/TeamRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.amcamp.global.exception.errorcode.TeamErrorCode;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,19 +27,8 @@ public class TeamRepositoryImpl implements TeamRepositoryCustom {
public Slice<TeamInfoResponse> findAllTeamByMemberId(
Long memberId, Long lastTeamId, int pageSize) {
List<TeamInfoResponse> results =
jpaQueryFactory
.select(
Projections.constructor(
TeamInfoResponse.class,
team.id,
team.name,
team.description,
team.emoji))
.from(teamParticipant)
.leftJoin(teamParticipant.team, team)
.on(team.id.eq(teamParticipant.team.id))
.where(lastTeamId(lastTeamId), teamParticipant.member.id.eq(memberId))
.orderBy(teamParticipant.createdDt.desc())
createTeamQueryByMemberId(memberId)
.where(lastTeamId(lastTeamId))
.limit(pageSize + 1)
.fetch();

Expand All @@ -49,6 +39,27 @@ public Slice<TeamInfoResponse> findAllTeamByMemberId(
return checkLastPage(pageSize, results);
}

@Override
public List<TeamInfoResponse> findAllTeamByMemberId(Long memberId) {
return createTeamQueryByMemberId(memberId).fetch();
}

private JPAQuery<TeamInfoResponse> createTeamQueryByMemberId(Long memberId) {
return jpaQueryFactory
.select(
Projections.constructor(
TeamInfoResponse.class,
team.id,
team.name,
team.description,
team.emoji))
.from(teamParticipant)
.leftJoin(teamParticipant.team, team)
.on(team.id.eq(teamParticipant.team.id))
.where(teamParticipant.member.id.eq(memberId))
.orderBy(teamParticipant.createdDt.desc());
}

private BooleanExpression lastTeamId(Long teamId) {
if (teamId == null) {
return null;
Expand Down