Skip to content

Commit

Permalink
feat: #137 질문 좋아요/취소 API 구현 및 질문 조회 API에 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
kyxxgsoo committed Sep 3, 2024
1 parent 1e027e8 commit fe0e850
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.server.capple.domain.question.controller;

import com.server.capple.config.security.AuthMember;
import com.server.capple.domain.board.dto.BoardResponse;
import com.server.capple.domain.member.entity.Member;
import com.server.capple.domain.question.dto.response.QuestionResponse;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionSummary;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionInfos;
import com.server.capple.domain.question.service.QuestionService;
Expand All @@ -11,9 +13,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "질문 API", description = "질문 관련 API")
@RestController
Expand Down Expand Up @@ -41,6 +41,13 @@ private BaseResponse<QuestionInfos> getQuestions(@AuthMember Member member) {
return BaseResponse.onSuccess(questionService.getQuestions(member));
}

@Operation(summary = "질문 좋아요/취소 API", description = " 질문 좋아요/취소 API 입니다." +
"pathvariable 으로 questionId를 주세요.")
@PostMapping("/{questionId}/heart")
public BaseResponse<QuestionResponse.QuestionToggleHeart> toggleBoardHeart(@AuthMember Member member, @PathVariable(value = "questionId") Long questionId) {
return BaseResponse.onSuccess(questionService.toggleQuestionHeart(member, questionId));
}


// @Operation(summary = "최근 지난 질문 조회 API", description = "최근 지난 질문을 조회합니다.")
// @ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -51,4 +52,13 @@ public static class QuestionId {
public static class QuestionInfos {
private List<QuestionInfo> questionInfos;
}

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class QuestionToggleHeart {
private Long questionId;
private Boolean isLiked;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.server.capple.domain.question.service;
import com.server.capple.config.security.AuthMember;
import com.server.capple.domain.board.dto.BoardResponse;
import com.server.capple.domain.member.entity.Member;
import com.server.capple.domain.question.dto.response.QuestionResponse;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionSummary;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionInfos;
import com.server.capple.domain.question.entity.Question;
Expand All @@ -10,4 +12,6 @@ public interface QuestionService {
QuestionSummary getMainQuestion(Member member);

QuestionInfos getQuestions(Member member);

QuestionResponse.QuestionToggleHeart toggleQuestionHeart(Member member, Long questionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.server.capple.domain.answer.repository.AnswerRepository;
import com.server.capple.domain.answerComment.repository.AnswerCommentHeartRedisRepository;
import com.server.capple.domain.board.dto.BoardResponse;
import com.server.capple.domain.board.entity.Board;
import com.server.capple.domain.member.entity.Member;
import com.server.capple.domain.question.dao.QuestionInfoInterface;
import com.server.capple.domain.question.dto.response.QuestionResponse;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionInfos;
import com.server.capple.domain.question.dto.response.QuestionResponse.QuestionSummary;
import com.server.capple.domain.question.entity.Question;
Expand Down Expand Up @@ -55,4 +58,12 @@ public QuestionInfos getQuestions(Member member) {
questionHeartRepository.getQuestionHeartsCount(questionInfo.getQuestion().getId()))
).toList());
}

@Override
public QuestionResponse.QuestionToggleHeart toggleQuestionHeart(Member member, Long questionId) {
Question question = findQuestion(questionId);

Boolean isLiked = questionHeartRepository.toggleBoardHeart(member.getId(), question.getId());
return new QuestionResponse.QuestionToggleHeart(questionId, isLiked);
}
}

0 comments on commit fe0e850

Please sign in to comment.