Skip to content

Commit

Permalink
Feat(#95) : 정보 좋아요 (#107)
Browse files Browse the repository at this point in the history
* Style : 코드 import 포맷팅

* Feat : 정보 좋아요 기능

좋아요 개수 조회
좋아요
좋아요 취소

* Style : 코드 포맷핑

* Feat : 정보 좋아요 삭제 시 요청 parameter수정
  • Loading branch information
Astin01 authored Aug 25, 2024
1 parent 10e0b44 commit 84429ae
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.RestController;
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.great_information.dto.response.GreatInformationResponse;
import solitour_backend.solitour.great_information.entity.GreatInformation;
import solitour_backend.solitour.great_information.service.GreatInformationService;

@RestController
Expand All @@ -27,17 +28,17 @@ public ResponseEntity<GreatInformationResponse> getInformationGreatCount(@Authen
}

@PostMapping()
public ResponseEntity<Void> createInformationGreat(@AuthenticationPrincipal Long userId,
public ResponseEntity<Long> createInformationGreat(@AuthenticationPrincipal Long userId,
@RequestParam Long infoId) {
service.createInformationGreat(userId, infoId);
GreatInformation greatInformation = service.createInformationGreat(userId, infoId);

return ResponseEntity.ok().build();
return ResponseEntity.ok(greatInformation.getId());
}

@DeleteMapping()
public ResponseEntity<Void> deleteInformationGreat(@AuthenticationPrincipal Long userId,
@RequestParam Long greatId) {
service.deleteInformationGreat(userId, greatId);
@RequestParam Long infoId) {
service.deleteInformationGreat(userId, infoId);

return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface GreatInformationRepository extends JpaRepository<GreatInformati
@Query("SELECT COUNT(g) FROM GreatInformation g WHERE g.information.id = :informationId")
int countByInformationId(Long informationId);

Optional<GreatInformation> findByIdAndUserId(Long greatInformationId, Long userId);
Optional<GreatInformation> findByInformationIdAndUserId(Long informationId, Long userId);

void deleteAllByInformationId(Long informationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public GreatInformation createInformationGreat(Long userId, Long infoId) {
Information information = informationRepository.findById(infoId)
.orElseThrow(() -> new IllegalArgumentException("해당 정보가 없습니다."));

return greatInformationRepository.findByIdAndUserId(infoId, userId)
return greatInformationRepository.findByInformationIdAndUserId(infoId, userId)
.orElseGet(
() -> greatInformationRepository.save(new GreatInformation(user, information)));
}

@Transactional
public void deleteInformationGreat(Long userId, Long bookMarkId) {
GreatInformation greatInformation = greatInformationRepository.findByIdAndUserId(bookMarkId,
public void deleteInformationGreat(Long userId, Long infoId) {
GreatInformation greatInformation = greatInformationRepository.findByInformationIdAndUserId(infoId,
userId)
.orElseThrow(() -> new EntityNotFoundException("해당 정보에는 좋아요를 하지 않았습니다"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

This comment has been minimized.

Copy link
@HyunJinNo

HyunJinNo Aug 25, 2024

Member

아래 코드에는 @NotNull이 존재합니다.

import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import lombok.Getter;
Expand Down

0 comments on commit 84429ae

Please sign in to comment.