Skip to content
Merged
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ out/
.vscode/

application*.yml

### mapstruct ###

/src/main/generated/
1 change: 1 addition & 0 deletions src/main/java/com/dowe/exception/ErrorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ErrorType {
MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "멤버가 존재하지 않습니다"),

// Team
TEAM_CREATION_LIMIT_EXCEPTION(HttpStatus.CONFLICT, "사용자가 이미 5개의 팀에 참여 중이라 새로운 팀을 생성할 수 없습니다."),
MEMBER_IS_ALREADY_IN_TEAM(HttpStatus.BAD_REQUEST, "이미 소속된 팀입니다"),
TEAM_IS_FULL(HttpStatus.BAD_REQUEST, "팀이 가득 차 참여할 수 없습니다");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dowe.exception.team;

import com.dowe.exception.CustomException;
import com.dowe.exception.ErrorType;

public class TeamCreationLimitException extends CustomException {

public TeamCreationLimitException() {
super(ErrorType.TEAM_CREATION_LIMIT_EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public Profile createDefaultProfile(
return profileRepository.save(defaultProfile);
}

public long countProfiles(
Long memberId
) {
return profileRepository.countByMemberId(memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
import com.dowe.profile.Profile;

public interface ProfileRepository extends JpaRepository<Profile, Long> {

long countByMemberId(Long memberId);

}
12 changes: 10 additions & 2 deletions src/main/java/com/dowe/team/application/TeamService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dowe.team.application;

import static com.dowe.util.AppConstants.*;

import com.dowe.exception.team.TeamCreationLimitException;
import com.dowe.profile.application.ProfileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -9,7 +12,6 @@
import com.dowe.member.Member;
import com.dowe.member.infrastructure.MemberRepository;
import com.dowe.profile.Profile;
import com.dowe.profile.infrastructure.ProfileRepository;
import com.dowe.team.Team;
import com.dowe.team.dto.NewTeam;
import com.dowe.team.dto.TeamSettings;
Expand All @@ -28,7 +30,6 @@ public class TeamService {

private final TeamRepository teamRepository;
private final MemberRepository memberRepository;
private final ProfileRepository profileRepository;
private final S3Uploader s3Uploader;

private final ProfileService profileService;
Expand All @@ -41,6 +42,13 @@ public NewTeam create(Long memberId, TeamSettings teamSettings) {
Member member = memberRepository.findById(memberId)
.orElseThrow(MemberNotFoundException::new);

long profileCount = profileService.countProfiles(member.getId());
log.info(">>> ProfileService create() profileCount for member {} : {}", memberId, profileCount);

if (profileCount == MAXIMUM_TEAM_COUNT) {
throw new TeamCreationLimitException();
}

String image = null;
if (teamSettings.getImage() != null && !teamSettings.getImage().isEmpty()) {
image = s3Uploader.upload(TEAM_IMAGE_DIRECTORY, teamSettings.getImage());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dowe/util/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class AppConstants {
public static final String X_WWW_FORM_URLENCODED_CHARSET_UTF_8 = "application/x-www-form-urlencoded;charset=utf-8";

public static final String MEMBER_ID = "memberId";
public static final int MAXIMUM_TEAM_COUNT = 5;
public static final String AUTHORIZATION_CODE = "authorization_code";
public static final String TOKEN_TYPE = "tokenType";
public static final String TEAM_TITLE = "title";
Expand Down