Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

템플릿 공개 여부에 따른 Swagger 파일 수정 #748

Merged
merged 11 commits into from
Oct 11, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public interface SpringDocTemplateController {
@SecurityRequirement(name = "쿠키 인증 토큰")
@Operation(summary = "템플릿 생성", description = """
새로운 템플릿을 생성합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록이 필요합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록, 템플릿 공개 여부가 필요합니다. \n
* 템플릿 이름은 비어있거나 공백일 수 없다.

zangsu marked this conversation as resolved.
Show resolved Hide resolved
소스 코드 목록은 파일명, 소스 코드, 소스 코드 순서가 필요합니다. \n
* 소스 코드 순서는 1부터 시작합니다.
* 소스 코드 순서는 오름차순으로 정렬하여 보내야 합니다.
Expand Down Expand Up @@ -62,17 +62,21 @@ public interface SpringDocTemplateController {
- 검색 키워드 (템플릿명, 템플릿 설명, 파일명, 소스 코드)
- 카테고리 ID
- 태그 ID들 \n


조건에 멤버 ID가 있을 경우
- 멤버 ID가 로그인된 멤버 정보와 동일하면 공개 템플릿, 비공개 템플릿 모두 반환
- 멤버 ID가 로그인된 멤버 정보와 동일하지 않으면 공개 템플릿만 반환
zangsu marked this conversation as resolved.
Show resolved Hide resolved

페이징 조건을 줄 수 있습니다. 페이지 번호는 1, 템플릿 개수는 20, 정렬 방식은 최신순이 기본 값입니다. \n
- 페이징 조건 \n
- 페이지 번호(pageNumber)
- 한 페이지에 템플릿 개수(pageSize)
- 페이지 정렬 방식(sort) \n

zangsu marked this conversation as resolved.
Show resolved Hide resolved
- 정렬 방식 \n
- 최신순 (modifiedAt,asc)
- 오래된순 (modifiedAt,desc)
- 좋아요 순 (likesCount, desc) \n
- 좋아요순 (likesCount, desc) \n
zangsu marked this conversation as resolved.
Show resolved Hide resolved
""")
@ApiResponse(responseCode = "200", description = "템플릿 검색 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST,
Expand Down Expand Up @@ -102,17 +106,21 @@ ResponseEntity<FindAllTemplatesResponse> findAllTemplates(
- 검색 키워드 (템플릿명, 템플릿 설명, 파일명, 소스 코드)
- 카테고리 ID
- 태그 ID들 \n


조건에 멤버 ID가 있을 경우
- 멤버 ID가 로그인된 멤버 정보와 동일하면 공개 템플릿, 비공개 템플릿 모두 반환
- 멤버 ID가 로그인된 멤버 정보와 동일하지 않으면 공개 템플릿만 반환

zangsu marked this conversation as resolved.
Show resolved Hide resolved
페이징 조건을 줄 수 있습니다. 페이지 번호는 1, 템플릿 개수는 20, 정렬 방식은 최신순이 기본 값입니다. \n
- 페이징 조건 \n
- 페이지 번호(pageNumber)
- 한 페이지에 템플릿 개수(pageSize)
- 페이지 정렬 방식(sort) \n

zangsu marked this conversation as resolved.
Show resolved Hide resolved
- 정렬 방식 \n
- 최신순 (modifiedAt,asc)
- 오래된순 (modifiedAt,desc)
- 좋아요 순 (likesCount, desc) \n
- 좋아요순 (likesCount, desc) \n
""")
@ApiResponse(responseCode = "200", description = "템플릿 검색 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST,
Expand Down
8 changes: 8 additions & 0 deletions backend/src/main/java/codezap/template/domain/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ public class Template extends BaseTimeEntity {
@Formula("(select count(*) from likes where likes.template_id = id)")
private Long likesCount;

@Column(nullable = false)
private boolean isPublic;
zeus6768 marked this conversation as resolved.
Show resolved Hide resolved

public Template(Member member, String title, String description, Category category) {
this(member, title, description, category, true);
zangsu marked this conversation as resolved.
Show resolved Hide resolved
}

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

public void updateTemplate(String title, String description, Category category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public record CreateTemplateRequest(
@NotNull(message = "태그 목록이 null 입니다.", groups = NotNullGroup.class)
@ByteLength(max = 30, message = "태그 명은 최대 30자까지 입력 가능합니다.", groups = SizeCheckGroup.class)
@Valid
List<String> tags
List<String> tags,

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template ADD COLUMN is_public BOOLEAN NOT NULL DEFAULT TRUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따봉

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ void createTemplateSuccess(String repeatTarget, int maxLength) throws Exception
List.of(new CreateSourceCodeRequest("a".repeat(MAX_LENGTH), repeatTarget.repeat(maxLength), 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -155,7 +156,8 @@ void createTemplateFailWithBlankTitle(String title) throws Exception {
List.of(new CreateSourceCodeRequest("a", "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -177,7 +179,8 @@ void createTemplateFailWithLongTitle() throws Exception {
List.of(new CreateSourceCodeRequest("a", "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -198,7 +201,8 @@ void createTemplateFailWithNullDescription() throws Exception {
List.of(new CreateSourceCodeRequest("title", "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -220,7 +224,8 @@ void createTemplateFailWithLongDescription(String repeatTarget, int exceededLeng
List.of(new CreateSourceCodeRequest("title", "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -242,7 +247,8 @@ void createTemplateFailWithBlankFileName(String fileName) throws Exception {
List.of(new CreateSourceCodeRequest(fileName, "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -264,7 +270,8 @@ void createTemplateFailWithLongFileName() throws Exception {
List.of(new CreateSourceCodeRequest(exceededTitle, "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -286,7 +293,8 @@ void createTemplateFailWithBlankContent(String sourceCode) throws Exception {
List.of(new CreateSourceCodeRequest("title", sourceCode, 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -308,7 +316,8 @@ void createTemplateFailWithLongSourceCode(String repeatTarget, int exceededLengt
List.of(new CreateSourceCodeRequest("title", repeatTarget.repeat(exceededLength), 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

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

mvc.perform(post("/templates")
Expand All @@ -350,7 +360,8 @@ void createTemplateFailWithLongNullCategoryId() throws Exception {
List.of(new CreateSourceCodeRequest("title", "sourceCode", 1)),
1,
null,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -371,7 +382,8 @@ void createTemplateFailWithLongNullTags() throws Exception {
List.of(new CreateSourceCodeRequest("title", "sourceCode", 1)),
1,
1L,
null
null,
true
);

mvc.perform(post("/templates")
Expand All @@ -394,7 +406,8 @@ void createTemplateFailWithOverSizeTags() throws Exception {
List.of(new CreateSourceCodeRequest("title", "sourceCode", 1)),
1,
1L,
List.of(exceededTag)
List.of(exceededTag),
true
);

mvc.perform(post("/templates")
Expand All @@ -417,7 +430,8 @@ void createTemplateFailWithWrongSourceCodeOrdinal(int firstIndex, int secondInde
new CreateSourceCodeRequest("title", "content", secondIndex)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -438,7 +452,8 @@ void createTemplateFailWithNotLogin() throws Exception {
List.of(new CreateSourceCodeRequest("filename", "content", 1)),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -458,7 +473,8 @@ void createTemplateFailWithNoMatchCategory() throws Exception {
List.of(new CreateSourceCodeRequest("filename", "content", 1)),
1,
2L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -479,7 +495,8 @@ void createTemplateFailWithNotCategory() throws Exception {
List.of(new CreateSourceCodeRequest("filename", "content", 1)),
1,
3L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand All @@ -500,7 +517,8 @@ void createTemplateFailWithNotSourceCode() throws Exception {
List.of(new CreateSourceCodeRequest("filename", "content", 1)),
10,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

mvc.perform(post("/templates")
Expand Down Expand Up @@ -1204,7 +1222,8 @@ private static CreateTemplateRequest templateRequestWithTwoSourceCodes() {
),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
false
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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);
return new Template(id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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);
return new Template(id, member, "Template 1", "Description 1", category, sourceCodes, likesCount, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public Template save(Template entity) {
entity.getDescription(),
entity.getCategory(),
entity.getSourceCodes(),
0L
0L,
true
);
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 @@ -73,7 +73,8 @@ void createTemplateSuccess() {
),
1,
category.getId(),
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
true
);

var actual = sut.create(member, templateRequest, category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private static CreateTemplateRequest createTemplateRequest(Category category) {
sourceCodes,
thumbnailOrdinal,
category.getId(),
tags);
tags,
true);
}
}

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)
VALUES (1, 1, '2024-09-27 08:43:08.773369', 'Description 1', 1, '2024-09-27 08:43:08.773369', 'Template 1');
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)
VALUES (2, 2, '2024-09-27 08:43:08.787995', 'Description 1', 1, '2024-09-27 08:43:08.787995', 'Template 1');
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)
VALUES (3, 1, '2024-09-27 08:43:08.790778', 'Description 1', 2, '2024-09-27 08:43:08.790778', 'Template 1');
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);

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