-
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
Changes from 6 commits
cf99438
7ef72d3
5eade32
60f48eb
55e5c09
0fa5709
c358253
f4fb3d7
a202f5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 관련 이슈 | ||
|
||
# 변경 사항 | ||
1. | ||
|
||
# 참고 사항 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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.stereotype.Controller | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Controller | ||
@RequestMapping("/follow") | ||
@RequiredArgsConstructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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() | ||
} | ||
} |
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) { | ||
} |
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) { | ||
} |
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 | ||
data class Follow( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Entity 에 data class 를 사용하신 이유가 있으신가욜? 몰라서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생각없이 썼어서 이유는 없었는데요, |
||
@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) | ||
} | ||
} |
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> | ||
} |
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) | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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 | ||
} | ||
} |
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.
@RestController 를 사용하는건 어떤가요?
ResponseBody가 따로 없어서 안쓰신건가용
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.
아뇨 그냥 생각없이 쓴 것 같아요.. 수정 하겠습니답