File tree 3 files changed +14
-19
lines changed
src/main/java/ddingdong/ddingdongBE 3 files changed +14
-19
lines changed Original file line number Diff line number Diff line change 1
1
package ddingdong .ddingdongBE .domain .feed .entity ;
2
2
3
3
import ddingdong .ddingdongBE .domain .filemetadata .entity .DomainType ;
4
- import java .util .Arrays ;
5
4
import lombok .Getter ;
6
5
import lombok .RequiredArgsConstructor ;
7
6
@@ -12,11 +11,4 @@ public enum FeedType {
12
11
VIDEO (DomainType .FEED_VIDEO );
13
12
14
13
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
- }
22
14
}
Original file line number Diff line number Diff line change @@ -16,11 +16,15 @@ public record CreateFeedCommand(
16
16
) {
17
17
18
18
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
+ }
25
29
}
26
30
}
Original file line number Diff line number Diff line change @@ -51,13 +51,12 @@ public static ContentType fromExtension(String extension) {
51
51
}
52
52
53
53
54
- public static ContentType fromMimeType (String mimeType ) {
55
- String lowerExtension = mimeType .substring (mimeType .lastIndexOf ("/" ) + 1 ).toLowerCase ();
54
+ public static String getMediaTypeFromMimeType (String mimeType ) {
56
55
for (ContentType contentType : values ()) {
57
- if (contentType .extensions . contains ( lowerExtension )) {
58
- return contentType ;
56
+ if (contentType .getMimeType (). equals ( mimeType )) {
57
+ return contentType . getKeyMediaType () ;
59
58
}
60
59
}
61
- return OCTET_STREAM ;
60
+ return OCTET_STREAM . getKeyMediaType () ;
62
61
}
63
62
}
You can’t perform that action at this time.
0 commit comments