Skip to content

Commit

Permalink
refactor(template): 공개 범위 필드 visibility로 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
kyum-q committed Oct 9, 2024
1 parent c2cf02e commit f83bcd3
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface SpringDocTemplateController {
@SecurityRequirement(name = "쿠키 인증 토큰")
@Operation(summary = "템플릿 생성", description = """
새로운 템플릿을 생성합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록, 템플릿 공개 여부가 필요합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록, 템플릿 공개 범위가 필요합니다. \n
* 템플릿 이름은 비어있거나 공백일 수 없다.
소스 코드 목록은 파일명, 소스 코드, 소스 코드 순서가 필요합니다. \n
Expand Down
11 changes: 7 additions & 4 deletions backend/src/main/java/codezap/template/domain/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -55,18 +57,19 @@ public class Template extends BaseTimeEntity {
private Long likesCount;

@Column(nullable = false)
private boolean isPublic;
@Enumerated(EnumType.STRING)
private Visibility visibility;

public Template(Member member, String title, String description, Category category) {
this(member, title, description, category, true);
this(member, title, description, category, Visibility.PUBLIC);
}

public Template(Member member, String title, String description, Category category, boolean isPublic) {
public Template(Member member, String title, String description, Category category, Visibility visibility) {
this.member = member;
this.title = title;
this.description = description;
this.category = category;
this.isPublic = isPublic;
this.visibility = visibility;
}

public void updateTemplate(String title, String description, Category category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import codezap.global.validation.ByteLength;
import codezap.global.validation.ValidationGroups.NotNullGroup;
import codezap.global.validation.ValidationGroups.SizeCheckGroup;
import codezap.template.domain.Visibility;
import codezap.template.dto.request.validation.ValidatedSourceCodesOrdinalRequest;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -43,10 +44,10 @@ public record CreateTemplateRequest(
@ByteLength(max = 30, message = "태그 명은 최대 30자까지 입력 가능합니다.", groups = SizeCheckGroup.class)
@Valid
List<String> tags,
@Schema(description = "템플릿 공개 여부", example = "true")

@Schema(description = "템플릿 공개 여부", example = "PUBLIC")
@NotNull(message = "템플릿 공개 여부가 null 입니다.", groups = NotNullGroup.class)
boolean isPublic
Visibility visibility
) implements ValidatedSourceCodesOrdinalRequest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Template create(Member member, CreateTemplateRequest createTemplateReques
createTemplateRequest.title(),
createTemplateRequest.description(),
category,
createTemplateRequest.isPublic());
createTemplateRequest.visibility());
return templateRepository.save(template);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template ADD COLUMN visibility VARCHAR(255) NOT NULL DEFAULT 'PUBLIC';
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import codezap.member.repository.FakeMemberRepository;
import codezap.member.repository.MemberRepository;
import codezap.tag.service.TagService;
import codezap.template.domain.Visibility;
import codezap.template.dto.request.CreateSourceCodeRequest;
import codezap.template.dto.request.CreateTemplateRequest;
import codezap.template.dto.request.UpdateSourceCodeRequest;
Expand Down Expand Up @@ -135,7 +136,7 @@ void createTemplateSuccess(String repeatTarget, int maxLength) throws Exception
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -157,7 +158,7 @@ void createTemplateFailWithBlankTitle(String title) throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -180,7 +181,7 @@ void createTemplateFailWithLongTitle() throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -202,7 +203,7 @@ void createTemplateFailWithNullDescription() throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -225,7 +226,7 @@ void createTemplateFailWithLongDescription(String repeatTarget, int exceededLeng
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -248,7 +249,7 @@ void createTemplateFailWithBlankFileName(String fileName) throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -271,7 +272,7 @@ void createTemplateFailWithLongFileName() throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -294,7 +295,7 @@ void createTemplateFailWithBlankContent(String sourceCode) throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -317,7 +318,7 @@ void createTemplateFailWithLongSourceCode(String repeatTarget, int exceededLengt
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -339,7 +340,7 @@ void createTemplateFailWithLongEmptySourceCode() throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -361,7 +362,7 @@ void createTemplateFailWithLongNullCategoryId() throws Exception {
1,
null,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -383,7 +384,7 @@ void createTemplateFailWithLongNullTags() throws Exception {
1,
1L,
null,
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -407,7 +408,7 @@ void createTemplateFailWithOverSizeTags() throws Exception {
1,
1L,
List.of(exceededTag),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -431,7 +432,7 @@ void createTemplateFailWithWrongSourceCodeOrdinal(int firstIndex, int secondInde
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -453,7 +454,7 @@ void createTemplateFailWithNotLogin() throws Exception {
1,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -474,7 +475,7 @@ void createTemplateFailWithNoMatchCategory() throws Exception {
1,
2L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -496,7 +497,7 @@ void createTemplateFailWithNotCategory() throws Exception {
1,
3L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand All @@ -518,7 +519,7 @@ void createTemplateFailWithNotSourceCode() throws Exception {
10,
1L,
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

mvc.perform(post("/templates")
Expand Down Expand Up @@ -1223,7 +1224,7 @@ private static CreateTemplateRequest templateRequestWithTwoSourceCodes() {
1,
1L,
List.of("tag1", "tag2"),
false
Visibility.PUBLIC
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private Template createTemplateById(Long id) {
Category category = CategoryFixture.getFirstCategory();
List<SourceCode> sourceCodes = List.of();
long likesCount = 1L;
return new Template(id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, true);
return new Template(
id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, Visibility.PUBLIC);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ private Template createTemplateById(Long id) {
Category category = CategoryFixture.getFirstCategory();
List<SourceCode> sourceCodes = List.of();
long likesCount = 1L;
return new Template(id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, true);
return new Template(
id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, Visibility.PUBLIC);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import codezap.global.exception.CodeZapException;
import codezap.template.domain.Template;
import codezap.template.domain.Visibility;

public class FakeTemplateRepository implements TemplateRepository {

Expand Down Expand Up @@ -67,7 +68,7 @@ public Template save(Template entity) {
entity.getCategory(),
entity.getSourceCodes(),
0L,
true
Visibility.PUBLIC
);
templates.removeIf(template -> Objects.equals(template.getId(), entity.getId()));
templates.add(saved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import codezap.member.domain.Member;
import codezap.member.repository.MemberRepository;
import codezap.template.domain.Template;
import codezap.template.domain.Visibility;
import codezap.template.dto.request.CreateSourceCodeRequest;
import codezap.template.dto.request.CreateTemplateRequest;
import codezap.template.dto.request.UpdateTemplateRequest;
Expand Down Expand Up @@ -74,7 +75,7 @@ void createTemplateSuccess() {
1,
category.getId(),
List.of("tag1", "tag2"),
true
Visibility.PUBLIC
);

var actual = sut.create(member, templateRequest, category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import codezap.template.domain.SourceCode;
import codezap.template.domain.Template;
import codezap.template.domain.Thumbnail;
import codezap.template.domain.Visibility;
import codezap.template.dto.request.CreateSourceCodeRequest;
import codezap.template.dto.request.CreateTemplateRequest;
import codezap.template.dto.request.UpdateSourceCodeRequest;
Expand Down Expand Up @@ -115,7 +116,7 @@ private static CreateTemplateRequest createTemplateRequest(Category category) {
thumbnailOrdinal,
category.getId(),
tags,
true);
Visibility.PUBLIC);
}
}

Expand Down
12 changes: 6 additions & 6 deletions backend/src/test/resources/search.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ INSERT INTO tag (id, created_at, modified_at, name)
VALUES (2, '2024-09-27 08:43:08.769440', '2024-09-27 08:43:08.769440', 'Tag 2');

-- Template 삽입
INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, is_public)
VALUES (1, 1, '2024-09-27 08:43:08.773369', 'Description 1', 1, '2024-09-27 08:43:08.773369', 'Template 1', true);
INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, visibility)
VALUES (1, 1, '2024-09-27 08:43:08.773369', 'Description 1', 1, '2024-09-27 08:43:08.773369', 'Template 1', 'PUBLIC');

INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, is_public)
VALUES (2, 2, '2024-09-27 08:43:08.787995', 'Description 1', 1, '2024-09-27 08:43:08.787995', 'Template 1', true);
INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, visibility)
VALUES (2, 2, '2024-09-27 08:43:08.787995', 'Description 1', 1, '2024-09-27 08:43:08.787995', 'Template 1', 'PUBLIC');

INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, is_public)
VALUES (3, 1, '2024-09-27 08:43:08.790778', 'Description 1', 2, '2024-09-27 08:43:08.790778', 'Template 1', true);
INSERT INTO template (id, category_id, created_at, description, member_id, modified_at, title, visibility)
VALUES (3, 1, '2024-09-27 08:43:08.790778', 'Description 1', 2, '2024-09-27 08:43:08.790778', 'Template 1', 'PUBLIC');

-- Source Code 삽입
INSERT INTO source_code (id, content, created_at, filename, modified_at, ordinal, template_id)
Expand Down

0 comments on commit f83bcd3

Please sign in to comment.