Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.example.interviewPrep.quiz.answer.domain;

import com.example.interviewPrep.quiz.domain.BaseTimeEntity;
import com.example.interviewPrep.quiz.heart.exception.HeartExistException;
import com.example.interviewPrep.quiz.exception.advice.CommonException;
import com.example.interviewPrep.quiz.exception.advice.ErrorCode;
import com.example.interviewPrep.quiz.interview.domain.Interview;
import com.example.interviewPrep.quiz.member.domain.Member;
import com.example.interviewPrep.quiz.question.domain.Question;
Expand Down Expand Up @@ -76,7 +77,7 @@ public synchronized int increase() {

public synchronized int decrease() {
if (this.heartCnt <= 0) {
throw new HeartExistException("좋아요 수가 0보다 작아 좋아요 수를 감소시킬수 없습니다.");
throw new CommonException(ErrorCode.NOT_EXIST_HEART_HISTORY);
}
return --this.heartCnt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package com.example.interviewPrep.quiz.heart.controller;

import com.example.interviewPrep.quiz.heart.dto.HeartRequestDTO;
import com.example.interviewPrep.quiz.heart.dto.request.HeartRequest;
import com.example.interviewPrep.quiz.heart.service.HeartService;
import com.example.interviewPrep.quiz.response.ResultResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

import static com.example.interviewPrep.quiz.utils.ResponseEntityConstants.RESPONSE_CREATED;
import static com.example.interviewPrep.quiz.utils.ResponseEntityConstants.RESPONSE_OK;
import static com.example.interviewPrep.quiz.utils.ResponseEntityConstants.RESPONSE_SERVER_ERROR;

@RestController
@RequestMapping("/heart")
@RequiredArgsConstructor
@RequestMapping("/api/v1/hearts")
@CrossOrigin(origins = "*")
@Log4j2
public class HeartController {
private final HeartService heartService;

public HeartController(HeartService heartService) {
this.heartService = heartService;
}

@PostMapping()
public ResultResponse<?> create(@RequestBody @NotNull HeartRequestDTO heartDTO) throws InterruptedException {
return ResultResponse.success(heartService.createHeart(heartDTO));
public ResponseEntity<Void> create(@RequestBody HeartRequest heartRequest) throws InterruptedException {
heartService.createHeart(heartRequest);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@DeleteMapping()
public ResultResponse<?> delete(@RequestBody @NotNull HeartRequestDTO heartDTO) throws InterruptedException {
return ResultResponse.success(heartService.deleteHeart(heartDTO));
public ResponseEntity<Void> delete(@RequestBody @NotNull HeartRequest heartRequest) throws InterruptedException {
heartService.deleteHeart(heartRequest);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@
import com.example.interviewPrep.quiz.answer.domain.Answer;
import com.example.interviewPrep.quiz.domain.BaseTimeEntity;
import com.example.interviewPrep.quiz.member.domain.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Objects;

import static javax.persistence.FetchType.LAZY;

@Entity
@Getter
@Builder
@RequiredArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
public class Heart extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "HEART_ID")
private Long id;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "ANSWER_ID")
Answer answer;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "MEMBER_ID")
Member member;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Builder
public Heart(Answer answer, Member member) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Objects.requireNonNull(answer, "answer가 null입니다.");
Objects.requireNonNull(member, "member가 null입니다.");

this.answer = answer;
this.member = member;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.interviewPrep.quiz.heart.dto.request;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Getter
@NoArgsConstructor
public class HeartRequest {

private Long answerId;

@Builder
public HeartRequest(Long answerId) {
Objects.requireNonNull(answerId, "answerId가 null입니다.");
this.answerId = answerId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.interviewPrep.quiz.heart.repository;

import com.example.interviewPrep.quiz.answer.domain.Answer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AnswerLockRepository extends JpaRepository<Answer, Long> {

@Query(value = "select get_lock(:key, 3000)", nativeQuery = true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

timeout도 파라미터로 받는게 어떨까요 ~?

void getLock(@Param("key") String key);

@Query(value = "select release_lock(:key)", nativeQuery = true)
void releaseLock(@Param("key") String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface HeartRepository extends JpaRepository<Heart, Long> {

Optional<Heart> findByAnswerIdAndMemberId(Long answerId, Long memberId);

List<Heart> findByAnswerId(Long id);

int countHeartByAnswerId(long id);

@Query("select h.answer.id from Heart h where h.answer.id in ?1 and h.member.id = ?2")
Expand Down

This file was deleted.

Loading