-
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.
Browse files
Browse the repository at this point in the history
…profile-infos [프로필] [팔로우] 팔로워, 팔로잉 프로필 조회 기능 개발
- Loading branch information
Showing
25 changed files
with
688 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 관련 이슈 | ||
|
||
# 변경 사항 | ||
1. | ||
|
||
# 참고 사항 |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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") | ||
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.