Skip to content

Commit

Permalink
Merge branch '9oormthon-univ:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEJaeHyeok97 authored Nov 23, 2024
2 parents 47e29b4 + 14f3af3 commit 90ba864
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.jangburich.domain.team.application;

import com.jangburich.domain.common.Status;
import com.jangburich.domain.team.dto.response.MyTeamDetailsResponse;
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jangburich.domain.common.Status;
import com.jangburich.domain.team.domain.Team;
import com.jangburich.domain.team.domain.TeamLeader;
import com.jangburich.domain.team.domain.TeamType;
import com.jangburich.domain.team.domain.UserTeam;
import com.jangburich.domain.team.domain.repository.TeamRepository;
import com.jangburich.domain.team.domain.repository.UserTeamRepository;
import com.jangburich.domain.team.dto.request.RegisterTeamRequest;
import com.jangburich.domain.team.dto.response.MyTeamDetailsResponse;
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamCodeResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import com.jangburich.domain.user.domain.User;
import com.jangburich.domain.user.repository.UserRepository;
import com.jangburich.global.payload.Message;
Expand Down Expand Up @@ -88,10 +90,10 @@ public Message joinTeam(String userId, String joinCode) {

public List<MyTeamResponse> getMyTeamByCategory(String userId, String category) {
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

List<Team> teams = teamRepository.findAllByUserAndStatus(user, Status.ACTIVE)
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹นํ•˜๋Š” ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹นํ•˜๋Š” ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

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

Expand All @@ -101,20 +103,21 @@ public List<MyTeamResponse> getMyTeamByCategory(String userId, String category)
int peopleCount = userTeamRepository.countByTeam(team);

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

if ("ALL".equalsIgnoreCase(category) ||
("LEADER".equalsIgnoreCase(category) && isMeLeader) ||
("MEMBER".equalsIgnoreCase(category) && !isMeLeader)) {
("LEADER".equalsIgnoreCase(category) && isMeLeader) ||
("MEMBER".equalsIgnoreCase(category) && !isMeLeader)) {

MyTeamResponse response = new MyTeamResponse(
team.getName(),
team.getTeamType().toString(),
false, // isLiked๋Š” ์ž„์˜๋กœ false๋กœ ์„ค์ •
peopleCount,
isMeLeader,
profileImageUrls
team.getName(),
team.getTeamType().toString(),
false, // isLiked๋Š” ์ž„์˜๋กœ false๋กœ ์„ค์ •
peopleCount,
isMeLeader,
profileImageUrls
);
myTeamResponses.add(response);
}
Expand All @@ -125,45 +128,68 @@ public List<MyTeamResponse> getMyTeamByCategory(String userId, String category)

public MyTeamDetailsResponse getTeamDetailsById(String userId, Long teamId) {
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹น ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹น ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

if (!team.getTeamLeader().getUser_id().equals(user.getUserId())) {
// ์ผ๋ฐ˜ ๊ตฌ์„ฑ์›
MyTeamDetailsResponse myTeamDetailsAsMember = teamRepository.findMyTeamDetailsAsMember(user.getUserId(),
teamId);
teamId);
return myTeamDetailsAsMember;
}
// ํŒ€ ๋ฆฌ๋”์ผ ๋•Œ
MyTeamDetailsResponse myTeamDetailsAsLeader = teamRepository.findMyTeamDetailsAsLeader(user.getUserId(),
teamId);
teamId);

return myTeamDetailsAsLeader;
}

