-
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.
[Refactor] 사진 도메인을 리팩토링하고 테스트를 작성한다 (#89)
* refactor: Image를 도메인 패키지로 변경한다 * refactor: Images의 upload 메서드가 Image 도메인 객체를 반환하도록 리팩토링한다 * refactor: ImageIdentifierGenerator를 인터페이스로 추상화하여 분리한다 * refactor: Image의 imageIdentifier 네이밍을 identifier로 변경한다 * feature: Image에 검증 로직을 추가한다 * fix: ImageIdentifier 수정으로 인한 버그를 수정한다 * test: Image 테스트를 작성한다
- Loading branch information
Showing
42 changed files
with
216 additions
and
140 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
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
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
2 changes: 1 addition & 1 deletion
2
...byquest/image/vo/BaseImageProperties.java → ...est/image/domain/BaseImageProperties.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
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,45 @@ | ||
package daybyquest.image.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import java.util.Objects; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class Image { | ||
|
||
private static final int MAX_IDENTIFIER_LENGTH = 255; | ||
|
||
@Column(nullable = false) | ||
private String identifier; | ||
|
||
public Image(String identifier) { | ||
this.identifier = identifier; | ||
validateIdentifier(); | ||
} | ||
|
||
private void validateIdentifier() { | ||
if (identifier == null || identifier.isEmpty() || identifier.length() > MAX_IDENTIFIER_LENGTH) { | ||
throw new InvalidDomainException(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof Image image)) { | ||
return false; | ||
} | ||
return this.identifier.equals(image.identifier); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(identifier); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/daybyquest/image/domain/ImageIdentifierGenerator.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,6 @@ | ||
package daybyquest.image.domain; | ||
|
||
public interface ImageIdentifierGenerator { | ||
|
||
String generate(final String category, final String originalName); | ||
} |
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,10 @@ | ||
package daybyquest.image.domain; | ||
|
||
import java.io.InputStream; | ||
|
||
public interface Images { | ||
|
||
Image upload(final String identifier, final InputStream imageStream); | ||
|
||
void remove(final String identifier); | ||
} |
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/daybyquest/image/infra/UUIDImageIdentifierGenerator.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 daybyquest.image.infra; | ||
|
||
import daybyquest.image.domain.ImageIdentifierGenerator; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UUIDImageIdentifierGenerator implements ImageIdentifierGenerator { | ||
|
||
private static final String CATEGORY_DELIMITER = "/"; | ||
|
||
private static final String UUID_DELIMITER = "-"; | ||
|
||
@Override | ||
public String generate(final String category, final String originalName) { | ||
final String uuid = UUID.randomUUID().toString(); | ||
return category + CATEGORY_DELIMITER + uuid + UUID_DELIMITER + originalName; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/daybyquest/image/vo/ImageIdentifierGenerator.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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.