-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fce88b5
commit 42efafb
Showing
8 changed files
with
206 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ore/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupReadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import java.time.ZonedDateTime; | ||
import org.springframework.data.domain.Slice; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; | ||
import site.timecapsulearchive.core.domain.group.entity.Group; | ||
|
||
public interface GroupReadService { | ||
|
||
Group findGroupById(final Long groupId); | ||
|
||
Slice<GroupSummaryDto> findGroupsSlice( | ||
final Long memberId, | ||
final int size, | ||
final ZonedDateTime createdAt | ||
); | ||
|
||
GroupDetailDto findGroupDetailByGroupId(final Long memberId, final Long groupId); | ||
} |
53 changes: 53 additions & 0 deletions
53
...src/main/java/site/timecapsulearchive/core/domain/group/service/GroupReadServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import java.time.ZonedDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; | ||
import site.timecapsulearchive.core.domain.group.entity.Group; | ||
import site.timecapsulearchive.core.domain.group.exception.GroupNotFoundException; | ||
import site.timecapsulearchive.core.domain.group.repository.GroupQueryRepository; | ||
import site.timecapsulearchive.core.domain.group.repository.GroupRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GroupReadServiceImpl implements GroupReadService { | ||
|
||
private final GroupQueryRepository groupQueryRepository; | ||
private final GroupRepository groupRepository; | ||
|
||
|
||
@Transactional(readOnly = true) | ||
public Group findGroupById(final Long groupId) { | ||
return groupRepository.findGroupById(groupId) | ||
.orElseThrow(GroupNotFoundException::new); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Slice<GroupSummaryDto> findGroupsSlice( | ||
final Long memberId, | ||
final int size, | ||
final ZonedDateTime createdAt | ||
) { | ||
return groupQueryRepository.findGroupsSlice(memberId, size, createdAt); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public GroupDetailDto findGroupDetailByGroupId(final Long memberId, final Long groupId) { | ||
final GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupId(groupId) | ||
.orElseThrow(GroupNotFoundException::new); | ||
|
||
final boolean isGroupMember = groupDetailDto.members() | ||
.stream() | ||
.anyMatch(m -> m.memberId().equals(memberId)); | ||
|
||
if (!isGroupMember) { | ||
throw new GroupNotFoundException(); | ||
} | ||
|
||
return groupDetailDto; | ||
} | ||
} |
84 changes: 1 addition & 83 deletions
84
...nd/core/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,5 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import java.time.ZonedDateTime; | ||
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.group.data.dto.GroupCreateDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; | ||
import site.timecapsulearchive.core.domain.group.entity.Group; | ||
import site.timecapsulearchive.core.domain.group.entity.MemberGroup; | ||
import site.timecapsulearchive.core.domain.group.exception.GroupNotFoundException; | ||
import site.timecapsulearchive.core.domain.group.repository.GroupQueryRepository; | ||
import site.timecapsulearchive.core.domain.group.repository.GroupRepository; | ||
import site.timecapsulearchive.core.domain.group.repository.MemberGroupRepository; | ||
import site.timecapsulearchive.core.domain.member.entity.Member; | ||
import site.timecapsulearchive.core.domain.member.exception.MemberNotFoundException; | ||
import site.timecapsulearchive.core.domain.member.repository.MemberRepository; | ||
import site.timecapsulearchive.core.infra.queue.manager.SocialNotificationManager; | ||
public interface GroupService extends GroupReadService, GroupWriteService { | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GroupService { | ||
|
||
private final GroupRepository groupRepository; | ||
private final MemberRepository memberRepository; | ||
private final MemberGroupRepository memberGroupRepository; | ||
private final TransactionTemplate transactionTemplate; | ||
private final SocialNotificationManager socialNotificationManager; | ||
private final GroupQueryRepository groupQueryRepository; | ||
|
||
public void createGroup(final Long memberId, final GroupCreateDto dto) { | ||
final Member member = memberRepository.findMemberById(memberId) | ||
.orElseThrow(MemberNotFoundException::new); | ||
|
||
final Group group = dto.toEntity(); | ||
|
||
final MemberGroup memberGroup = MemberGroup.createGroupOwner(member, group); | ||
|
||
transactionTemplate.execute(new TransactionCallbackWithoutResult() { | ||
@Override | ||
protected void doInTransactionWithoutResult(TransactionStatus status) { | ||
groupRepository.save(group); | ||
memberGroupRepository.save(memberGroup); | ||
} | ||
}); | ||
|
||
socialNotificationManager.sendGroupInviteMessage(member.getNickname(), | ||
dto.groupProfileUrl(), dto.targetIds()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Group findGroupById(Long groupId) { | ||
return groupRepository.findGroupById(groupId) | ||
.orElseThrow(GroupNotFoundException::new); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Slice<GroupSummaryDto> findGroupsSlice( | ||
final Long memberId, | ||
final int size, | ||
final ZonedDateTime createdAt | ||
) { | ||
return groupQueryRepository.findGroupsSlice(memberId, size, createdAt); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public GroupDetailDto findGroupDetailByGroupId(final Long memberId, final Long groupId) { | ||
final GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupId(groupId) | ||
.orElseThrow(GroupNotFoundException::new); | ||
|
||
final boolean isGroupMember = groupDetailDto.members() | ||
.stream() | ||
.anyMatch(m -> m.memberId().equals(memberId)); | ||
|
||
if (!isGroupMember) { | ||
throw new GroupNotFoundException(); | ||
} | ||
|
||
return groupDetailDto; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ore/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import java.time.ZonedDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.stereotype.Service; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; | ||
import site.timecapsulearchive.core.domain.group.entity.Group; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GroupServiceImpl implements GroupService { | ||
|
||
private final GroupReadService groupReadService; | ||
private final GroupWriteService groupWriteService; | ||
|
||
@Override | ||
public Group findGroupById(final Long groupId) { | ||
return groupReadService.findGroupById(groupId); | ||
} | ||
|
||
@Override | ||
public Slice<GroupSummaryDto> findGroupsSlice( | ||
final Long memberId, | ||
final int size, | ||
final ZonedDateTime createdAt | ||
) { | ||
return groupReadService.findGroupsSlice(memberId, size, createdAt); | ||
} | ||
|
||
@Override | ||
public GroupDetailDto findGroupDetailByGroupId(final Long memberId, final Long groupId) { | ||
return groupReadService.findGroupDetailByGroupId(memberId, groupId); | ||
} | ||
|
||
@Override | ||
public void createGroup(final Long memberId, final GroupCreateDto dto) { | ||
groupWriteService.createGroup(memberId, dto); | ||
} | ||
|
||
@Override | ||
public void inviteGroup(final Long memberId, final Long groupId, final Long targetId) { | ||
groupWriteService.inviteGroup(memberId, groupId, targetId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...re/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupWriteService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto; | ||
|
||
public interface GroupWriteService { | ||
|
||
void createGroup(final Long memberId, final GroupCreateDto dto); | ||
|
||
void inviteGroup(final Long memberId, final Long groupId, final Long targetId); | ||
} |
53 changes: 53 additions & 0 deletions
53
...rc/main/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package site.timecapsulearchive.core.domain.group.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.TransactionStatus; | ||
import org.springframework.transaction.support.TransactionCallbackWithoutResult; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto; | ||
import site.timecapsulearchive.core.domain.group.entity.Group; | ||
import site.timecapsulearchive.core.domain.group.entity.MemberGroup; | ||
import site.timecapsulearchive.core.domain.group.repository.GroupRepository; | ||
import site.timecapsulearchive.core.domain.group.repository.MemberGroupRepository; | ||
import site.timecapsulearchive.core.domain.member.entity.Member; | ||
import site.timecapsulearchive.core.domain.member.exception.MemberNotFoundException; | ||
import site.timecapsulearchive.core.domain.member.repository.MemberRepository; | ||
import site.timecapsulearchive.core.infra.queue.manager.SocialNotificationManager; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GroupWriteServiceImpl implements GroupWriteService { | ||
|
||
private final GroupRepository groupRepository; | ||
private final MemberRepository memberRepository; | ||
private final MemberGroupRepository memberGroupRepository; | ||
private final TransactionTemplate transactionTemplate; | ||
private final SocialNotificationManager socialNotificationManager; | ||
|
||
public void createGroup(final Long memberId, final GroupCreateDto dto) { | ||
final Member member = memberRepository.findMemberById(memberId) | ||
.orElseThrow(MemberNotFoundException::new); | ||
|
||
final Group group = dto.toEntity(); | ||
|
||
final MemberGroup memberGroup = MemberGroup.createGroupOwner(member, group); | ||
|
||
transactionTemplate.execute(new TransactionCallbackWithoutResult() { | ||
@Override | ||
protected void doInTransactionWithoutResult(TransactionStatus status) { | ||
groupRepository.save(group); | ||
memberGroupRepository.save(memberGroup); | ||
} | ||
}); | ||
|
||
socialNotificationManager.sendGroupInviteMessage(member.getNickname(), | ||
dto.groupProfileUrl(), dto.targetIds()); | ||
} | ||
|
||
@Override | ||
public void inviteGroup(Long memberId, Long groupId, Long targetId) { | ||
|
||
} | ||
|
||
} |