Skip to content
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

feat: 친구 해제 API를 작성해요. #135

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions _endpoint_test/member.http
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ Authorization: {{authorization}}
### 친구 관계 생성 API
POST {{host}}/member/friend
Content-Type: application/json
Authorization: {{authorization}}

{
"fromMemberId": "22ee8f4c-c2db-49c5-ad5d-22db7bb67796",
"toMemberId": "71400a62-b535-48c3-967b-5a25a64137ae"
}

### 친구 관계 해제 API
DELETE {{host}}/member/friend
Content-Type: application/json
Authorization: {{authorization}}

{
"fromMemberId": "22ee8f4c-c2db-49c5-ad5d-22db7bb67796",
"toMemberId": "71400a62-b535-48c3-967b-5a25a64137ae"
}

### 마이스페이스 내가 받은 픽 조회 API
GET {{host}}/member/my-space/pick
Expand Down
19 changes: 19 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/MemberController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.mashup.dojo.domain.MemberRelationId
import com.mashup.dojo.dto.FriendSpacePickResponse
import com.mashup.dojo.dto.MemberCreateFriendRelationRequest
import com.mashup.dojo.dto.MemberCreateRequest
import com.mashup.dojo.dto.MemberDeleteFriendRelationRequest
import com.mashup.dojo.dto.MemberLoginRequest
import com.mashup.dojo.dto.MemberProfileResponse
import com.mashup.dojo.dto.MemberSearchResponse
Expand All @@ -21,6 +22,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
Expand Down Expand Up @@ -206,6 +208,23 @@ class MemberController(
return DojoApiResponse.success(memberUseCase.updateFriendRelation(MemberUseCase.UpdateFriendCommand(request.fromMemberId, request.toMemberId)))
}

@DeleteMapping("/member/friend")
@Operation(
summary = "친구(팔로우)해제 API",
description = "from 이 to 에 대한 친구(팔로우)를 해제합니다. 이미 친구 관계가 아니라면 예외를 반환해요."
)
fun deleteFriend(
@RequestBody request: MemberDeleteFriendRelationRequest,
): DojoApiResponse<Unit> {
val command =
MemberUseCase.UpdateFriendCommand(
fromId = request.fromMemberId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromId는 MemberPrincipalContextHolder.current().id요렇게 꺼내는 건 어떨까요~?

toId = request.toMemberId
)
memberUseCase.deleteFriendRelation(command)
return DojoApiResponse.success()
}

@GetMapping("/member/my-space/pick")
@Operation(
summary = "마이 스페이스 내가 받은 픽 API",
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/dto/MemberCreateRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ data class MemberCreateFriendRelationRequest(
@Schema(description = "팔로우 대상 유저 id")
val toMemberId: MemberId,
)

@Schema(description = "팔로우 해제 요청")
data class MemberDeleteFriendRelationRequest(
@field:NotBlank
@Schema(description = "팔로우 해제 요청한 유저 id")
val fromMemberId: MemberId,
@field:NotBlank
@Schema(description = "팔로우 해제 대상 유저 id")
val toMemberId: MemberId,
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum class DojoExceptionType(
// friend
FRIEND_NOT_FOUND("Friend not found", "C070_FRIEND_NOT_FOUND", 400),
ALREADY_FRIEND("Already Friend", "C071_ALREADY_FRIEND", 400),
ALREADY_ACCOMPANY("Already Accompany", "C071_ALREADY_ACCOMPANY", 400),

// auth
INVALID_TOKEN("invalid token", "C100_INVALID_TOKEN", 401),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ data class MemberRelation(
fun updateToFriend(): MemberRelation {
return this.copy(relation = RelationType.FRIEND, lastUpdatedAt = LocalDateTime.now())
}

fun accompany(): MemberRelation {
return this.copy(relation = RelationType.ACCOMPANY, lastUpdatedAt = LocalDateTime.now())
}
}

enum class RelationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ interface MemberRelationService {
toId: MemberId,
): MemberRelationId

fun deleteFriendRelation(
fromId: MemberId,
toId: MemberId,
)

fun isFriend(
fromId: MemberId,
toId: MemberId,
Expand Down Expand Up @@ -107,6 +112,18 @@ class DefaultMemberRelationService(
return MemberRelationId(memberRelationRepository.save(updatedRelation.toEntity()).id)
}

@Transactional
override fun deleteFriendRelation(
fromId: MemberId,
toId: MemberId,
) {
val relation = memberRelationRepository.findByFromIdAndToId(fromId.value, toId.value)?.toDomain() ?: throw DojoException.of(DojoExceptionType.FRIEND_NOT_FOUND)
if (relation.relation == RelationType.ACCOMPANY) {
throw DojoException.of(DojoExceptionType.ALREADY_ACCOMPANY)
}
relation.accompany()
}

override fun isFriend(
fromId: MemberId,
toId: MemberId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ interface MemberUseCase {

fun updateFriendRelation(command: UpdateFriendCommand): MemberRelationId

fun deleteFriendRelation(command: UpdateFriendCommand)

fun receivedMySpacePicks(currentMemberId: MemberId): List<PickService.SpacePickDetail>

fun searchMember(
Expand Down Expand Up @@ -196,6 +198,11 @@ class DefaultMemberUseCase(
return memberRelationService.updateRelationToFriend(command.fromId, command.toId)
}

@Transactional
override fun deleteFriendRelation(command: MemberUseCase.UpdateFriendCommand) {
return memberRelationService.deleteFriendRelation(command.fromId, command.toId)
}

override fun searchMember(
memberId: MemberId,
keyword: String,
Expand Down
Loading