Skip to content

Commit

Permalink
Merge pull request #62 from DongnaeFriend/feature/#57
Browse files Browse the repository at this point in the history
Feature/#57
  • Loading branch information
Suanna01 authored Jul 31, 2023
2 parents ed5e0a6 + e2ce8d5 commit d5283ad
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/account-books/sharing/likes")
@RequestMapping("/account-books/sharing/comments/likes")
public class SharingCommentLikeController {
private final SharingCommentLikeService sharingCommentLikeService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.umc.DongnaeFriend.domain.account.sharing.controller;


import com.umc.DongnaeFriend.domain.account.sharing.service.SharingSympathyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/account-books/sharing/likes")
public class SharingSympathyController {
private final SharingSympathyService sharingSympathyService;

// 게시글 공감하기
@PostMapping("/{accountBookId}")
public String postSympathy(@PathVariable("accountBookId") Long accountBookId) {
sharingSympathyService.newSympathy(accountBookId);
return "";
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.umc.DongnaeFriend.domain.account.sharing.repository;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard;
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface SharingSympathyRepository extends JpaRepository<SharingSympathy, Long> {
@Query("SELECT u FROM User u WHERE u.id = :user_id")
User findByUserId(@Param("user_id") Long user_id);
@Query("SELECT sb FROM SharingBoard sb WHERE sb.id = :sharing_board_id")
SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id);

int countAllBySharingBoardId(Long sharing_board_id);
int countAllByUserId(Long userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.umc.DongnaeFriend.domain.account.sharing.service;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard;
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingSympathyRepository;
import com.umc.DongnaeFriend.domain.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class SharingSympathyService {
private final SharingSympathyRepository sharingSympathyRepository;

public String newSympathy(Long accountBookId){
// !임시! 유저 가져오기
User user = sharingSympathyRepository.findByUserId(1L);

// 게시판 가져오기
SharingBoard sharingBoard = sharingSympathyRepository.findBySharingBoardId(accountBookId);

// 공감 데이터 저장하기
SharingSympathy sharingSympathy = SharingSympathy.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();

sharingSympathyRepository.save(sharingSympathy);

return "[가계부 공유] 공감 성공";
}

}

0 comments on commit d5283ad

Please sign in to comment.