-
Notifications
You must be signed in to change notification settings - Fork 0
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
[프로필] [팔로우] 팔로워, 팔로잉 프로필 조회 기능 개발 #26
Merged
jojaeng2
merged 9 commits into
develop
from
feat/#22-get-follower-following-profile-infos
Sep 20, 2023
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cf99438
feature: follow, unfollow 기능 리팩토링
jojaeng2 7ef72d3
feat: profile 조회 시 팔로워 수, 팔로잉 수, 팔로워 프로필 조회, 팔로잉 프로필 조회 기능 추가
jojaeng2 5eade32
test: follow domain 비즈니스 로직 테스트 추가
jojaeng2 60f48eb
feat: profile domain 비즈니스 로직 테스트
jojaeng2 55e5c09
delete : 불필요한 dto 삭제
jojaeng2 0fa5709
docs: PR template 추가
jojaeng2 c358253
refactor: @RestController, delete data class
jojaeng2 f4fb3d7
chore: @RequiredArgs제거, addFollow method 변경
jojaeng2 a202f5c
test: 팔로우 관계 추가 test 수정
jojaeng2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 관련 이슈 | ||
|
||
# 변경 사항 | ||
1. | ||
|
||
# 참고 사항 |
27 changes: 27 additions & 0 deletions
27
sns_service/src/main/kotlin/joryu/sns_service/follow/controller/FollowController.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,27 @@ | ||
package joryu.sns_service.follow.controller | ||
|
||
import joryu.sns_service.follow.dto.request.FollowRequest | ||
import joryu.sns_service.follow.dto.request.UnFollowRequest | ||
import joryu.sns_service.follow.service.FollowService | ||
import lombok.RequiredArgsConstructor | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/follow") | ||
@RequiredArgsConstructor | ||
class FollowController( | ||
private val followService: FollowService | ||
) { | ||
@PostMapping("/{fromProfileId}") | ||
fun follow(@PathVariable("fromProfileId") fromProfileId: Long, @RequestBody followRequest: FollowRequest): ResponseEntity<Void> { | ||
followService.follow(fromProfileId, followRequest.toProfileId) | ||
return ResponseEntity.ok().build() | ||
} | ||
|
||
@DeleteMapping("/{fromProfileId}") | ||
fun unFollow(@PathVariable("fromProfileId") fromProfileId: Long, @RequestBody unFollowRequest: UnFollowRequest): ResponseEntity<Void> { | ||
followService.unFollow(fromProfileId, unFollowRequest.toProfileId) | ||
return ResponseEntity.ok().build() | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/FollowRequest.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,4 @@ | ||
package joryu.sns_service.follow.dto.request | ||
|
||
data class FollowRequest(val toProfileId: Long) { | ||
} |
4 changes: 4 additions & 0 deletions
4
sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/UnFollowRequest.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,4 @@ | ||
package joryu.sns_service.follow.dto.request | ||
|
||
data class UnFollowRequest(val toProfileId: Long) { | ||
} |
28 changes: 28 additions & 0 deletions
28
sns_service/src/main/kotlin/joryu/sns_service/follow/entity/Follow.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,28 @@ | ||
package joryu.sns_service.follow.entity | ||
|
||
import jakarta.persistence.* | ||
import joryu.sns_service.common.entity.BaseEntity | ||
import joryu.sns_service.profile.entity.Profile | ||
|
||
@Table(name = "follow") | ||
@Entity | ||
class Follow( | ||
@Id | ||
@Column(name = "follow_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long?, | ||
|
||
@ManyToOne | ||
@JoinColumn | ||
val fromProfile: Profile?, | ||
|
||
@ManyToOne | ||
@JoinColumn | ||
val toProfile: Profile? | ||
) : BaseEntity() { | ||
constructor() : this(null, null, null) | ||
constructor(fromProfile: Profile, toProfile: Profile) : this(null, fromProfile, toProfile) { | ||
toProfile.addFollower(this) | ||
fromProfile.addFollowing(this) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
sns_service/src/main/kotlin/joryu/sns_service/follow/repository/FollowRepository.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,11 @@ | ||
package joryu.sns_service.follow.repository | ||
|
||
import joryu.sns_service.follow.entity.Follow | ||
import joryu.sns_service.profile.entity.Profile | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface FollowRepository : JpaRepository<Follow, Long> { | ||
fun deleteByFromProfileAndToProfile(fromProfile: Profile, toProfile: Profile) | ||
fun findAllByToProfile(toProfile: Profile): MutableList<Follow> | ||
fun findAllByFromProfile(fromProfile: Profile): MutableList<Follow> | ||
} |
37 changes: 37 additions & 0 deletions
37
sns_service/src/main/kotlin/joryu/sns_service/follow/service/FollowService.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,37 @@ | ||
package joryu.sns_service.follow.service | ||
|
||
import joryu.sns_service.follow.entity.Follow | ||
import joryu.sns_service.follow.repository.FollowRepository | ||
import joryu.sns_service.profile.exception.ProfileBaseException | ||
import joryu.sns_service.profile.exception.ProfileExceptionEnums | ||
import joryu.sns_service.profile.repository.ProfileRepository | ||
import lombok.RequiredArgsConstructor | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
class FollowService( | ||
private val followRepository: FollowRepository, | ||
private val profileRepository: ProfileRepository | ||
) { | ||
|
||
@Transactional | ||
fun follow(fromProfileId: Long, toProfileId: Long) { | ||
val fromProfile = profileRepository.findById(fromProfileId) | ||
.orElseThrow { ProfileBaseException(ProfileExceptionEnums.PROFILE_NOT_FOUND) } | ||
val toProfile = profileRepository.findById(toProfileId) | ||
.orElseThrow { ProfileBaseException(ProfileExceptionEnums.PROFILE_NOT_FOUND) } | ||
val follow = Follow(fromProfile, toProfile) | ||
followRepository.save(follow) | ||
} | ||
|
||
@Transactional | ||
fun unFollow(fromProfileId: Long, toProfileId: Long) { | ||
val fromProfile = profileRepository.findById(fromProfileId) | ||
.orElseThrow { ProfileBaseException(ProfileExceptionEnums.PROFILE_NOT_FOUND) } | ||
val toProfile = profileRepository.findById(toProfileId) | ||
.orElseThrow { ProfileBaseException(ProfileExceptionEnums.PROFILE_NOT_FOUND) } | ||
followRepository.deleteByFromProfileAndToProfile(fromProfile, toProfile) | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
sns_service/src/main/kotlin/joryu/sns_service/follower/controller/FollowerController.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
sns_service/src/main/kotlin/joryu/sns_service/follower/dto/request/FollowRequest.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
sns_service/src/main/kotlin/joryu/sns_service/follower/dto/request/UnFollowRequest.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...e/src/main/kotlin/joryu/sns_service/follower/dto/response/AllFollowingProfilesResponse.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
sns_service/src/main/kotlin/joryu/sns_service/follower/entity/Follower.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
sns_service/src/main/kotlin/joryu/sns_service/follower/repository/FollowerRepository.kt
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
sns_service/src/main/kotlin/joryu/sns_service/follower/service/FollowerService.kt
This file was deleted.
Oops, something went wrong.
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
13 changes: 13 additions & 0 deletions
13
...vice/src/main/kotlin/joryu/sns_service/profile/dto/response/AllFollowerProfileResponse.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,13 @@ | ||
package joryu.sns_service.profile.dto.response | ||
|
||
import joryu.sns_service.profile.entity.Profile | ||
|
||
data class AllProfileResponse( | ||
val profileInfo: MutableList<ProfileInfoResponse> = mutableListOf() | ||
) { | ||
|
||
fun addProfileInfoInFollows(profiles: List<Profile?>): AllProfileResponse { | ||
profiles.forEach { profile -> profileInfo.add(ProfileInfoResponse(profile)) } | ||
return this | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RequiredArgsConstructor
는 없어도 될 것 같습니당