-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from KUIT-Space/develop
24.08.14 배포
- Loading branch information
Showing
36 changed files
with
354 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/space/space_spring/config/filter/RequestCachingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package space.space_spring.config.filter; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
import org.springframework.web.util.ContentCachingRequestWrapper; | ||
|
||
import java.io.IOException; | ||
@Component | ||
public class RequestCachingFilter extends OncePerRequestFilter { | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
ContentCachingRequestWrapper wrappedRequest = new ContentCachingRequestWrapper(request); | ||
filterChain.doFilter(wrappedRequest, response); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/space/space_spring/controller/LikeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package space.space_spring.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; | ||
import space.space_spring.response.BaseResponse; | ||
import space.space_spring.service.LikeService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/space/{spaceId}/board/post/{postId}") | ||
@Slf4j | ||
public class LikeController { | ||
|
||
private final LikeService likeService; | ||
|
||
// 게시글 좋아요 | ||
@PostMapping("/like") | ||
public BaseResponse<String> likePost( | ||
@JwtLoginAuth Long userId, | ||
@PathVariable Long spaceId, | ||
@PathVariable Long postId | ||
) { | ||
// TODO 1: 유저가 스페이스에 속하는지 검증 | ||
likeService.validateUserInSpace(userId, spaceId); | ||
|
||
// TODO 2: 유저가 해당 게시글에 이미 좋아요를 눌렀는지 검증 | ||
likeService.validateAlreadyLiked(userId, postId); | ||
|
||
// TODO 3: 좋아요 로직 수행 | ||
likeService.likePost(userId, postId); | ||
|
||
return new BaseResponse<>("게시글에 좋아요를 눌렀습니다."); | ||
} | ||
|
||
|
||
// 게시글 좋아요 취소 | ||
@DeleteMapping("/like") | ||
public BaseResponse<String> unlikePost( | ||
@JwtLoginAuth Long userId, | ||
@PathVariable Long spaceId, | ||
@PathVariable Long postId | ||
) { | ||
// TODO 1: 유저가 스페이스에 속하는지 검증 | ||
likeService.validateUserInSpace(userId, spaceId); | ||
|
||
// TODO 2: 유저가 해당 게시글에 좋아요를 눌렀는지 검증 | ||
likeService.validateNotLikedYet(userId, postId); | ||
|
||
// TODO 3: 좋아요 취소 로직 수행 | ||
likeService.unlikePost(userId, postId); | ||
|
||
return new BaseResponse<>("게시글에 좋아요를 취소하였습니다."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import space.space_spring.entity.Post; | ||
import space.space_spring.entity.PostLike; | ||
import space.space_spring.entity.User; | ||
|
||
import java.util.Optional; | ||
|
||
public interface LikeDao extends JpaRepository<PostLike, Long> { | ||
Optional<PostLike> findByUserAndPost(User user, Post post); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.