Skip to content

Commit

Permalink
[FIX] 중복 로직 수정! (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
tidavid1 authored Feb 20, 2024
1 parent 6d32d73 commit a735e24
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface UserSwagger {
schema = @Schema(implementation = ErrorResponse.class),
examples = {
@ExampleObject(name = "E020103", value = SwaggerUserErrorExamples.INVALID_USER_NAME),
@ExampleObject(name = "E020105", value = SwaggerUserErrorExamples.USER_WANTED_JOB_DUPLICATE)
})),
@ApiResponse(responseCode = "404", description = "OAuth2 정보가 존재하지 않음",
content = @Content(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class SwaggerUserErrorExamples {

public static final String USER_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E020301\",\"message\":\"해당 유저가 존재하지 않습니다.\"}";
public static final String USER_WANTED_JOB_DUPLICATE = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020105\",\"message\":\"중복된 희망 직무가 있습니다.\"}";
public static final String INVALID_USER_NAME = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020103\",\"message\":\"유저 이름은 비어있을 수 없습니다.\"}";

private SwaggerUserErrorExamples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
import io.oeid.mogakgo.domain.user.application.dto.res.UserSignUpResponse;
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.domain.UserWantedJobTag;
import io.oeid.mogakgo.domain.user.domain.enums.DevelopLanguage;
import io.oeid.mogakgo.domain.user.domain.enums.WantedJob;
import io.oeid.mogakgo.domain.user.exception.UserException;
import io.oeid.mogakgo.domain.user.infrastructure.UserWantedJobTagJpaRepository;
import io.oeid.mogakgo.exception.code.ErrorCode400;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -23,6 +29,7 @@ public class UserService {
public UserSignUpResponse userSignUp(UserSignUpRequest userSignUpRequest) {
User user = userCommonService.getUserById(userSignUpRequest.getUserId());
user.updateUsername(userSignUpRequest.getUsername());
validateWantedJobDuplicate(userSignUpRequest.getWantedJobs());
for (WantedJob wantedJob : userSignUpRequest.getWantedJobs()) {
userWantedJobTagRepository.save(UserWantedJobTag.builder()
.user(user)
Expand All @@ -33,7 +40,7 @@ public UserSignUpResponse userSignUp(UserSignUpRequest userSignUpRequest) {
return UserSignUpResponse.from(user);
}

public UserProfileResponse getUserProfile(Long userId){
public UserProfileResponse getUserProfile(Long userId) {
User user = userCommonService.getUserById(userId);
return UserProfileResponse.from(user);
}
Expand All @@ -44,4 +51,18 @@ public void deleteUser(Long userId) {
user.delete();
}

private void validateWantedJobDuplicate(List<WantedJob> wantedJobs) {
Set<WantedJob> wantedJobSet = new HashSet<>(wantedJobs);
if (wantedJobSet.size() != wantedJobs.size()) {
throw new UserException(ErrorCode400.USER_WANTED_JOB_DUPLICATE);
}
}

private void validateDevelopLanguageDuplicate(List<DevelopLanguage> developLanguages) {
Set<DevelopLanguage> developLanguageSet = new HashSet<>(developLanguages);
if (developLanguageSet.size() != developLanguages.size()) {
throw new UserException(ErrorCode400.USER_DEVELOP_LANGUAGE_DUPLICATE);
}
}

}
17 changes: 12 additions & 5 deletions src/main/java/io/oeid/mogakgo/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class User {
private String githubUrl;



@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@OrderBy("byteSize ASC")
private final List<UserDevelopLanguageTag> userDevelopLanguageTags = new ArrayList<>();
Expand Down Expand Up @@ -146,22 +145,30 @@ public void updateGithubInfo(String githubId, String avatarUrl, String githubUrl
}

public void updateUsername(String username) {
if(username == null || username.isBlank()){
if (username == null || username.isBlank()) {
throw new UserException(ErrorCode400.USERNAME_SHOULD_BE_NOT_EMPTY);
}
this.username = username;
}

public void delete(){
public void delete() {
this.deletedAt = LocalDateTime.now();
}

public void signUpComplete(){
public void deleteAllWantJobTags() {
this.userWantedJobTags.clear();
}

public void deleteAllDevelopLanguageTags() {
this.userDevelopLanguageTags.clear();
}

public void signUpComplete() {
this.signupYn = true;
}

public void updateRegion(Region region) {
if(region == null){
if (region == null) {
throw new UserException(ErrorCode400.USER_REGION_SHOULD_BE_NOT_EMPTY);
}
this.region = region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public enum ErrorCode400 implements ErrorCode {
USER_WANTED_JOB_BAD_REQUEST("E020102", "희망 직무는 3개까지만 등록 가능합니다."),
USERNAME_SHOULD_BE_NOT_EMPTY("E020103", "유저 이름은 비어있을 수 없습니다."),
USER_REGION_SHOULD_BE_NOT_EMPTY("E020104", "유저 지역은 비어있을 수 없습니다."),
USER_WANTED_JOB_DUPLICATE("E020105", "중복된 희망 직무가 있습니다."),
USER_DEVELOP_LANGUAGE_DUPLICATE("E020106", "중복된 개발 언어가 있습니다."),
USER_ID_NOT_NULL("E020001", "유저 아이디는 필수값입니다."),

INVALID_PROJECT_STATUS_TO_ACCEPT("E050101", "프로젝트가 대기중이 아니여서 참여 요청을 수락할 수 없습니다."),
Expand Down

0 comments on commit a735e24

Please sign in to comment.