From 5937da7b43a3d64f6500723a597fba844618c41c Mon Sep 17 00:00:00 2001 From: xonmin Date: Wed, 14 Aug 2024 17:25:17 +0900 Subject: [PATCH] =?UTF-8?q?add=20:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mashup/dojo/MemberController.kt | 20 ++++++++++++++++++- .../mashup/dojo/dto/MemberCreateRequest.kt | 11 ++++++++++ .../dojo/service/MemberRelationService.kt | 16 +++++++-------- .../com/mashup/dojo/usecase/MemberUseCase.kt | 12 +++++++++++ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/api/src/main/kotlin/com/mashup/dojo/MemberController.kt b/api/src/main/kotlin/com/mashup/dojo/MemberController.kt index e5ee90a2..6df5e66c 100644 --- a/api/src/main/kotlin/com/mashup/dojo/MemberController.kt +++ b/api/src/main/kotlin/com/mashup/dojo/MemberController.kt @@ -4,6 +4,7 @@ import com.mashup.dojo.common.DojoApiResponse import com.mashup.dojo.config.security.JwtTokenService import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.MemberRelationId +import com.mashup.dojo.dto.MemberCreateFriendRelationRequest import com.mashup.dojo.dto.MemberCreateRequest import com.mashup.dojo.dto.MemberLoginRequest import com.mashup.dojo.dto.MemberProfileResponse @@ -155,10 +156,27 @@ class MemberController( // todo : temp api for insert relationship data @PostMapping("/public/member/relation/{id}") - fun createRelationShip(@PathVariable id: MemberId): DojoApiResponse> { + fun createRelationShip( + @PathVariable id: MemberId, + ): DojoApiResponse> { return DojoApiResponse.success(memberUseCase.createDefaultMemberRelation(id)) } + // follow 생성 API - todo : mashup 내 인원들 follow 생성을 위해 url public 으로 시작 (이후 변경) + @PostMapping("/public/member/relation") + @Operation( + summary = "팔로우 생성 API", + description = "팔로우 생성 API, 팔로우 기능에 대해서 from 이 to 를 follow 합니다. 이미 follow가 존재한다면 예외를 반환해요", + responses = [ + ApiResponse(responseCode = "200", description = "생성된 관계 id") + ] + ) + fun createFriend( + @RequestBody request: MemberCreateFriendRelationRequest, + ): DojoApiResponse { + return DojoApiResponse.success(memberUseCase.updateToFollowRelation(MemberUseCase.CreateFollowCommand(request.fromMemberId, request.toMemberId))) + } + data class MemberCreateResponse( val id: MemberId, ) diff --git a/api/src/main/kotlin/com/mashup/dojo/dto/MemberCreateRequest.kt b/api/src/main/kotlin/com/mashup/dojo/dto/MemberCreateRequest.kt index 8b05e49e..a3e4d1fa 100644 --- a/api/src/main/kotlin/com/mashup/dojo/dto/MemberCreateRequest.kt +++ b/api/src/main/kotlin/com/mashup/dojo/dto/MemberCreateRequest.kt @@ -2,6 +2,7 @@ package com.mashup.dojo.dto import com.mashup.dojo.domain.ImageId import com.mashup.dojo.domain.MemberGender +import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.MemberPlatform import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank @@ -24,3 +25,13 @@ data class MemberCreateRequest( data class MemberUpdateRequest( val profileImageId: ImageId?, ) + +@Schema(description = "팔로우 생성 요청") +data class MemberCreateFriendRelationRequest( + @field:NotBlank + @Schema(description = "팔로우 요청한 유저 id") + val fromMemberId: MemberId, + @field:NotBlank + @Schema(description = "팔로우 대상 유저 id") + val toMemberId: MemberId, +) diff --git a/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt b/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt index e1266327..e05aa42a 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/MemberRelationService.kt @@ -29,9 +29,9 @@ interface MemberRelationService { ): List fun updateRelationToFriend( - fromId: String, - toId: String, - ) + fromId: MemberId, + toId: MemberId, + ): MemberRelationId fun isFriend( fromId: MemberId, @@ -81,15 +81,15 @@ class DefaultMemberRelationService( @Transactional override fun updateRelationToFriend( - fromId: String, - toId: String, - ) { - val toDomain = memberRelationRepository.findByFromIdAndToId(fromId, toId)?.toDomain() ?: throw DojoException.of(DojoExceptionType.FRIEND_NOT_FOUND) + fromId: MemberId, + toId: MemberId, + ): MemberRelationId { + val toDomain = memberRelationRepository.findByFromIdAndToId(fromId.value, toId.value)?.toDomain() ?: throw DojoException.of(DojoExceptionType.FRIEND_NOT_FOUND) if (toDomain.relation == RelationType.FRIEND) { throw DojoException.of(DojoExceptionType.ALREADY_FRIEND) } val updatedRelation = toDomain.updateToFriend() - memberRelationRepository.save(updatedRelation.toEntity()) + return MemberRelationId(memberRelationRepository.save(updatedRelation.toEntity()).id) } override fun isFriend( diff --git a/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt b/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt index 56ee9bae..fac75c71 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt @@ -40,6 +40,11 @@ interface MemberUseCase { val friendCount: Int, ) + data class CreateFollowCommand( + val fromId: MemberId, + val toId: MemberId, + ) + fun create(command: CreateCommand): MemberId fun update(command: UpdateCommand): MemberId @@ -50,6 +55,8 @@ interface MemberUseCase { fun findMemberByIdMock(targetMemberId: MemberId): ProfileResponse fun createDefaultMemberRelation(newMemberId: MemberId): List + + fun updateToFollowRelation(command: CreateFollowCommand): MemberRelationId } @Component @@ -145,4 +152,9 @@ class DefaultMemberUseCase( return memberRelationService.bulkCreateRelation(newMemberId, allMemberIds) } + + @Transactional + override fun updateToFollowRelation(command: MemberUseCase.CreateFollowCommand): MemberRelationId { + return memberRelationService.updateRelationToFriend(command.fromId, command.toId) + } }