public List<TeamMemberResponse> getTeamMembers(String userId, Long teamId) {
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new NullPointerException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹นํ•˜๋Š” ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));
.orElseThrow(() -> new IllegalArgumentException("ํ•ด๋‹นํ•˜๋Š” ํŒ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

List<UserTeam> userTeams = userTeamRepository.findAllByTeamAndStatus(team, Status.ACTIVE);

return userTeams.stream()
.map(userTeam -> {
User teamMember = userTeam.getUser();

return new TeamMemberResponse(
teamMember.getUserId(),
teamMember.getName(),
teamMember.getUserId().equals(user.getUserId()),
team.getTeamLeader().getUser_id().equals(teamMember.getUserId()),
Optional.ofNullable(teamMember.getProfileImageUrl()).orElse(DEFAULT_PROFILE_IMAGE_URL)
);
})
.toList();
.map(userTeam -> {
User teamMember = userTeam.getUser();

return new TeamMemberResponse(
teamMember.getUserId(),
teamMember.getName(),
teamMember.getUserId().equals(user.getUserId()),
team.getTeamLeader().getUser_id().equals(teamMember.getUserId()),
Optional.ofNullable(teamMember.getProfileImageUrl()).orElse(DEFAULT_PROFILE_IMAGE_URL)
);
})
.toList();
}

public TeamCodeResponse getTeamsWithSecretCode(String secretCode) {
Team team = teamRepository.findBySecretCode(secretCode)
.orElseThrow(() -> new RuntimeException("์‹œํฌ๋ฆฟ ์ฝ”๋“œ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."));

long count = userTeamRepository.findAllByTeam(team).size();

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

TeamCodeResponse teamCodeResponse = new TeamCodeResponse(
team.getName(),
team.getCreatedAt(),
team.getTeamType(),
count,
profileImages,
team.getStatus());

return teamCodeResponse;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.jangburich.domain.team.dto.response;

import java.time.LocalDateTime;
import java.util.List;

import com.jangburich.domain.common.Status;
import com.jangburich.domain.team.domain.TeamType;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class TeamCodeResponse {
private String teamName;
private LocalDateTime createdAt;
private TeamType teamType;
private Long teamMembers;
private List<String> teamMemberProfileImages;
private Status status;

@Builder
public TeamCodeResponse(String teamName, LocalDateTime createdAt, TeamType teamType, Long teamMembers,
List<String> teamMemberProfileImages, Status status) {
this.teamName = teamName;
this.createdAt = createdAt;
this.teamType = teamType;
this.teamMembers = teamMembers;
this.teamMemberProfileImages = teamMemberProfileImages;
this.status = status;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.jangburich.domain.team.presentation;

import com.jangburich.domain.team.dto.response.MyTeamDetailsResponse;
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import java.util.List;

import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -15,6 +13,10 @@

import com.jangburich.domain.team.application.TeamService;
import com.jangburich.domain.team.dto.request.RegisterTeamRequest;
import com.jangburich.domain.team.dto.response.MyTeamDetailsResponse;
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamCodeResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;
Expand Down Expand Up @@ -53,27 +55,35 @@ public ResponseCustom<Message> joinTeam(
@Operation(summary = "๋‚ด๊ฐ€ ์†ํ•œ ๊ทธ๋ฃน ์กฐํšŒ", description = "๋‚ด๊ฐ€ ์†ํ•œ ๊ทธ๋ฃน์„ ์นดํ…Œ๊ณ ๋ฆฌ(ALL, LEADER, MEMBER) ๋ณ„๋กœ ์กฐํšŒํ•œ๋‹ค.")
@GetMapping
public ResponseCustom<List<MyTeamResponse>> getMyTeamByCategory(
Authentication authentication,
@RequestParam(required = false, defaultValue = "ALL") String category
Authentication authentication,
@RequestParam(required = false, defaultValue = "ALL") String category
) {
return ResponseCustom.OK(teamService.getMyTeamByCategory(AuthenticationParser.parseUserId(authentication), category));
return ResponseCustom.OK(
teamService.getMyTeamByCategory(AuthenticationParser.parseUserId(authentication), category));
}

@Operation(summary = "๊ทธ๋ฃน(ํŒ€) ์ƒ์„ธ ์กฐํšŒ", description = "๋‚ด๊ฐ€ ์†ํ•œ ํŒ€์˜ ์ •๋ณด๋ฅผ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/{teamId}")
public ResponseCustom<MyTeamDetailsResponse> getTeamDetailsById(
Authentication authentication,
@PathVariable Long teamId
Authentication authentication,
@PathVariable Long teamId
) {
return ResponseCustom.OK(teamService.getTeamDetailsById(AuthenticationParser.parseUserId(authentication), teamId));
return ResponseCustom.OK(
teamService.getTeamDetailsById(AuthenticationParser.parseUserId(authentication), teamId));
}

@Operation(summary = "๊ทธ๋ฃน(ํŒ€) ๋ฉค๋ฒ„ ์ „์ฒด ์กฐํšŒ", description = "๊ทธ๋ฃน(ํŒ€)์— ์†Œ์†๋œ ๋ชจ๋“  ๋ฉค๋ฒ„๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/{teamId}/members")
public ResponseCustom<List<TeamMemberResponse>> getTeamMembers(
Authentication authentication,
@PathVariable Long teamId
Authentication authentication,
@PathVariable Long teamId
) {
return ResponseCustom.OK(teamService.getTeamMembers(AuthenticationParser.parseUserId(authentication), teamId));
}

@Operation(summary = "๊ทธ๋ฃน(ํŒ€) ๋น„๋ฐ€์ฝ”๋“œ ์กฐํšŒ", description = "๋น„๋ฐ€์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด, ๊ทธ ํŒ€์„ ์กฐํšŒํ•˜๋Š” api ์ž…๋‹ˆ๋‹ค.")
@GetMapping("/info/{secretCode}")
public ResponseCustom<TeamCodeResponse> getTeamWithSecretCode(@PathVariable String secretCode) {
return ResponseCustom.OK(teamService.getTeamsWithSecretCode(secretCode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public class UserService {
private long refreshTokenExpiration;

public KakaoApiResponseDTO getUserInfo(String accessToken) {
User user = userRepository.findByProviderId(accessToken)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));



String userInfoUrl = "https://kapi.kakao.com/v2/user/me";

HttpHeaders headers = new HttpHeaders();
Expand All @@ -80,7 +75,7 @@ public User getUserInfos(String accessToken) {
@Transactional
public TokenResponseDTO joinUser(String kakaoaccessToken) {
KakaoApiResponseDTO userInfo = getUserInfo(kakaoaccessToken);

System.out.println("userInfo = " + userInfo);
User user = userRepository.findByProviderId("kakao_" + userInfo.getId()).orElse(null);
if (user == null) {
user = userRepository.save(User.create("kakao_" + userInfo.getId(), userInfo.getProperties().getNickname(),
Expand Down

0 comments on commit 90ba864

Please sign in to comment.