Skip to content

Commit

Permalink
Merge pull request #65 from DongnaeFriend/feature/#57
Browse files Browse the repository at this point in the history
Feature/#57
  • Loading branch information
Suanna01 authored Aug 4, 2023
2 parents 7cebe44 + 59d33a4 commit 01e03f2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public interface SharingSympathyRepository extends JpaRepository<SharingSympathy
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);
@Query(value = "SELECT sharing_sympathy.* FROM sharing_sympathy WHERE sharing_sympathy.sharing_board_id = :sharing_board_id", nativeQuery = true)
SharingSympathy findBySharingBoardId(@Param("sharing_board_id") SharingBoard 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
Expand Up @@ -19,15 +19,25 @@ public String newSympathy(Long accountBookId){
// 게시판 가져오기
SharingBoard sharingBoard = sharingSympathyRepository.findBySharingBoardId(accountBookId);

// 공감 데이터 저장하기
SharingSympathy sharingSympathy = SharingSympathy.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();
// 공감 유무 확인하기
SharingSympathy sharingSympathyExist = sharingSympathyRepository.findBySharingBoardId(sharingBoard);

sharingSympathyRepository.save(sharingSympathy);
if (sharingSympathyExist == null) {
// 공감 데이터 저장하기
SharingSympathy sharingSympathy = SharingSympathy.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();

return "[가계부 공유] 공감 성공";
sharingSympathyRepository.save(sharingSympathy);

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

// 공감 데이터 삭제하기
sharingSympathyRepository.delete(sharingSympathyExist);

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ public ResponseEntity<?> deleteBoard(@PathVariable("townInformationId") int boar
dongnaeBoardService.deleteBoard(board_id);
return ResponseEntity.ok("요청에 성공했습니다.");
}

// [동네정보] 게시글 공감
@PostMapping("/likes/{townInformationId}")
public ResponseEntity<?> postLike(@PathVariable("townInformationId") int board_id) throws AuthenticationException {
dongnaeBoardService.postLike(board_id);
return ResponseEntity.ok("요청에 성공했습니다.");
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.umc.DongnaeFriend.domain.dongnae.respository;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard;
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeSympathy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.web.PageableDefault;

import java.util.List;
Expand All @@ -12,4 +17,7 @@ public interface DongnaeSympathyRepository extends JpaRepository<DongnaeSympathy
int countAllByUserId(Long userId);

List<DongnaeSympathy> findByUser_Id(long user_id);
@Query(value = "SELECT dongnae_sympathy.* FROM dongnae_sympathy WHERE dongnae_sympathy.dongnae_board_id = :dongnae_board_id", nativeQuery = true)
DongnaeSympathy findByDongnaeBoardId(@Param("dongnae_board_id") DongnaeBoard dongnae_board_id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface DongnaeBoardService {
void updateBoard(long board_id, DongnaeBoardDto.Request request) throws AuthenticationException;

void deleteBoard(long board_id) throws AuthenticationException;

String postLike(long board_id) throws AuthenticationException;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.umc.DongnaeFriend.domain.dongnae.service;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.dongnae.dto.DongnaeBoardDto;
import com.umc.DongnaeFriend.domain.dongnae.dto.UserLocationDto;
import com.umc.DongnaeFriend.domain.dongnae.entity.Dongnae;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeImg;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeSympathy;
import com.umc.DongnaeFriend.domain.dongnae.respository.*;
import com.umc.DongnaeFriend.domain.type.DongnaeBoardCategory;
import com.umc.DongnaeFriend.domain.user.entity.User;
Expand All @@ -14,11 +16,14 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.naming.AuthenticationException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -188,6 +193,33 @@ public void deleteBoard(long board_id) {

}

@Override
public String postLike(long board_id) {
User user = getCurUser();

Optional<DongnaeBoard> board = dongnaeBoardRepository.findById(board_id);

// 공감 유무 확인하기
DongnaeSympathy dongnaeSympathyExist = dongnaeSympathyRepository.findByDongnaeBoardId(board.get());

if (dongnaeSympathyExist == null) {
// 공감 데이터 저장하기
DongnaeSympathy dongnaeSympathy = DongnaeSympathy.builder()
.dongnaeBoard(board.get())
.user(user)
.build();

dongnaeSympathyRepository.save(dongnaeSympathy);

return "[동네정보] 공감 성공";
}

// 공감 데이터 삭제하기
dongnaeSympathyRepository.delete(dongnaeSympathyExist);

return "[동네정보] 공감 삭제 성공";
}


//ListResponse 변환
private List<DongnaeBoardDto.ListResponse> getListResponses(List<DongnaeBoard> dongnaeBoardList) {
Expand Down Expand Up @@ -222,6 +254,7 @@ private User getCurUser() {
new CustomException(ErrorCode.UNAUTHORIZED_MEMBER)
);
}

}


Expand Down

0 comments on commit 01e03f2

Please sign in to comment.