-
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 #169 from THEGOODs-repo/feature/168
โจ feat: ํ๋ก์ฐ ๊ธฐ๋ฅ api ์ถ๊ฐ(#168)
- Loading branch information
Showing
14 changed files
with
169 additions
and
32 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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/umc/TheGoods/apiPayload/exception/handler/PostHandler.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,9 @@ | ||
package com.umc.TheGoods.apiPayload.exception.handler; | ||
|
||
import com.umc.TheGoods.apiPayload.code.status.ErrorStatus; | ||
import com.umc.TheGoods.apiPayload.exception.GeneralException; | ||
|
||
public class PostHandler extends GeneralException { | ||
|
||
public PostHandler(ErrorStatus errorCode){ super(errorCode);} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/umc/TheGoods/converter/post/PostConverter.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,14 @@ | ||
package com.umc.TheGoods.converter.post; | ||
|
||
import com.umc.TheGoods.domain.member.Follow; | ||
import com.umc.TheGoods.domain.member.Member; | ||
|
||
public class PostConverter { | ||
public static Follow toFollow(Member follower, Member following){ | ||
|
||
return Follow.builder() | ||
.follower(follower) | ||
.following(following) | ||
.build(); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/umc/TheGoods/repository/post/FollowRepository.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,11 @@ | ||
package com.umc.TheGoods.repository.post; | ||
|
||
import com.umc.TheGoods.domain.member.Follow; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FollowRepository extends JpaRepository<Follow, Long> { | ||
|
||
Optional<Follow> findByFollowingIdAndFollowerId(Long followingId, Long followerId); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/umc/TheGoods/service/PostService/PostCommandService.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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package com.umc.TheGoods.service.PostService; | ||
|
||
import com.umc.TheGoods.domain.member.Member; | ||
|
||
public interface PostCommandService { | ||
|
||
void follow(Long followingId, Member follower); | ||
|
||
void deleteFollow(Long followingId, Long followerId); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/umc/TheGoods/service/PostService/PostCommandServiceImpl.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 |
---|---|---|
@@ -1,13 +1,50 @@ | ||
package com.umc.TheGoods.service.PostService; | ||
|
||
import com.umc.TheGoods.apiPayload.code.status.ErrorStatus; | ||
import com.umc.TheGoods.apiPayload.exception.handler.MemberHandler; | ||
import com.umc.TheGoods.apiPayload.exception.handler.PostHandler; | ||
import com.umc.TheGoods.converter.post.PostConverter; | ||
import com.umc.TheGoods.domain.member.Follow; | ||
import com.umc.TheGoods.domain.member.Member; | ||
import com.umc.TheGoods.repository.member.MemberRepository; | ||
import com.umc.TheGoods.repository.post.FollowRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class PostCommandServiceImpl implements PostCommandService { | ||
|
||
private final FollowRepository followRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Override | ||
public void follow(Long followingId, Member follower) { | ||
|
||
if(followingId.equals(follower.getId())){ | ||
throw new PostHandler(ErrorStatus.POST_SELF_FOLLOW); | ||
} | ||
Optional<Follow> check = followRepository.findByFollowingIdAndFollowerId(followingId,follower.getId()); | ||
if(!check.isEmpty()){ | ||
throw new PostHandler(ErrorStatus.POST_ALREADY_FOLLOW); | ||
} | ||
|
||
Member following = memberRepository.findById(followingId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
Follow follow = PostConverter.toFollow(follower,following); | ||
followRepository.save(follow); | ||
} | ||
|
||
@Override | ||
public void deleteFollow(Long followingId, Long followerId) { | ||
|
||
Follow follow = followRepository.findByFollowingIdAndFollowerId(followingId,followerId).orElseThrow(() -> new PostHandler(ErrorStatus.POST_FOLLOW_NOT_FOUND)); | ||
|
||
followRepository.delete(follow); | ||
} | ||
} |
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