Skip to content

Commit 19b5332

Browse files
authored
[DDING-000] FeedType 변환 로직 수정 (#221)
1 parent 7f7f6d8 commit 19b5332

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ddingdong.ddingdongBE.domain.feed.entity;
22

33
import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType;
4-
import java.util.Arrays;
54
import lombok.Getter;
65
import lombok.RequiredArgsConstructor;
76

@@ -12,11 +11,4 @@ public enum FeedType {
1211
VIDEO(DomainType.FEED_VIDEO);
1312

1413
private final DomainType domainType;
15-
16-
public static FeedType findByContentType(String contentType) {
17-
return Arrays.stream(values())
18-
.filter(feedType -> feedType.name().equalsIgnoreCase(contentType))
19-
.findFirst()
20-
.orElseThrow(() -> new IllegalArgumentException("Feed 내 해당 컨텐츠 종류(" + contentType + ")는 지원하지 않습니다."));
21-
}
2214
}

src/main/java/ddingdong/ddingdongBE/domain/feed/service/dto/command/CreateFeedCommand.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ public record CreateFeedCommand(
1616
) {
1717

1818
public Feed toEntity(Club club) {
19-
String mediaType = ContentType.fromMimeType(mimeType).getKeyMediaType();
20-
return Feed.builder()
21-
.activityContent(activityContent)
22-
.club(club)
23-
.feedType(FeedType.findByContentType(mediaType))
24-
.build();
19+
try {
20+
String mediaType = ContentType.getMediaTypeFromMimeType(mimeType);
21+
return Feed.builder()
22+
.activityContent(activityContent)
23+
.club(club)
24+
.feedType(FeedType.valueOf(mediaType))
25+
.build();
26+
} catch (Exception e) {
27+
throw new IllegalArgumentException("Feed 내 해당 컨텐츠 종류(" + mimeType + ")는 지원하지 않습니다.");
28+
}
2529
}
2630
}

src/main/java/ddingdong/ddingdongBE/file/service/ContentType.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ public static ContentType fromExtension(String extension) {
5151
}
5252

5353

54-
public static ContentType fromMimeType(String mimeType) {
55-
String lowerExtension = mimeType.substring(mimeType.lastIndexOf("/") + 1).toLowerCase();
54+
public static String getMediaTypeFromMimeType(String mimeType) {
5655
for (ContentType contentType : values()) {
57-
if (contentType.extensions.contains(lowerExtension)) {
58-
return contentType;
56+
if (contentType.getMimeType().equals(mimeType)) {
57+
return contentType.getKeyMediaType();
5958
}
6059
}
61-
return OCTET_STREAM;
60+
return OCTET_STREAM.getKeyMediaType();
6261
}
6362
}

0 commit comments

Comments
 (0)