Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop_back_core' into feat/group_invite_li…
Browse files Browse the repository at this point in the history
…st-B-#458

# Conflicts:
#	backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/api/query/MemberGroupQueryApi.java
#	backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/api/query/MemberGroupQueryApiController.java
#	backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandService.java
#	backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupQueryService.java
#	backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java
  • Loading branch information
seokho-1116 committed Jun 4, 2024
2 parents 603f155 + f42c146 commit 8258fc2
Show file tree
Hide file tree
Showing 55 changed files with 867 additions and 202 deletions.
2 changes: 2 additions & 0 deletions backend/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
//redis
implementation 'org.springframework.data:spring-data-redis'
implementation 'io.lettuce:lettuce-core:6.3.0.RELEASE'
implementation 'org.redisson:redisson-spring-boot-starter:3.30.0'

//RabbitMQ
implementation 'org.springframework.boot:spring-boot-starter-amqp'
Expand Down Expand Up @@ -85,6 +86,7 @@ dependencies {
testImplementation 'org.testcontainers:testcontainers:1.19.1'
testImplementation 'org.testcontainers:junit-jupiter:1.19.1'
testImplementation 'org.testcontainers:mysql:1.19.1'
testImplementation 'com.redis:testcontainers-redis:2.2.2'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@Builder
public record GroupCapsuleCreateRequestDto(
List<Long> groupMemberIds,
List<String> imageNames,
List<String> videoNames,
Long capsuleSkinId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
@Schema(description = "그룹 캡슐 생성 포맷")
public record GroupCapsuleCreateRequest(

@Schema(description = "그룹 멤버 아이디들")
@NotNull(message = "그룹 멤버 아이디들는 필수입니다.")
List<Long> groupMemberIds,

@Schema(description = "업로드한 이미지 경로 ex) xxx.jpg")
List<@Image String> imageNames,

Expand Down Expand Up @@ -56,7 +52,6 @@ public record GroupCapsuleCreateRequest(

public GroupCapsuleCreateRequestDto toGroupCapsuleCreateRequestDto() {
return GroupCapsuleCreateRequestDto.builder()
.groupMemberIds(groupMemberIds)
.videoNames(videoNames)
.imageNames(imageNames)
.capsuleSkinId(capsuleSkinId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.facade;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.locationtech.jts.geom.Point;
import org.springframework.stereotype.Component;
Expand All @@ -16,6 +17,7 @@
import site.timecapsulearchive.core.domain.group.service.query.GroupQueryService;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.domain.member.service.MemberService;
import site.timecapsulearchive.core.domain.member_group.service.MemberGroupQueryService;
import site.timecapsulearchive.core.global.geography.GeoTransformManager;

@Component
Expand All @@ -25,6 +27,7 @@ public class GroupCapsuleFacade {
private final MemberService memberService;
private final GroupCapsuleService groupCapsuleService;
private final GroupQueryService groupQueryService;
private final MemberGroupQueryService memberGroupQueryService;
private final ImageService imageService;
private final VideoService videoService;
private final GeoTransformManager geoTransformManager;
Expand All @@ -51,6 +54,8 @@ public void saveGroupCapsule(
imageService.bulkSave(dto.imageNames(), capsule, member);
videoService.bulkSave(dto.videoNames(), capsule, member);

groupCapsuleOpenService.bulkSave(dto.groupMemberIds(), capsule);
final List<Long> groupMemberIds = memberGroupQueryService.findGroupMemberIds(groupId);

groupCapsuleOpenService.bulkSave(groupMemberIds, capsule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinCreateDto;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinSummaryDto;
Expand Down Expand Up @@ -59,12 +57,9 @@ public CapsuleSkinStatusResponse sendCapsuleSkinCreateMessage(
if (isNotExistMotionNameAndRetarget(dto)) {
CapsuleSkin capsuleSkin = capsuleSkinMapper.createDtoToEntity(dto, foundMember);

transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
capsuleSkinRepository.save(capsuleSkin);
}
});
transactionTemplate.executeWithoutResult(status ->
capsuleSkinRepository.save(capsuleSkin)
);
return CapsuleSkinStatusResponse.success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ ResponseEntity<ApiSpec<SearchFriendsResponse>> searchMembersByPhones(
@Operation(
summary = "친구 검색",
description = """
친구의 tag로 친구 검색을 한다.
<br>
태그가 일치하면 일치하는 태그를 가진 사용자를 일치하지 않으면 가장 비슷한 태그를 가진 사용자를 반환한다.
""",
친구의 tag로 친구 검색을 한다.
<br>
태그가 일치하면 일치하는 태그를 가진 사용자를 일치하지 않으면 가장 비슷한 태그를 가진 사용자를 반환한다.
""",
security = {@SecurityRequirement(name = "user_token")},
tags = {"friend"}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import site.timecapsulearchive.core.domain.friend.entity.FriendInvite;
import site.timecapsulearchive.core.domain.friend.entity.MemberFriend;
Expand Down Expand Up @@ -34,15 +32,12 @@ public void requestFriends(Long memberId, List<Long> friendIds) {
final Member[] owner = new Member[1];
final List<Long>[] foundFriendIds = new List[1];

transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
owner[0] = memberRepository.findMemberById(memberId)
.orElseThrow(MemberNotFoundException::new);
foundFriendIds[0] = memberRepository.findMemberIdsByIds(friendIds);
transactionTemplate.executeWithoutResult(status -> {
owner[0] = memberRepository.findMemberById(memberId)
.orElseThrow(MemberNotFoundException::new);
foundFriendIds[0] = memberRepository.findMemberIdsByIds(friendIds);

friendInviteRepository.bulkSave(owner[0].getId(), foundFriendIds[0]);
}
friendInviteRepository.bulkSave(owner[0].getId(), foundFriendIds[0]);
});

socialNotificationManager.sendFriendRequestMessages(
Expand All @@ -64,12 +59,9 @@ public void requestFriend(final Long memberId, final Long friendId) {

final FriendInvite createfriendInvite = FriendInvite.createOf(owner, friend);

transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
friendInviteRepository.save(createfriendInvite);
}
});
transactionTemplate.executeWithoutResult(status ->
friendInviteRepository.save(createfriendInvite)
);

socialNotificationManager.sendFriendReqMessage(owner.getNickname(), friendId);
}
Expand All @@ -93,31 +85,28 @@ private void validateTwoWayInvite(final Long memberId, final Long friendId) {
public void acceptFriend(final Long memberId, final Long friendId) {
validateFriendDuplicateId(memberId, friendId);

final String[] ownerNickname = new String[1];
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final List<FriendInvite> friendInvites = friendInviteRepository
.findFriendInviteWithMembersByOwnerIdAndFriendId(memberId, friendId);
final String ownerNickname = transactionTemplate.execute(status -> {
final List<FriendInvite> friendInvites = friendInviteRepository
.findFriendInviteWithMembersByOwnerIdAndFriendId(memberId, friendId);

if (friendInvites.isEmpty()) {
throw new FriendInviteNotFoundException();
}
if (friendInvites.isEmpty()) {
throw new FriendInviteNotFoundException();
}

final FriendInvite friendInvite = friendInvites.get(0);
final FriendInvite friendInvite = friendInvites.get(0);

final MemberFriend ownerRelation = friendInvite.ownerRelation();
ownerNickname[0] = ownerRelation.getOwnerNickname();
final MemberFriend ownerRelation = friendInvite.ownerRelation();

final MemberFriend friendRelation = friendInvite.friendRelation();
final MemberFriend friendRelation = friendInvite.friendRelation();

memberFriendRepository.save(ownerRelation);
memberFriendRepository.save(friendRelation);
friendInvites.forEach(friendInviteRepository::delete);
}
memberFriendRepository.save(ownerRelation);
memberFriendRepository.save(friendRelation);
friendInvites.forEach(friendInviteRepository::delete);

return ownerRelation.getOwnerNickname();
});

socialNotificationManager.sendFriendAcceptMessage(ownerNickname[0], friendId);
socialNotificationManager.sendFriendAcceptMessage(ownerNickname, friendId);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.time.ZonedDateTime;
import org.springframework.http.ResponseEntity;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberInfosResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsSliceResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;

Expand Down Expand Up @@ -38,7 +38,7 @@ public interface GroupQueryApi {
ResponseEntity<ApiSpec<GroupDetailResponse>> findGroupDetailById(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "조회할 그룹 아이디", required = true, schema = @Schema())
@Parameter(in = ParameterIn.PATH, description = "조회할 그룹 아이디", required = true)
Long groupId
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package site.timecapsulearchive.core.domain.group.api.query;

import java.time.ZonedDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
import org.springframework.http.ResponseEntity;
Expand All @@ -10,9 +11,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import site.timecapsulearchive.core.domain.group.data.dto.CompleteGroupSummaryDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailTotalDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberInfosResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsSliceResponse;
import site.timecapsulearchive.core.domain.group.service.query.GroupQueryService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
Expand All @@ -28,7 +31,7 @@ public class GroupQueryApiController implements GroupQueryApi {
private final S3PreSignedUrlManager s3PreSignedUrlManager;

@GetMapping(
value = "/{group_id}",
value = "/{group_id}/detail",
produces = {"application/json"}
)
@Override
Expand Down Expand Up @@ -57,7 +60,8 @@ public ResponseEntity<ApiSpec<GroupsSliceResponse>> findGroups(
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<GroupSummaryDto> groupsSlice = groupQueryService.findGroupsSlice(memberId, size,
final Slice<CompleteGroupSummaryDto> groupsSlice = groupQueryService.findGroupsSlice(memberId,
size,
createdAt);

return ResponseEntity.ok(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.util.function.Function;
import site.timecapsulearchive.core.domain.group.data.response.GroupSummaryResponse;

public record CompleteGroupSummaryDto(

GroupSummaryDto groupSummaryDto,
String groupOwnerProfileUrl,
Long totalGroupMemberCount

) {

public GroupSummaryResponse toResponse(final Function<String, String> preSignedUrlFunction) {
return GroupSummaryResponse.builder()
.id(groupSummaryDto.id())
.name(groupSummaryDto.groupName())
.groupOwnerProfileUrl(groupOwnerProfileUrl)
.profileUrl(preSignedUrlFunction.apply(groupSummaryDto.groupProfileUrl()))
.totalGroupMemberCount(totalGroupMemberCount)
.createdAt(groupSummaryDto.createdAt())
.isOwner(groupSummaryDto.isOwner())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static GroupDetailDto as(
Boolean isOwner,
List<GroupMemberDto> members
) {
return new GroupDetailDto(groupName, groupDescription, groupProfileUrl, createdAt, isOwner, members);
return new GroupDetailDto(groupName, groupDescription, groupProfileUrl, createdAt, isOwner,
members);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberWithRelationResponse;

public record GroupDetailTotalDto(
String groupName,
Expand Down Expand Up @@ -38,8 +38,8 @@ public static GroupDetailTotalDto as(
}

public GroupDetailResponse toResponse(final Function<String, String> singlePreSignUrlFunction) {
List<GroupMemberResponse> members = this.members.stream()
.map(GroupMemberWithRelationDto::toResponse)
List<GroupMemberWithRelationResponse> groupMemberResponses = members.stream()
.map(member -> member.toResponse(singlePreSignUrlFunction))
.toList();

return GroupDetailResponse.builder()
Expand All @@ -49,7 +49,7 @@ public GroupDetailResponse toResponse(final Function<String, String> singlePreSi
.createdAt(createdAt)
.groupCapsuleTotalCount(groupCapsuleTotalCount)
.canGroupEdit(canGroupEdit)
.members(members)
.members(groupMemberResponses)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberInfoResponse;

public record GroupMemberDto(
Long memberId,
Expand All @@ -20,4 +22,15 @@ public GroupMemberWithRelationDto toRelationDto(final List<Long> friendIds) {
.isFriend(friendIds.contains(memberId))
.build();
}

public GroupMemberInfoResponse toInfoResponse(
final Function<String, String> singlePreSignUrlFunction) {
return GroupMemberInfoResponse.builder()
.memberId(memberId)
.profileUrl(singlePreSignUrlFunction.apply(profileUrl))
.nickname(nickname)
.tag(tag)
.isOwner(isOwner)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.util.function.Function;
import lombok.Builder;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberWithRelationResponse;

@Builder
public record GroupMemberWithRelationDto(
Expand All @@ -13,10 +14,11 @@ public record GroupMemberWithRelationDto(
Boolean isFriend
) {

public GroupMemberResponse toResponse() {
return GroupMemberResponse.builder()
public GroupMemberWithRelationResponse toResponse(
final Function<String, String> singlePreSignUrlFunction) {
return GroupMemberWithRelationResponse.builder()
.memberId(memberId)
.profileUrl(profileUrl)
.profileUrl(singlePreSignUrlFunction.apply(profileUrl))
.nickname(nickname)
.tag(tag)
.isOwner(isOwner)
Expand Down
Loading

0 comments on commit 8258fc2

Please sign in to comment.