-
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.
- Loading branch information
1 parent
b00058c
commit 3314b32
Showing
9 changed files
with
144 additions
and
10 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
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
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/healthiee/rest/repository/follow/FollowCustomRepository.kt
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,10 @@ | ||
package healthiee.rest.repository.follow | ||
|
||
import healthiee.rest.domain.follow.Follow | ||
import healthiee.rest.domain.member.Member | ||
|
||
interface FollowCustomRepository { | ||
|
||
fun findByMember(member: Member, targetMember: Member): Follow? | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/healthiee/rest/repository/follow/FollowCustomRepositoryImpl.kt
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,23 @@ | ||
package healthiee.rest.repository.follow | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import healthiee.rest.domain.follow.Follow | ||
import healthiee.rest.domain.follow.QFollow.follow | ||
import healthiee.rest.domain.member.Member | ||
import java.util.* | ||
|
||
class FollowCustomRepositoryImpl( | ||
private val queryFactory: JPAQueryFactory, | ||
) : FollowCustomRepository { | ||
|
||
override fun findByMember(member: Member, targetMember: Member): Follow? { | ||
return queryFactory.selectFrom(follow) | ||
.where( | ||
follow.member.eq(member), | ||
follow.targetMember.eq(targetMember), | ||
follow.deleted.eq(false) | ||
) | ||
.fetchOne() | ||
|
||
} | ||
} |
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,38 @@ | ||
package healthiee.rest.service | ||
|
||
import healthiee.rest.domain.follow.Follow | ||
import healthiee.rest.domain.member.Member | ||
import healthiee.rest.lib.error.ApiException | ||
import healthiee.rest.lib.error.ApplicationErrorCode.BAD_REQUEST_ALREADY_EXIST_FOLLOW | ||
import healthiee.rest.lib.error.ApplicationErrorCode.NOT_FOUND_FOLLOW | ||
import healthiee.rest.repository.follow.FollowRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class FollowService( | ||
val followRepository: FollowRepository, | ||
) { | ||
|
||
@Transactional | ||
fun follow(member: Member, targetMember: Member) { | ||
val findFollow = followRepository.findByMember(member, targetMember) | ||
findFollow?.let { throw ApiException(BAD_REQUEST_ALREADY_EXIST_FOLLOW) } | ||
|
||
followRepository.save(Follow.createFollow(member, targetMember)) | ||
} | ||
|
||
@Transactional | ||
fun unfollow(member: Member, targetMember: Member) { | ||
val findFollow = followRepository.findByMember(member, targetMember) | ||
?: throw ApiException(NOT_FOUND_FOLLOW) | ||
|
||
findFollow.delete() | ||
} | ||
|
||
fun getFollowingCount(member: Member): Int = followRepository.countByMember(member) | ||
|
||
fun getFollowerCount(member: Member): Int = followRepository.countByTargetMember(member) | ||
|
||
} |
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