Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ :: (#114) κ²Œμ‹œκΈ€ μ’‹μ•„μš” api #115

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -49,4 +49,8 @@ public PublicFeed(String title, String content, Integer likeCount, Feed feed) {
this.likeCount = likeCount;
this.feed = feed;
}

public void like() {
glay415 marked this conversation as resolved.
Show resolved Hide resolved
likeCount++;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.moizaspringserver.domain.feed.presenstation;

import com.example.moizaspringserver.domain.feed.service.AddLikeService;
import com.example.moizaspringserver.domain.feed.service.DeleteFeedService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -11,11 +12,18 @@
public class FeedController {

private final DeleteFeedService deleteFeedService;
private final AddLikeService addLikeService;

@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/{feed-id}")
public void deleteFeed(@PathVariable("feed-id") Integer feedId) {
deleteFeedService.execute(feedId);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/{feed-id}/like")
public void like(@PathVariable("feed-id") Integer feedId) {
addLikeService.execute(feedId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.moizaspringserver.domain.feed.service;

import com.example.moizaspringserver.domain.feed.entity.PublicFeed;
import com.example.moizaspringserver.domain.feed.exception.FeedNotFoundException;
import com.example.moizaspringserver.domain.feed.respository.PublicFeedRepository;
import com.example.moizaspringserver.domain.like.entity.FeedLike;
import com.example.moizaspringserver.domain.like.entity.FeedLikeId;
import com.example.moizaspringserver.domain.like.repository.FeedLikeRepository;
import com.example.moizaspringserver.domain.user.facade.UserFacade;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class AddLikeService {

private final PublicFeedRepository publicFeedRepository;
private final UserFacade userFacade;
private final FeedLikeRepository feedLikeRepository;

@Transactional
public void execute(Integer feedId) {

PublicFeed feed = publicFeedRepository.findById(feedId)
.orElseThrow(() -> FeedNotFoundException.EXCEPTION);

feed.like();
Copy link
Member

Choose a reason for hiding this comment

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

μˆœμ„œλ₯Ό FeedLike 객체λ₯Ό μƒμ„±ν•œ 후에 ν˜ΈμΆœν•˜λŠ” 게 더 쒋을 것 κ°™μ•„μš”

Copy link
Member Author

Choose a reason for hiding this comment

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

γ…‡γ…‹


FeedLike feedLike = FeedLike.builder()
.id(FeedLikeId.builder()
.user(
userFacade.queryCurrentUser()
Copy link
Member

Choose a reason for hiding this comment

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

currentUserλŠ” λ”°λ‘œ λ³€μˆ˜λ‘œ λΉΌλŠ” 게 μ–΄λ•Œμš”

Copy link
Member Author

Choose a reason for hiding this comment

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

μ—¬μ„œλ§Œ μ“°λŠ”λ° ꡳ이?

Copy link
Member

Choose a reason for hiding this comment

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

μ—μž‰

.getId()
)
.feed(feed.getFeedId())
.build())
.build();

feedLikeRepository.save(feedLike);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public class FeedLike extends BaseTimeEntity {
private Feed feed;

@Builder
public FeedLike(FeedLikeId id, User user,
Feed feed) {
public FeedLike(FeedLikeId id) {
this.id = id;
this.user = user;
this.feed = feed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected void configure(HttpSecurity http) throws Exception {

// feeds
.antMatchers(HttpMethod.DELETE, "/feeds/{feed-id}").authenticated()
.antMatchers(HttpMethod.POST, "/feeds/{feed-id}/like").hasAnyAuthority(UserType.ROLE_STUDENT.name(), UserType.ROLE_GRADUATE
.name())

// notice
.antMatchers(HttpMethod.GET, "/notices/{notice-id}").authenticated()
Expand Down