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,7 +25,7 @@ public interface SpringDocTemplateController {
@SecurityRequirement(name = "쿠키 인증 토큰")
@Operation(summary = "템플릿 생성", description = """
새로운 템플릿을 생성합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록이 필요합니다. \n
템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록, 템플릿 공개 범위가 필요합니다. \n
* 템플릿 이름은 비어있거나 공백일 수 없다.

zangsu marked this conversation as resolved.
Show resolved Hide resolved
소스 코드 목록은 파일명, 소스 코드, 소스 코드 순서가 필요합니다. \n
Expand Down Expand Up @@ -64,6 +64,10 @@ public interface SpringDocTemplateController {
- 카테고리 ID
- 태그 ID들 \n

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

페이징 조건을 줄 수 있습니다. 페이지 번호는 1, 템플릿 개수는 20, 정렬 방식은 최신순이 기본 값입니다. \n
- 페이징 조건 \n
- 페이지 번호(pageNumber)
Expand All @@ -73,7 +77,7 @@ public interface SpringDocTemplateController {
- 정렬 방식 \n
- 최신순 (modifiedAt,asc)
- 오래된순 (modifiedAt,desc)
- 좋아요 순 (likesCount, desc) \n
- 좋아요순 (likesCount, desc) \n
""")
@ApiResponse(responseCode = "200", description = "템플릿 검색 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST,
Expand Down
11 changes: 11 additions & 0 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 @@ -54,11 +56,20 @@ public class Template extends BaseTimeEntity {
@Formula("(select count(*) from likes where likes.template_id = id)")
private Long likesCount;

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

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

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.visibility = visibility;
}

public void updateTemplate(String title, String description, Category category) {
Expand Down
8 changes: 8 additions & 0 deletions backend/src/main/java/codezap/template/domain/Visibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package codezap.template.domain;

public enum Visibility {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


PUBLIC,
PRIVATE,
;
}
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 @@ -42,7 +43,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 = "PUBLIC")
@NotNull(message = "템플릿 공개 여부가 null 입니다.", groups = NotNullGroup.class)
Visibility visibility
) implements ValidatedSourceCodesOrdinalRequest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import codezap.tag.dto.response.FindTagResponse;
import codezap.template.domain.SourceCode;
import codezap.template.domain.Template;
import codezap.template.domain.Visibility;
import io.swagger.v3.oas.annotations.media.Schema;

public record FindAllTemplateItemResponse(
Expand All @@ -28,6 +29,9 @@ public record FindAllTemplateItemResponse(
@Schema(description = "썸네일")
FindThumbnailResponse thumbnail,

@Schema(description = "공개 범위", example = "PUBLIC")
Visibility visibility,

@Schema(description = "좋아요 수", example = "134")
Long likesCount,
@Schema(description = "조회 멤버의 좋아요 여부", example = "true")
Expand All @@ -54,6 +58,7 @@ public static FindAllTemplateItemResponse of(
.map(FindTagResponse::from)
.toList(),
FindThumbnailResponse.from(thumbnailSourceCode),
template.getVisibility(),
template.getLikesCount(),
isLiked,
template.getCreatedAt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import codezap.tag.dto.response.FindTagResponse;
import codezap.template.domain.SourceCode;
import codezap.template.domain.Template;
import codezap.template.domain.Visibility;
import io.swagger.v3.oas.annotations.media.Schema;

public record FindTemplateResponse(
Expand All @@ -32,6 +33,9 @@ public record FindTemplateResponse(
@Schema(description = "태그 목록")
List<FindTagResponse> tags,

@Schema(description = "공개 범위", example = "PUBLIC")
Visibility visibility,

@Schema(description = "좋아요 수", example = "134")
Long likesCount,

Expand Down Expand Up @@ -62,6 +66,7 @@ public static FindTemplateResponse of(
tags.stream()
.map(FindTagResponse::from)
.toList(),
template.getVisibility(),
template.getLikesCount(),
isLiked,
template.getCreatedAt(),
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.visibility());
return templateRepository.save(template);
}

Expand Down
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 @@ -134,7 +135,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"),
Visibility.PUBLIC
);

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

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

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

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

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

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

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

mvc.perform(post("/templates")
Expand All @@ -308,7 +317,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"),
Visibility.PUBLIC
);

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

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

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

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

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

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

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

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

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

mvc.perform(post("/templates")
Expand Down Expand Up @@ -1204,7 +1223,8 @@ private static CreateTemplateRequest templateRequestWithTwoSourceCodes() {
),
1,
1L,
List.of("tag1", "tag2")
List.of("tag1", "tag2"),
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);
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);
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 @@ -66,7 +67,8 @@ public Template save(Template entity) {
entity.getDescription(),
entity.getCategory(),
entity.getSourceCodes(),
0L
0L,
Visibility.PUBLIC
);
templates.removeIf(template -> Objects.equals(template.getId(), entity.getId()));
templates.add(saved);
Expand Down
Loading