diff --git a/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1CreateRequest.java b/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1CreateRequest.java index 3514241ae..b5dd0bea3 100644 --- a/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1CreateRequest.java +++ b/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1CreateRequest.java @@ -1,14 +1,15 @@ package com.festago.admin.dto.artist; import com.festago.artist.dto.command.ArtistCreateCommand; +import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; public record ArtistV1CreateRequest( @NotBlank String name, - @NotBlank + @Nullable String profileImageUrl, - @NotBlank + @Nullable String backgroundImageUrl ) { diff --git a/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1UpdateRequest.java b/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1UpdateRequest.java index f1b76cc40..42ea06955 100644 --- a/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1UpdateRequest.java +++ b/backend/src/main/java/com/festago/admin/dto/artist/ArtistV1UpdateRequest.java @@ -1,14 +1,15 @@ package com.festago.admin.dto.artist; import com.festago.artist.dto.command.ArtistUpdateCommand; +import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; public record ArtistV1UpdateRequest( @NotBlank String name, - @NotBlank + @Nullable String profileImageUrl, - @NotBlank + @Nullable String backgroundImageUrl ) { diff --git a/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaCreateV1Request.java b/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaCreateV1Request.java index 05074c44c..054f109a6 100644 --- a/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaCreateV1Request.java +++ b/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaCreateV1Request.java @@ -3,6 +3,7 @@ import com.festago.socialmedia.domain.OwnerType; import com.festago.socialmedia.domain.SocialMediaType; import com.festago.socialmedia.dto.command.SocialMediaCreateCommand; +import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Builder; @@ -17,7 +18,7 @@ public record SocialMediaCreateV1Request( SocialMediaType socialMediaType, @NotBlank String name, - @NotBlank + @Nullable String logoUrl, @NotBlank String url diff --git a/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaUpdateV1Request.java b/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaUpdateV1Request.java index 82fa5adca..b02f9f996 100644 --- a/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaUpdateV1Request.java +++ b/backend/src/main/java/com/festago/admin/dto/socialmedia/SocialMediaUpdateV1Request.java @@ -1,6 +1,7 @@ package com.festago.admin.dto.socialmedia; import com.festago.socialmedia.dto.command.SocialMediaUpdateCommand; +import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; import lombok.Builder; @@ -8,7 +9,7 @@ public record SocialMediaUpdateV1Request( @NotBlank String name, - @NotBlank + @Nullable String logoUrl, @NotBlank String url diff --git a/backend/src/main/java/com/festago/artist/domain/Artist.java b/backend/src/main/java/com/festago/artist/domain/Artist.java index 89081a8c6..f1baf8ee9 100644 --- a/backend/src/main/java/com/festago/artist/domain/Artist.java +++ b/backend/src/main/java/com/festago/artist/domain/Artist.java @@ -1,6 +1,8 @@ package com.festago.artist.domain; import com.festago.common.domain.BaseTimeEntity; +import com.festago.common.util.ImageUrlHelper; +import com.festago.common.util.Validator; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -13,8 +15,6 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Artist extends BaseTimeEntity { - private static final String DEFAULT_URL = "https://picsum.photos/536/354"; - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -27,14 +27,15 @@ public class Artist extends BaseTimeEntity { private String backgroundImageUrl; public Artist(Long id, String name, String profileImage, String backgroundImageUrl) { + validateName(name); this.id = id; this.name = name; - this.profileImage = profileImage; - this.backgroundImageUrl = backgroundImageUrl; + this.profileImage = ImageUrlHelper.getBlankStringIfBlank(profileImage); + this.backgroundImageUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl); } - public Artist(String name, String profileImage) { - this(null, name, profileImage, DEFAULT_URL); + private void validateName(String name) { + Validator.notBlank(name, "name"); } public Artist(String name, String profileImage, String backgroundImageUrl) { @@ -42,9 +43,10 @@ public Artist(String name, String profileImage, String backgroundImageUrl) { } public void update(String name, String profileImage, String backgroundImageUrl) { + validateName(name); this.name = name; - this.profileImage = profileImage; - this.backgroundImageUrl = backgroundImageUrl; + this.profileImage = ImageUrlHelper.getBlankStringIfBlank(profileImage); + this.backgroundImageUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl); } public Long getId() { diff --git a/backend/src/main/java/com/festago/common/util/ImageUrlHelper.java b/backend/src/main/java/com/festago/common/util/ImageUrlHelper.java new file mode 100644 index 000000000..f1d29d783 --- /dev/null +++ b/backend/src/main/java/com/festago/common/util/ImageUrlHelper.java @@ -0,0 +1,17 @@ +package com.festago.common.util; + +import org.springframework.util.StringUtils; + +public class ImageUrlHelper { + + private ImageUrlHelper() { + + } + + public static String getBlankStringIfBlank(String input) { + if (StringUtils.hasText(input)) { + return input; + } + return ""; + } +} diff --git a/backend/src/main/java/com/festago/festival/domain/Festival.java b/backend/src/main/java/com/festago/festival/domain/Festival.java index a40ebd075..e7995390e 100644 --- a/backend/src/main/java/com/festago/festival/domain/Festival.java +++ b/backend/src/main/java/com/festago/festival/domain/Festival.java @@ -1,6 +1,7 @@ package com.festago.festival.domain; import com.festago.common.domain.BaseTimeEntity; +import com.festago.common.util.ImageUrlHelper; import com.festago.common.util.Validator; import com.festago.school.domain.School; import jakarta.persistence.Embedded; @@ -21,7 +22,6 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Festival extends BaseTimeEntity { - private static final String DEFAULT_POSTER_IMAGE_URL = "https://picsum.photos/536/354"; private static final int MAX_NAME_LENGTH = 50; private static final int MAX_POSTER_IMAGE_URL_LENGTH = 255; @@ -44,10 +44,6 @@ public class Festival extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) private School school; - public Festival(String name, FestivalDuration festivalDuration, School school) { - this(null, name, festivalDuration, DEFAULT_POSTER_IMAGE_URL, school); - } - public Festival(String name, FestivalDuration festivalDuration, String posterImageUrl, School school) { this(null, name, festivalDuration, posterImageUrl, school); } @@ -60,7 +56,7 @@ public Festival(Long id, String name, FestivalDuration festivalDuration, String this.id = id; this.name = name; this.festivalDuration = festivalDuration; - this.posterImageUrl = posterImageUrl; + this.posterImageUrl = ImageUrlHelper.getBlankStringIfBlank(posterImageUrl); this.school = school; } @@ -71,9 +67,7 @@ private void validateName(String name) { } private void validatePosterImageUrl(String posterImageUrl) { - String fieldName = "posterImageUrl"; - Validator.notBlank(posterImageUrl, fieldName); - Validator.maxLength(posterImageUrl, MAX_POSTER_IMAGE_URL_LENGTH, fieldName); + Validator.maxLength(posterImageUrl, MAX_POSTER_IMAGE_URL_LENGTH, "posterImageUrl"); } private void validateFestivalDuration(FestivalDuration festivalDuration) { @@ -99,7 +93,7 @@ public void changeName(String name) { public void changePosterImageUrl(String posterImageUrl) { validatePosterImageUrl(posterImageUrl); - this.posterImageUrl = posterImageUrl; + this.posterImageUrl = ImageUrlHelper.getBlankStringIfBlank(posterImageUrl); } public void changeFestivalDuration(FestivalDuration festivalDuration) { diff --git a/backend/src/main/java/com/festago/member/domain/Member.java b/backend/src/main/java/com/festago/member/domain/Member.java index 7c7624859..1ed93648f 100644 --- a/backend/src/main/java/com/festago/member/domain/Member.java +++ b/backend/src/main/java/com/festago/member/domain/Member.java @@ -2,6 +2,7 @@ import com.festago.auth.domain.SocialType; import com.festago.common.domain.BaseTimeEntity; +import com.festago.common.util.ImageUrlHelper; import com.festago.common.util.Validator; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -37,7 +38,6 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends BaseTimeEntity { - private static final String DEFAULT_IMAGE_URL = "https://festa-go.site/images/default-profile.png"; private static final String DEFAULT_NICKNAME = "FestivalLover"; private static final int MAX_SOCIAL_ID_LENGTH = 255; private static final int MAX_NICKNAME_LENGTH = 30; @@ -77,7 +77,7 @@ public Member(Long id, String socialId, SocialType socialType, String nickname, this.socialId = socialId; this.socialType = socialType; this.nickname = (StringUtils.hasText(nickname)) ? nickname : DEFAULT_NICKNAME; - this.profileImage = (StringUtils.hasText(profileImage)) ? profileImage : DEFAULT_IMAGE_URL; + this.profileImage = ImageUrlHelper.getBlankStringIfBlank(profileImage); } private void validate(String socialId, SocialType socialType, String nickname, String profileImage) { diff --git a/backend/src/main/java/com/festago/mock/domain/MockFestivalsGenerator.java b/backend/src/main/java/com/festago/mock/domain/MockFestivalsGenerator.java index a5d01f4ef..227a726e6 100644 --- a/backend/src/main/java/com/festago/mock/domain/MockFestivalsGenerator.java +++ b/backend/src/main/java/com/festago/mock/domain/MockFestivalsGenerator.java @@ -26,6 +26,7 @@ public List generate(List schools) { return new Festival( school.getName() + " " + festivalDuration.getStartDate().format(DATE_TIME_FORMATTER) + " 축제", festivalDuration, + "", school ); }) diff --git a/backend/src/main/java/com/festago/mock/domain/MockSchoolsGenerator.java b/backend/src/main/java/com/festago/mock/domain/MockSchoolsGenerator.java index 9de356674..0d4c968ff 100644 --- a/backend/src/main/java/com/festago/mock/domain/MockSchoolsGenerator.java +++ b/backend/src/main/java/com/festago/mock/domain/MockSchoolsGenerator.java @@ -33,6 +33,8 @@ private School crateSchool(SchoolRegion schoolRegion, String schoolName, String return new School( schoolEmail, schoolName, + "", + "", schoolRegion ); } diff --git a/backend/src/main/java/com/festago/school/domain/School.java b/backend/src/main/java/com/festago/school/domain/School.java index 22ca6859c..be28f3f4d 100644 --- a/backend/src/main/java/com/festago/school/domain/School.java +++ b/backend/src/main/java/com/festago/school/domain/School.java @@ -1,6 +1,7 @@ package com.festago.school.domain; import com.festago.common.domain.BaseTimeEntity; +import com.festago.common.util.ImageUrlHelper; import com.festago.common.util.Validator; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -13,13 +14,11 @@ import jakarta.validation.constraints.Size; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.springframework.util.StringUtils; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) public class School extends BaseTimeEntity { - private static final String DEFAULT_URL = "https://picsum.photos/536/354"; private static final int MAX_DOMAIN_LENGTH = 50; private static final int MAX_NAME_LENGTH = 255; private static final int MAX_IMAGE_URL_LENGTH = 255; @@ -45,27 +44,20 @@ public class School extends BaseTimeEntity { @Enumerated(EnumType.STRING) private SchoolRegion region; + public School(String domain, String name, String logoUrl, String backgroundUrl, SchoolRegion region) { + this(null, domain, name, logoUrl, backgroundUrl, region); + } + public School(Long id, String domain, String name, String logoUrl, String backgroundImageUrl, SchoolRegion region) { validate(domain, name, region, logoUrl, backgroundImageUrl); this.id = id; this.domain = domain; this.name = name; - this.logoUrl = getDefaultUrlIfBlank(logoUrl); - this.backgroundUrl = getDefaultUrlIfBlank(backgroundImageUrl); + this.logoUrl = ImageUrlHelper.getBlankStringIfBlank(logoUrl); + this.backgroundUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl); this.region = region; } - private String getDefaultUrlIfBlank(String imageUrl) { - if (StringUtils.hasText(imageUrl)) { - return imageUrl; - } - return DEFAULT_URL; - } - - public School(String domain, String name, SchoolRegion region) { - this(null, domain, name, DEFAULT_URL, DEFAULT_URL, region); - } - private void validate(String domain, String name, SchoolRegion region, String logoUrl, String backgroundImageUrl) { validateDomain(domain); validateName(name); @@ -111,12 +103,12 @@ public void changeRegion(SchoolRegion region) { public void changeLogoUrl(String logoUrl) { validateImageUrl(logoUrl, "logoUrl"); - this.logoUrl = getDefaultUrlIfBlank(logoUrl); + this.logoUrl = ImageUrlHelper.getBlankStringIfBlank(logoUrl); } public void changeBackgroundImageUrl(String backgroundImageUrl) { validateImageUrl(backgroundImageUrl, "backgroundImageUrl"); - this.backgroundUrl = getDefaultUrlIfBlank(backgroundImageUrl); + this.backgroundUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl); } public Long getId() { diff --git a/backend/src/main/java/com/festago/socialmedia/domain/SocialMedia.java b/backend/src/main/java/com/festago/socialmedia/domain/SocialMedia.java index 4271cf2e7..5d3b39aca 100644 --- a/backend/src/main/java/com/festago/socialmedia/domain/SocialMedia.java +++ b/backend/src/main/java/com/festago/socialmedia/domain/SocialMedia.java @@ -1,6 +1,8 @@ package com.festago.socialmedia.domain; import com.festago.common.domain.BaseTimeEntity; +import com.festago.common.util.ImageUrlHelper; +import com.festago.common.util.Validator; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -19,7 +21,7 @@ name = "social_media", uniqueConstraints = { @UniqueConstraint( - columnNames= {"owner_id", "owner_type", "media_type"} + columnNames = {"owner_id", "owner_type", "media_type"} ) } ) @@ -47,14 +49,18 @@ public class SocialMedia extends BaseTimeEntity { private String url; public SocialMedia(Long id, Long ownerId, OwnerType ownerType, SocialMediaType mediaType, String name, - String logoUrl, - String url) { + String logoUrl, String url) { + Validator.notNull(ownerId, "ownerId"); + Validator.notNull(ownerType, "ownerType"); + Validator.notNull(mediaType, "mediaType"); + Validator.notBlank(name, "name"); + Validator.notBlank(url, "url"); this.id = id; this.ownerId = ownerId; this.ownerType = ownerType; this.mediaType = mediaType; this.name = name; - this.logoUrl = logoUrl; + this.logoUrl = ImageUrlHelper.getBlankStringIfBlank(logoUrl); this.url = url; } @@ -64,10 +70,12 @@ public SocialMedia(Long ownerId, OwnerType ownerType, SocialMediaType mediaType, } public void changeName(String name) { + Validator.notBlank(name, "name"); this.name = name; } public void changeUrl(String url) { + Validator.notBlank(url, "url"); this.url = url; } diff --git a/backend/src/test/java/com/festago/member/domain/MemberTest.java b/backend/src/test/java/com/festago/member/domain/MemberTest.java index 43342b7cd..a9b0fc582 100644 --- a/backend/src/test/java/com/festago/member/domain/MemberTest.java +++ b/backend/src/test/java/com/festago/member/domain/MemberTest.java @@ -91,7 +91,6 @@ class MemberTest { Member actual = new Member("12345", SocialType.FESTAGO, "nickname", profileImage); // when & then - assertThat(actual.getProfileImage()).isNotNull(); - assertThat(actual.getProfileImage()).isNotBlank(); + assertThat(actual.getProfileImage()).isEmpty(); } } diff --git a/backend/src/test/java/com/festago/school/domain/SchoolTest.java b/backend/src/test/java/com/festago/school/domain/SchoolTest.java index 1b3276adc..b398cc89f 100644 --- a/backend/src/test/java/com/festago/school/domain/SchoolTest.java +++ b/backend/src/test/java/com/festago/school/domain/SchoolTest.java @@ -27,7 +27,7 @@ class 생성 { String domain = "1".repeat(51); // when & then - assertThatThrownBy(() -> new School(domain, "테코대학교", SchoolRegion.서울)) + assertThatThrownBy(() -> new School(domain, "테코대학교", "", "", SchoolRegion.서울)) .isInstanceOf(ValidException.class); } @@ -36,7 +36,7 @@ class 생성 { @ValueSource(strings = {"", " ", "\t", "\n"}) void 도메인이_null_또는_공백이면_예외(String domain) { // when & then - assertThatThrownBy(() -> new School(domain, "테코대학교", SchoolRegion.서울)) + assertThatThrownBy(() -> new School(domain, "테코대학교", "", "", SchoolRegion.서울)) .isInstanceOf(ValidException.class); } @@ -47,7 +47,7 @@ class 생성 { String domain = "1".repeat(length); // when - School school = new School(domain, "테코대학교", SchoolRegion.서울); + School school = new School(domain, "테코대학교", "", "", SchoolRegion.서울); // then assertThat(school.getDomain()).isEqualTo(domain); @@ -59,7 +59,7 @@ class 생성 { String name = "1".repeat(256); // when & then - assertThatThrownBy(() -> new School("teco.ac.kr", name, SchoolRegion.서울)) + assertThatThrownBy(() -> new School("teco.ac.kr", name, "", "", SchoolRegion.서울)) .isInstanceOf(ValidException.class); } @@ -68,7 +68,7 @@ class 생성 { @ValueSource(strings = {"", " ", "\t", "\n"}) void 이름이_null_또는_공백이면_예외(String name) { // when & then - assertThatThrownBy(() -> new School("teco.ac.kr", name, SchoolRegion.서울)) + assertThatThrownBy(() -> new School("teco.ac.kr", name, "", "", SchoolRegion.서울)) .isInstanceOf(ValidException.class); } @@ -79,7 +79,7 @@ class 생성 { String name = "1".repeat(length); // when - School school = new School("teco.ac.kr", name, SchoolRegion.서울); + School school = new School("teco.ac.kr", name, "", "", SchoolRegion.서울); // then assertThat(school.getName()).isEqualTo(name); @@ -91,20 +91,20 @@ class 생성 { SchoolRegion region = null; // when & then - assertThatThrownBy(() -> new School("teco.ac.kr", "테코대학교", region)) + assertThatThrownBy(() -> new School("teco.ac.kr", "테코대학교", "", "", region)) .isInstanceOf(ValidException.class); } @ParameterizedTest @NullSource @ValueSource(strings = {"", " ", "\t", "\n"}) - void logoUrl이_null_또는_공백이어도_성공(String logoUrl) { + void logoUrl이_null_또는_공백이면_기본값이_할당된다(String logoUrl) { // when School school = new School(1L, "teco.ac.kr", "테코대학교", logoUrl, "https://image.com/backgroundImage.png", SchoolRegion.서울); // then - assertThat(school.getLogoUrl()).isNotBlank(); + assertThat(school.getLogoUrl()).isEmpty(); } @ParameterizedTest @@ -136,13 +136,13 @@ class 생성 { @ParameterizedTest @NullSource @ValueSource(strings = {"", " ", "\t", "\n"}) - void backgroundImageUrl이_null_또는_공백이어도_성공(String backgroundImageUrl) { + void backgroundImageUrl이_null_또는_공백이면_기본값이_할당된다(String backgroundImageUrl) { // when School school = new School(1L, "teco.ac.kr", "테코대학교", "https://image.com/logo.png", backgroundImageUrl, SchoolRegion.서울); // then - assertThat(school.getBackgroundUrl()).isNotBlank(); + assertThat(school.getBackgroundUrl()).isEmpty(); } @ParameterizedTest @@ -295,12 +295,12 @@ void setUp() { @ParameterizedTest @NullSource @ValueSource(strings = {"", " ", "\t", "\n"}) - void logoUrl이_null_또는_공백이어도_성공(String logoUrl) { + void logoUrl이_null_또는_공백이면_기본값이_할당된다(String logoUrl) { // when school.changeLogoUrl(logoUrl); // then - assertThat(school.getLogoUrl()).isNotBlank(); + assertThat(school.getLogoUrl()).isEmpty(); } @ParameterizedTest @@ -328,12 +328,12 @@ void setUp() { @ParameterizedTest @NullSource @ValueSource(strings = {"", " ", "\t", "\n"}) - void backgroundImageUrl이_null_또는_공백이어도_성공(String backgroundImageUrl) { + void backgroundImageUrl이_null_또는_공백이면_기본값이_할당된다(String backgroundImageUrl) { // when school.changeBackgroundImageUrl(backgroundImageUrl); // then - assertThat(school.getBackgroundUrl()).isNotBlank(); + assertThat(school.getBackgroundUrl()).isEmpty(); } @ParameterizedTest