-
Notifications
You must be signed in to change notification settings - Fork 4
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 #25 from sjmjys954646/feature/3-branch-mentoring
mentorPost 버그 수정 및 Enum형 추가
- Loading branch information
Showing
6 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/demo/config/utils/StateConverter.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,27 @@ | ||
package com.example.demo.config.utils; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class StateConverter implements AttributeConverter<StateEnum, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(StateEnum attribute) { | ||
return Optional.ofNullable(attribute).orElse(StateEnum.NULL).getValue(); | ||
} | ||
|
||
@Override | ||
public StateEnum convertToEntityAttribute(String dbData) { | ||
if (dbData == null || dbData.length() == 0) { | ||
return StateEnum.NULL; | ||
} | ||
return StateEnum.findOf(dbData); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/demo/config/utils/StateEnum.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,32 @@ | ||
package com.example.demo.config.utils; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Getter | ||
public enum StateEnum { | ||
NULL("NULL", ""), | ||
ACTIVE("ACTIVE", "ACTIVE"), | ||
DONE("DONE", "DONE"), | ||
DELETED("DELETED", "DELETED"); | ||
|
||
private final String desc; | ||
private final String value; | ||
|
||
StateEnum(String desc, String value) { | ||
this.desc = desc; | ||
this.value = value; | ||
} | ||
|
||
private static final Map<String, StateEnum> descriptions = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(StateEnum::getValue, Function.identity()))); | ||
|
||
public static StateEnum findOf(String findValue) { | ||
return Optional.ofNullable(descriptions.get(findValue)).orElse(NULL); | ||
} | ||
} |
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
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