Skip to content

Commit

Permalink
refactor(user): Max 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
NameIsUser06 committed Apr 16, 2024
1 parent 1ce5173 commit b22ad27
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/main/java/com/project/bumawiki/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.List;

import com.project.bumawiki.domain.thumbsup.domain.ThumbsUp;
import com.project.bumawiki.domain.thumbsup.exception.AlreadyThumbsUpException;
import com.project.bumawiki.domain.thumbsup.exception.YouDontThumbsUpThisDocs;
import com.project.bumawiki.domain.thumbsup.presentation.dto.ThumbsUpResponseDto;
import com.project.bumawiki.domain.user.domain.authority.Authority;

Expand All @@ -19,6 +17,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.Max;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -43,38 +42,26 @@ public class User {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Max(32)
@Column(unique = true, length = 32)
private String email;

@Max(16)
@Column(length = 16)
private String name;

@Max(8)
@Column(length = 8)
private Integer enroll;

@Max(20)
@Column(length = 20)
private String nickName;

@Enumerated(EnumType.STRING)
@Column(length = 16)
private Authority authority;

public void cancelThumbsUp(ThumbsUp thumbsUp) {
boolean removed = thumbsUps
.removeIf(thumbsUp::equals);

if (!removed) {
throw YouDontThumbsUpThisDocs.EXCEPTION;
}
}

public void addThumbsUp(ThumbsUp thumbsUp) {
boolean anyMatch = thumbsUps
.stream()
.anyMatch(iterThumbsUp -> iterThumbsUp.equals(thumbsUp));

if (anyMatch) {
throw AlreadyThumbsUpException.EXCEPTION;
}
this.thumbsUps.add(thumbsUp);
}

public List<ThumbsUpResponseDto> getList() {
return this.thumbsUps
.stream()
Expand Down

0 comments on commit b22ad27

Please sign in to comment.