-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from it-s-time-goat/dev/ldy/directory
[FEAT] 폴더 관련 미구현 부분 추가 구현
- Loading branch information
Showing
14 changed files
with
153 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/goat/server/directory/domain/type/DirectoryColor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.goat.server.directory.domain.type; | ||
|
||
public enum DirectoryColor { | ||
RED, | ||
ORANGE, | ||
YELLOW, | ||
PINK, | ||
GREEN, | ||
CYAN, | ||
BLUE, | ||
PURPLE, | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/goat/server/directory/domain/type/DirectoryIcon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.goat.server.directory.domain.type; | ||
|
||
public enum DirectoryIcon { | ||
PENCIL, | ||
BOOK, | ||
INSIGHT, | ||
BOOK2 | ||
} |
10 changes: 8 additions & 2 deletions
10
src/main/java/com/goat/server/directory/dto/request/DirectoryInitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package com.goat.server.directory.dto.request; | ||
|
||
import com.goat.server.directory.domain.Directory; | ||
import com.goat.server.directory.domain.type.DirectoryColor; | ||
import com.goat.server.directory.domain.type.DirectoryIcon; | ||
import com.goat.server.directory.util.EnumValid; | ||
import com.goat.server.mypage.domain.User; | ||
|
||
public record DirectoryInitRequest( | ||
String directoryName, | ||
Long parentDirectoryId, | ||
String directoryColor | ||
@EnumValid(enumClass = DirectoryColor.class) String directoryColor, | ||
@EnumValid(enumClass = DirectoryIcon.class) String directoryIcon, | ||
String directoryDescription | ||
) { | ||
public Directory toEntity(User user, Directory parentDirectory) { | ||
return Directory.builder() | ||
.user(user) | ||
.parentDirectory(parentDirectory) | ||
.depth(parentDirectory == null ? 1 : parentDirectory.getDepth() + 1) | ||
.title(directoryName) | ||
.directoryColor(directoryColor) | ||
.directoryColor(DirectoryColor.valueOf(directoryColor)) | ||
.directoryIcon(DirectoryIcon.valueOf(directoryIcon)) | ||
.build(); | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
src/main/java/com/goat/server/directory/dto/response/DirectoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
package com.goat.server.directory.dto.response; | ||
|
||
import com.goat.server.directory.domain.Directory; | ||
import com.goat.server.directory.domain.type.DirectoryColor; | ||
import com.goat.server.directory.domain.type.DirectoryIcon; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record DirectoryResponse( | ||
Long directoryId, | ||
String directoryName, | ||
String directoryColor | ||
DirectoryColor directoryColor, | ||
DirectoryIcon directoryIcon | ||
) { | ||
|
||
public static DirectoryResponse from(Directory directory) { | ||
return DirectoryResponse.builder() | ||
.directoryId(directory.getId()) | ||
.directoryName(directory.getTitle()) | ||
.directoryColor(directory.getDirectoryColor()) | ||
.directoryIcon(directory.getDirectoryIcon()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/goat/server/directory/util/EnumValid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.goat.server.directory.util; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.FIELD, ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = EnumValidator.class) | ||
public @interface EnumValid { | ||
|
||
Class<? extends Enum<?>> enumClass(); | ||
String message() default "지정되지 않은 Enum 값입니다."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/goat/server/directory/util/EnumValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.goat.server.directory.util; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import java.util.Arrays; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class EnumValidator implements ConstraintValidator<EnumValid, String> { | ||
private Set<String> acceptedValues; | ||
|
||
@Override | ||
public void initialize(EnumValid enumAnnotation) { | ||
acceptedValues = Arrays.stream(enumAnnotation.enumClass().getEnumConstants()) | ||
.map(Enum::name) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
return acceptedValues.contains(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.