-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathCoverImage.java
More file actions
38 lines (32 loc) · 1.19 KB
/
CoverImage.java
File metadata and controls
38 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package nextstep.courses.domain;
import nextstep.courses.InvalidCoverImageException;
public class CoverImage {
private final int width;
private final int height;
private final int sizeInBytes;
private final ImageExtension extension;
public CoverImage(int width, int height, int sizeInBytes, ImageExtension extension) {
this.width = width;
this.height = height;
this.sizeInBytes = sizeInBytes;
this.extension = extension;
validate();
}
private void validate() {
if (sizeInBytes > 1_000_000) {
throw new InvalidCoverImageException("1MB를 초과하는 이미지입니다.");
}
if (width < 300) {
throw new InvalidCoverImageException("너비는 300px 이상이어야 합니다.");
}
if (height < 200) {
throw new InvalidCoverImageException("높이는 200px 이상이어야 합니다.");
}
if (width * 2 != height * 3) {
throw new InvalidCoverImageException("비율은 3:2여야 합니다.");
}
if (extension == null) {
throw new InvalidCoverImageException("지원하지 않는 확장자입니다.");
}
}
}