Skip to content

Commit

Permalink
feat: 내 그룹 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEJaeHyeok97 committed Nov 20, 2024
1 parent 2ffe327 commit e82f58c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.amazonaws.services.kms.model.NotFoundException;
import com.jangburich.domain.common.Status;
import com.jangburich.domain.menu.domain.Menu;
import com.jangburich.domain.menu.domain.repository.MenuRepository;
import com.jangburich.domain.menu.repository.MenuRepository;
import com.jangburich.domain.order.domain.Cart;
import com.jangburich.domain.order.domain.OrderStatus;
import com.jangburich.domain.order.domain.Orders;
Expand All @@ -15,8 +15,7 @@
import com.jangburich.domain.order.dto.response.GetCartItemsResponse;
import com.jangburich.domain.order.dto.response.OrderResponse;
import com.jangburich.domain.store.domain.Store;
import com.jangburich.domain.store.domain.repository.StoreRepository;
import com.jangburich.domain.store.domain.repository.StoreTeamRepository;
import com.jangburich.domain.store.repository.StoreRepository;
import com.jangburich.domain.team.domain.Team;
import com.jangburich.domain.team.domain.repository.TeamRepository;
import com.jangburich.domain.user.domain.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.jangburich.domain.team.application;

import com.jangburich.domain.common.Status;
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -77,4 +81,38 @@ public Message joinTeam(String userId, String joinCode) {
.message("팀에 성공적으로 참여하였습니다.")
.build();
}

public List<MyTeamResponse> getMyTeamByCategory(String userId, String category) {
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException());

List<Team> teams = teamRepository.findAllByUserAndStatus(user, Status.ACTIVE)
.orElseThrow(() -> new IllegalArgumentException("해당하는 팀을 찾을 수 없습니다."));

List<MyTeamResponse> myTeamResponses = new ArrayList<>();

for (Team team : teams) {
boolean isMeLeader = team.getTeamLeader().getUser_id().equals(user.getUserId());

int peopleCount = userTeamRepository.countByTeam(team);

List<String> profileImageUrls = userTeamRepository.findAllByTeam(team).stream()
.map(userTeam -> userTeam.getUser().getProfileImageUrl())
.toList();

if ("ALL".equalsIgnoreCase(category) || team.getTeamType().toString().equalsIgnoreCase(category)) {
MyTeamResponse response = new MyTeamResponse(
team.getName(),
team.getTeamType().toString(),
false, // isLiked는 임의로 false로 설정
peopleCount,
isMeLeader,
profileImageUrls
);
myTeamResponses.add(response);
}
}

return myTeamResponses;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.jangburich.domain.team.domain.repository;

import com.jangburich.domain.common.Status;
import com.jangburich.domain.team.domain.Team;
import com.jangburich.domain.user.domain.User;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface TeamRepository extends JpaRepository<Team, Long> {
Optional<Team> findBySecretCode(String joinCode);

@Query("SELECT t FROM Team t JOIN UserTeam ut ON ut.team = t WHERE ut.user = :user AND t.status = :status")
Optional<List<Team>> findAllByUserAndStatus(@Param("user") User user, @Param("status") Status status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.jangburich.domain.team.domain.Team;
import com.jangburich.domain.team.domain.UserTeam;
import com.jangburich.domain.user.domain.User;
import java.util.Collection;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserTeamRepository extends JpaRepository<UserTeam, Long> {
int countByTeam(Team team);

boolean existsByUserAndTeam(User user, Team team);

List<UserTeam> findAllByTeam(Team team);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jangburich.domain.team.dto.response;

import java.util.List;

public record MyTeamResponse(
String teamName,
String teamType,
Boolean isLiked,
int peopleCount,
Boolean isMeLeader,
List<String> profileImageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.jangburich.domain.team.presentation;

import com.jangburich.domain.team.dto.response.MyTeamResponse;
import java.util.List;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jangburich.domain.team.application.TeamService;
Expand Down Expand Up @@ -43,4 +47,13 @@ public ResponseCustom<Message> joinTeam(
) {
return ResponseCustom.OK(teamService.joinTeam(AuthenticationParser.parseUserId(authentication), joinCode));
}

@Operation(summary = "내가 속한 그룹 조회", description = "내가 속한 그룹을 카테고리(전체, 그룹장, 그룹원) 별로 조회한다.")
@GetMapping
public ResponseCustom<List<MyTeamResponse>> getMyTeamByCategory(
Authentication authentication,
@RequestParam(required = false, defaultValue = "ALL") String category
) {
return ResponseCustom.OK(teamService.getMyTeamByCategory(AuthenticationParser.parseUserId(authentication), category));
}
}

0 comments on commit e82f58c

Please sign in to comment.