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: 그룹 수락 기능 구현 #422

Merged
merged 24 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
42efafb
feat : 프록시 패턴으로 서비스 분리
GaBaljaintheroom May 8, 2024
4d0dcda
feat : 그룹 초대 기능 구현
GaBaljaintheroom May 8, 2024
b0b03dc
refact: 그룹 초대 서비스 수정
GaBaljaintheroom May 8, 2024
53b255d
chore : 서비스 레포지토리 패키지 분리
GaBaljaintheroom May 8, 2024
4366d26
feat : 그룹 초대 거부 기능 구현
GaBaljaintheroom May 9, 2024
b1c9515
refact : 친구 초대 거절 쿼리 수정
GaBaljaintheroom May 9, 2024
731a01b
refact : 비밀 캡슐 오픈 쿼리 수정
GaBaljaintheroom May 9, 2024
2521e9c
feat : memberId, FriendId 중복 검사 추가
GaBaljaintheroom May 11, 2024
1fbd27c
feat : 그룹 요청 수락 기능 구현
GaBaljaintheroom May 11, 2024
a289073
refact : 그룹 도메인 문서화 수정 및 코드 일치
GaBaljaintheroom May 12, 2024
d68800b
test : 그룹 생성 및 초대 단위 테스트 작성
GaBaljaintheroom May 13, 2024
da3cb0e
feat : 그룹 초대 거부 기능 구현
GaBaljaintheroom May 9, 2024
dde3704
refact : 친구 초대 거절 쿼리 수정
GaBaljaintheroom May 9, 2024
8d86e12
refact : 비밀 캡슐 오픈 쿼리 수정
GaBaljaintheroom May 9, 2024
babcf85
feat : memberId, FriendId 중복 검사 추가
GaBaljaintheroom May 11, 2024
8447394
Merge remote-tracking branch 'origin/feat/group_reject_B-#408' into f…
GaBaljaintheroom May 13, 2024
9971076
test : 그룹 초대 거부 테스트
GaBaljaintheroom May 13, 2024
2bd870c
feat : 그룹 요청 수락 기능 구현
GaBaljaintheroom May 11, 2024
38be188
refact : 그룹 도메인 문서화 수정 및 코드 일치
GaBaljaintheroom May 12, 2024
60ea79a
Merge remote-tracking branch 'origin/feat/group_accept_B-#414' into f…
GaBaljaintheroom May 13, 2024
02a1ff0
test : 그룹 초대 테스트 작성
GaBaljaintheroom May 13, 2024
c3f7609
refact : 그룹 초대에 그룹 id 추가
GaBaljaintheroom May 13, 2024
bfeeacb
Merge branch 'develop_back_core' into feat/group_accept_B-#414
GaBaljaintheroom May 14, 2024
1ec519a
Merge branch 'develop_back_core' into feat/group_accept_B-#414
GaBaljaintheroom May 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public record NearbyARCapsuleSummaryResponse(
@Schema(description = "캡슐 타입")
CapsuleType capsuleType
) {

public NearbyARCapsuleSummaryResponse {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Optional<Capsule> findCapsuleByMemberIdAndCapsuleId(

@Modifying(clearAutomatically = true)
@Query("UPDATE Capsule c SET c.isOpened = true WHERE c.id = :capsuleId and c.member.id = :memberId")
void updateIsOpenedTrue(
int updateIsOpenedTrue(
@Param("memberId") Long memberId,
@Param("capsuleId") Long capsuleId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public Capsule findCapsuleByMemberIdAndCapsuleId(final Long memberId, final Long

@Transactional
public void updateIsOpenedTrue(final Long memberId, final Long capsuleId) {
capsuleRepository.updateIsOpenedTrue(memberId, capsuleId);
int isOpenedTrue = capsuleRepository.updateIsOpenedTrue(memberId, capsuleId);

if (isOpenedTrue != 1) {
throw new CapsuleNotFondException();
}
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.function.Function;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.response.MySecreteCapsuleResponse;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

public record MySecreteCapsuleDto(
Long capsuleId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.http.ResponseEntity;
import site.timecapsulearchive.core.domain.friend.data.request.SearchFriendsRequest;
import site.timecapsulearchive.core.domain.friend.data.request.SendFriendRequest;
import site.timecapsulearchive.core.domain.friend.data.response.FriendReqStatusResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendRequestsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchFriendsResponse;
Expand Down Expand Up @@ -129,7 +128,7 @@ ResponseEntity<ApiSpec<String>> denyFriendRequest(
description = "외부 API 요청 실패"
)
})
ResponseEntity<ApiSpec<FriendReqStatusResponse>> requestFriend(
ResponseEntity<ApiSpec<String>> requestFriend(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "친구 아이디", required = true, schema = @Schema())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import site.timecapsulearchive.core.domain.friend.data.dto.SearchFriendSummaryDto;
import site.timecapsulearchive.core.domain.friend.data.request.SearchFriendsRequest;
import site.timecapsulearchive.core.domain.friend.data.request.SendFriendRequest;
import site.timecapsulearchive.core.domain.friend.data.response.FriendReqStatusResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendRequestsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchFriendsResponse;
Expand Down Expand Up @@ -89,7 +88,9 @@ public ResponseEntity<ApiSpec<String>> deleteFriend(
friendService.deleteFriend(memberId, friendId);

return ResponseEntity.ok(
ApiSpec.empty(SuccessCode.SUCCESS)
ApiSpec.empty(
SuccessCode.SUCCESS
)
);
}

Expand All @@ -101,23 +102,26 @@ public ResponseEntity<ApiSpec<String>> denyFriendRequest(

friendService.denyRequestFriend(memberId, friendId);

return ResponseEntity.ok(ApiSpec.empty(SuccessCode.SUCCESS));

return ResponseEntity.ok(
ApiSpec.empty(
SuccessCode.SUCCESS
)
);
}

@PostMapping(value = "/{friend_id}/request")
@Override
public ResponseEntity<ApiSpec<FriendReqStatusResponse>> requestFriend(
public ResponseEntity<ApiSpec<String>> requestFriend(
@AuthenticationPrincipal final Long memberId,
@PathVariable("friend_id") final Long friendId) {

return ResponseEntity.accepted()
.body(
ApiSpec.success(
SuccessCode.SUCCESS,
friendService.requestFriend(memberId, friendId)
)
);
friendService.requestFriend(memberId, friendId);

return ResponseEntity.ok(
ApiSpec.empty(
SuccessCode.ACCEPTED
)
);
}

@PostMapping(value = "/requests")
Expand All @@ -128,8 +132,11 @@ public ResponseEntity<ApiSpec<String>> requestFriends(
) {
friendFacade.requestFriends(memberId, request.friendIds());

return ResponseEntity.accepted()
.body(ApiSpec.empty(SuccessCode.ACCEPTED));
return ResponseEntity.ok(
ApiSpec.empty(
SuccessCode.ACCEPTED
)
);
}

@PostMapping(value = "/{friend_id}/accept-request")
Expand All @@ -140,7 +147,11 @@ public ResponseEntity<ApiSpec<String>> acceptFriendRequest(
) {
friendService.acceptFriend(memberId, friendId);

return ResponseEntity.ok(ApiSpec.empty(SuccessCode.SUCCESS));
return ResponseEntity.ok(
ApiSpec.empty(
SuccessCode.SUCCESS
)
);
}

@PostMapping(
Expand Down Expand Up @@ -173,12 +184,11 @@ public ResponseEntity<ApiSpec<SearchTagFriendSummaryResponse>> searchFriendByTag
@AuthenticationPrincipal Long memberId,
@RequestParam(value = "friend_tag") final String tag
) {
return ResponseEntity.ok()
.body(
ApiSpec.success(
SuccessCode.SUCCESS,
friendService.searchFriend(memberId, tag)
)
);
return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
friendService.searchFriend(memberId, tag)
)
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.ZonedDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
Expand All @@ -19,8 +21,8 @@ public void bulkSave(final Long ownerId, final List<Long> friendIds) {
jdbcTemplate.batchUpdate(
"""
INSERT INTO friend_invite (
friend_invite_id, owner_id, friend_id
) values (?, ?, ?)
friend_invite_id, owner_id, friend_id, created_at, updated_at
) values (?, ?, ?, ?, ?)
""",
new BatchPreparedStatementSetter() {

Expand All @@ -30,6 +32,8 @@ public void setValues(final PreparedStatement ps, final int i) throws SQLExcepti
ps.setNull(1, Types.BIGINT);
ps.setLong(2, ownerId);
ps.setLong(3, friendId);
ps.setTimestamp(4, Timestamp.valueOf(ZonedDateTime.now().toLocalDateTime()));
ps.setTimestamp(5, Timestamp.valueOf(ZonedDateTime.now().toLocalDateTime()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ List<FriendInvite> findFriendInviteWithMembersByOwnerIdAndFriendId(

Optional<FriendInvite> findFriendInviteByOwnerIdAndFriendId(Long memberId, Long targetId);

void deleteFriendInviteById(Long id);
int deleteFriendInviteByOwnerIdAndFriendId(Long memberId, Long targetId);

void delete(FriendInvite friendInvite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import site.timecapsulearchive.core.domain.friend.data.dto.FriendSummaryDto;
import site.timecapsulearchive.core.domain.friend.data.dto.SearchFriendSummaryDto;
import site.timecapsulearchive.core.domain.friend.data.dto.SearchFriendSummaryDtoByTag;
import site.timecapsulearchive.core.domain.friend.data.response.FriendReqStatusResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchTagFriendSummaryResponse;
import site.timecapsulearchive.core.domain.friend.entity.FriendInvite;
import site.timecapsulearchive.core.domain.friend.entity.MemberFriend;
Expand Down Expand Up @@ -43,7 +42,7 @@ public class FriendService {
private final SocialNotificationManager socialNotificationManager;
private final TransactionTemplate transactionTemplate;

public FriendReqStatusResponse requestFriend(final Long memberId, final Long friendId) {
public void requestFriend(final Long memberId, final Long friendId) {
validateFriendDuplicateId(memberId, friendId);
validateTwoWayInvite(memberId, friendId);

Expand All @@ -63,8 +62,6 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
});

socialNotificationManager.sendFriendReqMessage(owner.getNickname(), friendId);

return FriendReqStatusResponse.success();
}

private void validateFriendDuplicateId(final Long memberId, final Long friendId) {
Expand Down Expand Up @@ -114,20 +111,22 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
}

@Transactional
public void denyRequestFriend(Long memberId, Long friendId) {
public void denyRequestFriend(final Long memberId, final Long friendId) {
validateFriendDuplicateId(memberId, friendId);
final FriendInvite friendInvite = friendInviteRepository
.findFriendInviteByOwnerIdAndFriendId(memberId, friendId).orElseThrow(
FriendNotFoundException::new);

friendInviteRepository.deleteFriendInviteById(friendInvite.getId());
int isDenyRequest = friendInviteRepository.deleteFriendInviteByOwnerIdAndFriendId(friendId,
memberId);

if (isDenyRequest != 1) {
throw new FriendTwoWayInviteException();
}
}

@Transactional
public void deleteFriend(final Long memberId, final Long friendId) {
validateFriendDuplicateId(memberId, friendId);

List<MemberFriend> memberFriends = memberFriendRepository
final List<MemberFriend> memberFriends = memberFriendRepository
.findMemberFriendByOwnerIdAndFriendId(memberId, friendId);

memberFriends.forEach(memberFriendRepository::delete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupCreateRequest;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupUpdateRequest;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
Expand All @@ -32,15 +31,24 @@ public interface GroupApi {
@ApiResponse(
responseCode = "200",
description = "처리 완료"
),
@ApiResponse(
responseCode = "404",
description = "그룹 초대 찾기 실패"
),
@ApiResponse(
responseCode = "500",
description = "외부 API 요청 실패"
)
})
@PostMapping(value = "/groups/{group_id}/members/{member_id}/accept-invitation")
ResponseEntity<Void> acceptGroupInvitation(
@Parameter(in = ParameterIn.PATH, description = "그룹 아이디", required = true, schema = @Schema())
@PathVariable("group_id") Long groupId,
ResponseEntity<ApiSpec<String>> acceptGroupInvitation(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "대상 회원 아이디", required = true, schema = @Schema())
@PathVariable("member_id") Long memberId
@Parameter(in = ParameterIn.PATH, description = "그룹 아이디", required = true)
Long groupId,

@Parameter(in = ParameterIn.PATH, description = "대상 회원 아이디", required = true)
Long targetId
);

@Operation(
Expand All @@ -53,6 +61,10 @@ ResponseEntity<Void> acceptGroupInvitation(
@ApiResponse(
responseCode = "200",
description = "처리완료"
),
@ApiResponse(
responseCode = "500",
description = "외부 API 요청 실패"
)
})
ResponseEntity<ApiSpec<String>> createGroup(
Expand Down Expand Up @@ -111,13 +123,13 @@ ResponseEntity<Void> deleteGroupMember(
description = "처리 완료"
)
})
@PostMapping(value = "/groups/{group_id}/members/{member_id}/deny-invitation")
ResponseEntity<Void> denyGroupInvitation(
@Parameter(in = ParameterIn.PATH, description = "그룹 아이디", required = true, schema = @Schema())
@PathVariable("group_id") Long groupId,
ResponseEntity<ApiSpec<String>> rejectGroupInvitation(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "대상 회원 아이디", required = true, schema = @Schema())
@PathVariable("member_id") Long memberId
Long groupId,

@Parameter(in = ParameterIn.PATH, description = "그룹 초대 대상 아이디", required = true)
Long groupOwnerId
);

@Operation(
Expand Down Expand Up @@ -181,13 +193,14 @@ ResponseEntity<ApiSpec<GroupsSliceResponse>> findGroups(
description = "처리 시작"
)
})
@PostMapping(value = "/groups/{group_id}/members/{member_id}/invitation")
ResponseEntity<Void> inviteGroup(
@Parameter(in = ParameterIn.PATH, description = "그룹 아이디", required = true, schema = @Schema())
@PathVariable("group_id") Long groupId,
ResponseEntity<ApiSpec<String>> inviteGroup(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "대상 회원 아이디", required = true, schema = @Schema())
@PathVariable("member_id") Long memberId
@Parameter(in = ParameterIn.PATH, description = "그룹 아이디", required = true)
Long groupId,

@Parameter(in = ParameterIn.PATH, description = "대상 회원 아이디", required = true)
Long targetId
);

@Operation(
Expand Down
Loading
Loading