Skip to content

Commit

Permalink
Merge pull request #675 from woowacourse-teams/feat/668-be-like
Browse files Browse the repository at this point in the history
  • Loading branch information
jminkkk authored Sep 22, 2024
2 parents 8252785 + da3c4ce commit 75a7bf2
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 5 deletions.
24 changes: 24 additions & 0 deletions backend/src/main/java/codezap/like/controller/LikeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package codezap.like.controller;

import org.apache.commons.lang3.NotImplementedException;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import codezap.member.dto.MemberDto;

@Controller
public class LikeController implements SpringDocsLikeController {

@PostMapping("like/{templateId}")
public ResponseEntity<Void> like(MemberDto memberDto, @PathVariable long templateId) {
throw new NotImplementedException();
}

@DeleteMapping("like/{templateId}")
public ResponseEntity<Void> cancelLike(MemberDto memberDto, @PathVariable long templateId) {
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package codezap.like.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import codezap.global.swagger.error.ApiErrorResponse;
import codezap.global.swagger.error.ErrorCase;
import codezap.member.dto.MemberDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "좋아요 API", description = "좋아요 기능 관련 API")
public interface SpringDocsLikeController {

@SecurityRequirement(name = "쿠키 인증 토큰")
@Operation(summary = "좋아요", description = "템플릿을 좋아요 합니다.")
@ApiResponse(responseCode = "200", description = "좋아요 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST, instance = "/like/1", errorCases = {
@ErrorCase(description = "템플릿 Id 에 해당하는 템플릿이 존재하지 않는 경우", exampleMessage = "식별자 1에 해당하는 템플릿이 존재하지 않습니다.")
})
@ApiErrorResponse(status = HttpStatus.UNAUTHORIZED, instance = "/like/1", errorCases = {
@ErrorCase(description = "인증 정보에 해당하는 멤버가 없는 경우", exampleMessage = "인증 정보가 정확하지 않습니다.")
})
ResponseEntity<Void> like(MemberDto memberDto, long templateId);

@SecurityRequirement(name = "쿠키 인증 토큰")
@Operation(summary = "좋아요 취소", description = "템플릿 좋아요를 취소합니다.")
@ApiResponse(responseCode = "200", description = "좋아요 취소 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST, instance = "/dislike/1", errorCases = {
@ErrorCase(description = "템플릿 Id 에 해당하는 템플릿이 존재하지 않는 경우", exampleMessage = "식별자 1에 해당하는 템플릿이 존재하지 않습니다.")
})
@ApiErrorResponse(status = HttpStatus.UNAUTHORIZED, instance = "/dislike/1", errorCases = {
@ErrorCase(description = "인증 정보에 해당하는 멤버가 없는 경우", exampleMessage = "인증 정보가 정확하지 않습니다.")
})
ResponseEntity<Void> cancelLike(MemberDto memberDto, long templateId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public interface SpringDocTemplateController {
- 정렬 방식 \n
- 최신순 (modifiedAt,asc)
- 오래된순 (modifiedAt,desc) \n
- 오래된순 (modifiedAt,desc)
- 좋아요 수가 많은 순 (like, desc) \n
""")
@ApiResponse(responseCode = "200", description = "템플릿 검색 성공")
@ApiErrorResponse(status = HttpStatus.BAD_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ public record FindAllTemplateItemResponse(
List<FindTagResponse> tags,
@Schema(description = "썸네일")
FindThumbnailResponse thumbnail,
@Schema(description = "좋아요 수", example = "134")
Long likeCount,
@Schema(description = "조회 멤버의 좋아요 여부", example = "true")
Boolean isLiked,
@Schema(description = "템플릿 생성 시간", example = "2024-11-10 12:00:00", type = "string")
LocalDateTime createdAt,
@Schema(description = "템플릿 수정 시간", example = "2024-11-11 12:00:00", type = "string")
LocalDateTime modifiedAt
) {
public static FindAllTemplateItemResponse of(
Template template, List<Tag> templateTags, SourceCode thumbnailSourceCode
Template template, List<Tag> templateTags, SourceCode thumbnailSourceCode, Long likeCount, Boolean isLiked
) {
return new FindAllTemplateItemResponse(
template.getId(),
Expand All @@ -40,6 +44,8 @@ public static FindAllTemplateItemResponse of(
.map(tag -> new FindTagResponse(tag.getId(), tag.getName()))
.toList(),
FindThumbnailResponse.from(thumbnailSourceCode),
likeCount,
isLiked,
template.getCreatedAt(),
template.getModifiedAt()
);
Expand All @@ -53,6 +59,8 @@ public FindAllTemplateItemResponse updateMember(Member member) {
description,
tags,
thumbnail,
likeCount,
isLiked,
createdAt,
modifiedAt
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ public record FindTemplateResponse(
@Schema(description = "태그 목록")
List<FindTagResponse> tags,

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

@Schema(description = "조회 회원의 좋아요 여부", example = "true")
Boolean isLiked,

@Schema(description = "템플릿 생성 시간", example = "2024-11-10 12:00:00", type = "string")
LocalDateTime createdAt,

@Schema(description = "템플릿 수정 시간", example = "2024-11-11 12:00:00", type = "string")
LocalDateTime modifiedAt
) {
public static FindTemplateResponse of(Template template, List<SourceCode> sourceCodes, List<Tag> tags) {
public static FindTemplateResponse of(Template template, List<SourceCode> sourceCodes, List<Tag> tags, Long likeCount, Boolean isLiked) {
return new FindTemplateResponse(
template.getId(),
null,
Expand All @@ -48,6 +54,8 @@ public static FindTemplateResponse of(Template template, List<SourceCode> source
mapToFindAllSourceCodeByTemplateResponse(sourceCodes),
FindCategoryResponse.from(template.getCategory()),
mapToFindTagByTemplateResponse(tags),
likeCount,
isLiked,
template.getCreatedAt(),
template.getModifiedAt()
);
Expand All @@ -62,6 +70,8 @@ public FindTemplateResponse updateMember(Member member) {
sourceCodes,
category,
tags,
likeCount,
isLiked,
createdAt,
modifiedAt
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public FindTemplateResponse getById(Long id) {
List<Tag> tags = templateTagService.getByTemplate(template);

List<SourceCode> sourceCodes = sourceCodeService.findSourceCodesByTemplate(template);
return FindTemplateResponse.of(template, sourceCodes, tags);
//todo 좋아요 값 삽입 필요
return FindTemplateResponse.of(template, sourceCodes, tags, 0L, false);
}

public FindAllTagsResponse getAllTagsByMemberId(Long memberId) {
Expand All @@ -71,7 +72,10 @@ private FindAllTemplatesResponse makeTemplatesResponse(Page<Template> page) {
.map(template -> FindAllTemplateItemResponse.of(
template,
templateTagService.getByTemplate(template),
thumbnailService.getByTemplate(template).getSourceCode())
thumbnailService.getByTemplate(template).getSourceCode(),
//todo 값 삽입 필요
0L,
false)
)
.toList();
return new FindAllTemplatesResponse(page.getTotalPages(), page.getTotalElements(), findTemplateByAllResponse);
Expand Down

0 comments on commit 75a7bf2

Please sign in to comment.