Skip to content

Commit

Permalink
fix:✨ 팀 참가 유저 명단 조회 수정 (#36)
Browse files Browse the repository at this point in the history
* feat: ✨ 참여코드로 팀(방) 참여 기능 구현 (#27)

* feat: ✨ 참여코드로 팀(방) 참여 기능 구현

* docs: 참여코드로 팀(방) 참여 api 문서 수정

* feat: ✨루틴 조회/추가/삭제

* feat: 루틴 생성 기능 수정

* fix: 루틴 조회 수정

* feat: ✨ 팀 생성 시, 팀 이름 설정 추가 (#32)

* feat:✨ 팀 참가 인원 명단 조회

* feat:✨ 팀 참가 인원 명단 조회

* chore:정리

* feat:✨ 팀 루틴 목록 조회

* feat:✨ 팀 루틴 목록 조회

* feat:✨ 팀 루틴 목록 조회

* fix:✨ 팀 참가 유저 명단 조회 수정

---------

Co-authored-by: 이재혁 <[email protected]>
  • Loading branch information
gzhan0226 and LEEJaeHyeok97 authored Sep 28, 2024
1 parent 8716108 commit 2d41951
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse;
import com.goormdari.domain.team.exception.TeamAlreadyExistException;
import com.goormdari.domain.user.domain.User;
import com.goormdari.domain.user.domain.dto.response.findByTeamIdResponse;
import com.goormdari.domain.user.domain.repository.UserRepository;
import com.goormdari.global.config.email.EmailClient;
import com.goormdari.global.payload.Message;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -42,6 +45,19 @@ public findAllRoutineByUserIdResponse findAllRoutineByUserId(Long userId) {
.build();
}

@jakarta.transaction.Transactional
public List<findByTeamIdResponse> findTeamByUserId(Long userId) {
Long teamId = userRepository.findById(userId)
.orElseThrow(()->new NotFoundException("User Not Found")).getTeam().getId();
List<User> users = userRepository.findByTeamId(teamId);
return users.stream()
.map(user -> findByTeamIdResponse.builder()
.id(user.getId())
.username(user.getUsername())
.build())
.collect(Collectors.toList());
}

@Transactional
public CreateTeamResponse createNewTeam(final String username, final CreateTeamRequest createTeamRequest) {
User user = userRepository.findByUsername(username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.goormdari.domain.team.dto.request.CreateTeamRequest;
import com.goormdari.domain.team.dto.response.CreateTeamResponse;
import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse;
import com.goormdari.domain.user.domain.dto.response.findByTeamIdResponse;
import com.goormdari.global.config.security.jwt.JWTUtil;
import com.goormdari.global.payload.ErrorResponse;
import com.goormdari.global.payload.Message;
Expand All @@ -20,6 +21,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Team", description = "Team API")
@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -105,4 +108,25 @@ public ResponseCustom<findAllRoutineByUserIdResponse> getRoutineList(
return ResponseCustom.OK(teamService.findAllRoutineByUserId(userId));
}

@Operation(summary = "팀 참가 유저 명단 조회", description = "팀에 존재하는 유저 명단")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공 ", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = findByTeamIdResponse.class))}),
@ApiResponse(responseCode = "400", description = "조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/user-list")
public ResponseCustom<List<findByTeamIdResponse>> getTeamMember(
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader("Authorization") String token
) {
if (token == null) {
throw new InvalidTokenException();
}

String jwt = token.startsWith("Bearer ") ? token.substring(7) : token;
if (!jwtUtil.validateToken(jwt)) {
throw new IllegalArgumentException("Invalid token");
}
Long userId = jwtUtil.extractId(jwt);
return ResponseCustom.OK(teamService.findTeamByUserId(userId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ public findCurrentStepResponse findCurrentStepById(Long userId) {

return findCurrentStepResponse.builder().currentStep(user.getCurrentStep()).build();
}

@Transactional
public List<findByTeamIdResponse> findTeamByUserId(Long userId) {
Long teamId = userRepository.findById(userId)
.orElseThrow(()->new NotFoundException("User Not Found")).getTeam().getId();
List<User> users = userRepository.findByTeamId(teamId);
return users.stream()
.map(user -> findByTeamIdResponse.builder()
.id(user.getId())
.username(user.getUsername())
.build())
.collect(Collectors.toList());
}
@Transactional
public Long save(AddUserRequest dto) {
// 사용자 이름 중복 체크
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.List;


@Tag(name = "User", description = "Routine API")
@Tag(name = "User", description = "User API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
Expand Down Expand Up @@ -51,24 +51,4 @@ public ResponseCustom<findCurrentStepResponse> getCurrentStep(
return ResponseCustom.OK(userService.findCurrentStepById(userId));
}

@Operation(summary = "팀 참가 유저 명단 조회", description = "같은 팀에 존재하는 유저 명단")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공 ", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = findByTeamIdResponse.class))}),
@ApiResponse(responseCode = "400", description = "조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/team-list")
public ResponseCustom<List<findByTeamIdResponse>> getTeamMember(
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader("Authorization") String token
) {
if (token == null) {
throw new InvalidTokenException();
}

String jwt = token.startsWith("Bearer ") ? token.substring(7) : token;
if (!jwtUtil.validateToken(jwt)) {
throw new IllegalArgumentException("Invalid token");
}
Long userId = jwtUtil.extractId(jwt);
return ResponseCustom.OK(userService.findTeamByUserId(userId));
}
}

0 comments on commit 2d41951

Please sign in to comment.