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

API - v0.1.7 #156

Merged
merged 2 commits into from
Aug 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class DeleteArchivingUseCase {
private final RecycleDomainService recycleDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.ARCHIVING, identifier ={"archivingId"})
@DistributedLock(
lockType = DistributedLockType.ARCHIVING,
identifier = {"archivingId"})
public void execute(Long archivingId) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(archivingId, userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package allchive.server.api.archiving.service;


import allchive.server.api.config.security.SecurityUtil;
import allchive.server.core.annotation.UseCase;
import allchive.server.domain.common.aop.distributedLock.DistributedLock;
import allchive.server.domain.common.enums.DistributedLockType;
Expand All @@ -17,7 +16,9 @@ public class UpdateArchivingPinUseCase {
private final ArchivingDomainService archivingDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.ARCHIVING_PIN, identifier ={"archivingId", "userId"})
@DistributedLock(
lockType = DistributedLockType.ARCHIVING_PIN,
identifier = {"archivingId", "userId"})
public void execute(Long archivingId, Boolean cancel, Long userId) {
validateExecution(archivingId, userId, cancel);
archivingDomainService.updatePin(archivingId, userId, !cancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static allchive.server.core.consts.AllchiveConst.MINUS_ONE;
import static allchive.server.core.consts.AllchiveConst.PLUS_ONE;

import allchive.server.api.config.security.SecurityUtil;
import allchive.server.core.annotation.UseCase;
import allchive.server.domain.common.aop.distributedLock.DistributedLock;
import allchive.server.domain.common.enums.DistributedLockType;
Expand All @@ -27,7 +26,9 @@ public class UpdateArchivingScrapUseCase {
private final ScrapValidator scrapValidator;

@Transactional
@DistributedLock(lockType = DistributedLockType.ARCHIVING_SCRAP, identifier ={"archivingId", "userId"})
@DistributedLock(
lockType = DistributedLockType.ARCHIVING_SCRAP,
identifier = {"archivingId", "userId"})
public void execute(Long archivingId, Boolean cancel, Long userId) {
validateExecution(archivingId, userId, cancel);
User user = userAdaptor.findById(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import allchive.server.api.common.util.UrlUtil;
import allchive.server.api.config.security.SecurityUtil;
import allchive.server.core.annotation.UseCase;
import allchive.server.domain.common.aop.distributedLock.DistributedLock;
import allchive.server.domain.common.enums.DistributedLockType;
import allchive.server.core.event.Event;
import allchive.server.core.event.events.s3.S3ImageDeleteEvent;
import allchive.server.domain.common.aop.distributedLock.DistributedLock;
import allchive.server.domain.common.enums.DistributedLockType;
import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor;
import allchive.server.domain.domains.archiving.domain.Archiving;
import allchive.server.domain.domains.archiving.service.ArchivingDomainService;
import allchive.server.domain.domains.archiving.validator.ArchivingValidator;
import allchive.server.infrastructure.s3.service.S3DeleteObjectService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -26,7 +25,9 @@ public class UpdateArchivingUseCase {
private final ArchivingValidator archivingValidator;

@Transactional
@DistributedLock(lockType = DistributedLockType.ARCHIVING, identifier ={"archivingId"})
@DistributedLock(
lockType = DistributedLockType.ARCHIVING,
identifier = {"archivingId"})
public void execute(Long archivingId, UpdateArchivingRequest request) {
validateExecution(archivingId);
Archiving archiving = archivingAdaptor.findById(archivingId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public class WithdrawUserUseCase {
private final ArchivingDomainService archivingDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.USER, identifier ={"userId"})
@DistributedLock(
lockType = DistributedLockType.USER,
identifier = {"userId"})
public void execute(String appleAccessToken, String referer, Long userId) {
User user = userAdaptor.findById(userId);
// oauth쪽 탈퇴
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class DeleteBlockUseCase {
private final UserAdaptor userAdaptor;

@Transactional
@DistributedLock(lockType = DistributedLockType.BLOCK, identifier ={"fromUserId, toUserId"})
@DistributedLock(
lockType = DistributedLockType.BLOCK,
identifier = {"fromUserId, toUserId"})
public BlockResponse execute(BlockRequest request, Long fromUserId, Long toUserId) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(userId, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import allchive.server.domain.domains.content.domain.enums.ContentType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import javax.validation.constraints.Positive;
import lombok.Getter;

@Getter
Expand All @@ -13,6 +14,7 @@ public class UpdateContentRequest {
@ValidEnum(target = ContentType.class)
private ContentType contentType;

@Positive
@Schema(defaultValue = "0", description = "아카이빙 고유번호")
private Long archivingId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class DeleteContentUseCase {
private final ArchivingAsyncDomainService archivingAsyncDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.CONTENT, identifier ={"contentId"})
@DistributedLock(
lockType = DistributedLockType.CONTENT,
identifier = {"contentId"})
public void execute(Long contentId) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(contentId, userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class UpdateContentUseCase {
private final ArchivingAsyncDomainService archivingAsyncDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.CONTENT, identifier ={"contentId"})
@DistributedLock(
lockType = DistributedLockType.CONTENT,
identifier = {"contentId"})
public void execute(Long contentId, UpdateContentRequest request) {
validateExecution(contentId, request);
regenerateContentTagGroup(contentId, request.getTagIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/recycles")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package allchive.server.api.recycle.service;


import allchive.server.api.config.security.SecurityUtil;
import allchive.server.api.recycle.model.dto.request.ClearDeletedObjectRequest;
import allchive.server.core.annotation.UseCase;
import allchive.server.core.event.Event;
Expand Down Expand Up @@ -46,7 +45,9 @@ public class ClearDeletedObjectUseCase {
private final ArchivingAdaptor archivingAdaptor;

@Transactional
@DistributedLock(lockType = DistributedLockType.RECYCLE, identifier ={"userId"})
@DistributedLock(
lockType = DistributedLockType.RECYCLE,
identifier = {"userId"})
public void execute(ClearDeletedObjectRequest request, Long userId) {
validateExecution(userId, request);
List<Content> contents = contentAdaptor.findAllByArchivingIds(request.getArchivingIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static allchive.server.core.consts.AllchiveConst.PLUS_ONE;

import allchive.server.api.config.security.SecurityUtil;
import allchive.server.api.recycle.model.dto.request.RestoreDeletedObjectRequest;
import allchive.server.core.annotation.UseCase;
import allchive.server.domain.common.aop.distributedLock.DistributedLock;
Expand Down Expand Up @@ -30,7 +29,9 @@ public class RestoreDeletedObjectUseCase {
private final ContentAdaptor contentAdaptor;

@Transactional
@DistributedLock(lockType = DistributedLockType.RECYCLE, identifier ={"userId"})
@DistributedLock(
lockType = DistributedLockType.RECYCLE,
identifier = {"userId"})
public void execute(RestoreDeletedObjectRequest request, Long userId) {
validateExecution(request, userId);
archivingDomainService.restoreByIdIn(request.getArchivingIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class DeleteTagUseCase {
private final TagDomainService tagDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.TAG, identifier ={"tagId"})
@DistributedLock(
lockType = DistributedLockType.TAG,
identifier = {"tagId"})
public void execute(Long tagId) {
validateExecution(tagId);
Tag tag = tagAdaptor.findById(tagId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class UpdateTagUseCase {
private final TagDomainService tagDomainService;

@Transactional
@DistributedLock(lockType = DistributedLockType.TAG, identifier ={"tagId"})
@DistributedLock(
lockType = DistributedLockType.TAG,
identifier = {"tagId"})
public void execute(Long tagId, UpdateTagRequest request) {
validateExecution(tagId);
tagDomainService.updateTag(tagId, request.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import allchive.server.api.common.util.UrlUtil;
import allchive.server.api.config.security.SecurityUtil;
import allchive.server.api.user.model.dto.request.UpdateUserInfoRequest;
import allchive.server.core.annotation.UseCase;
import allchive.server.core.event.Event;
Expand All @@ -27,7 +26,9 @@ public class UpdateUserInfoUseCase {
private final S3DeleteObjectService s3DeleteObjectService;

@Transactional
@DistributedLock(lockType = DistributedLockType.USER, identifier ={"userId"})
@DistributedLock(
lockType = DistributedLockType.USER,
identifier = {"userId"})
public void execute(UpdateUserInfoRequest request, Long userId) {
validateExecution(userId);
eliminateOldImage(userId, request.getImgUrl());
Expand Down
4 changes: 2 additions & 2 deletions Core/src/main/java/allchive/server/core/CoreApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package allchive.server.core;


import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CoreApplication {
}
public class CoreApplication {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package allchive.server.domain;


import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DomainApplication {
}
public class DomainApplication {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import allchive.server.domain.common.enums.DistributedLockType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
Expand All @@ -38,10 +37,15 @@ public Object lock(final ProceedingJoinPoint joinPoint) throws Throwable {
private String getKey(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
String[] methodParameterNames = methodSignature.getParameterNames();
return REDISSON_LOCK_PREFIX + distributedLock.lockType().getLockName() + "-" + createDynamicKey(methodParameterNames, joinPoint.getArgs(), distributedLock.identifier());
return REDISSON_LOCK_PREFIX
+ distributedLock.lockType().getLockName()
+ "-"
+ createDynamicKey(
methodParameterNames, joinPoint.getArgs(), distributedLock.identifier());
}

private String createDynamicKey(String[] methodParameterNames, Object[] methodArgs, String[] identifiers) {
private String createDynamicKey(
String[] methodParameterNames, Object[] methodArgs, String[] identifiers) {
List<String> resultList = new ArrayList<>();
for (String identifier : identifiers) {
int indexOfKey = Arrays.asList(methodParameterNames).indexOf(identifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package allchive.server.domain.common.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;

@RequiredArgsConstructor
public class ArchivingCustomRepositoryImpl implements ArchivingCustomRepository {
Expand All @@ -31,6 +32,7 @@ public Slice<Archiving> querySliceArchivingExceptBlock(
List<Long> blockList,
Category category,
Pageable pageable) {
List<OrderSpecifier> sorting = createdAtAndscrapCntDescPriority(pageable.getSort());
List<Archiving> archivings =
queryFactory
.select(archiving)
Expand All @@ -40,7 +42,7 @@ public Slice<Archiving> querySliceArchivingExceptBlock(
publicStatusTrue(),
categoryEq(category),
deleteStatusFalse())
.orderBy(scrabListDesc(archivingIdList), scrapCntDesc(), createdAtDesc())
.orderBy(scrabListDesc(archivingIdList), sorting.get(0), sorting.get(1))
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + PLUS_ONE)
.fetch();
Expand Down Expand Up @@ -68,6 +70,7 @@ public Slice<Archiving> querySliceArchivingByIdInExceptBlockList(
List<Long> blockList,
Category category,
Pageable pageable) {
List<OrderSpecifier> sorting = createdAtAndscrapCntDescPriority(pageable.getSort());
List<Archiving> archivings =
queryFactory
.select(archiving)
Expand All @@ -78,7 +81,7 @@ public Slice<Archiving> querySliceArchivingByIdInExceptBlockList(
userIdNotIn(blockList),
categoryEq(category),
deleteStatusFalse())
.orderBy(scrapCntDesc(), createdAtDesc())
.orderBy(sorting.get(0), sorting.get(1))
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + PLUS_ONE)
.fetch();
Expand Down Expand Up @@ -212,6 +215,13 @@ private OrderSpecifier<Long> scrapCntDesc() {
return archiving.scrapCnt.desc();
}

private <T> List<OrderSpecifier> createdAtAndscrapCntDescPriority(Sort sort) {
if (sort.equals(Sort.by("popular"))) {
return List.of(archiving.scrapCnt.desc(), archiving.createdAt.desc());
}
return List.of(archiving.createdAt.desc(), archiving.scrapCnt.desc());
}

private OrderSpecifier<LocalDateTime> createdAtDesc() {
return archiving.createdAt.desc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class ArchivingAsyncDomainService {
private final ArchivingDomainService archivingDomainService;

@Async(value = "archivingContentCntTaskExecutor")
@DistributedLock(lockType = DistributedLockType.ARCHIVING, identifier ={"archivingId"})
@DistributedLock(
lockType = DistributedLockType.ARCHIVING,
identifier = {"archivingId"})
public void updateContentCnt(Long archivingId, ContentType contentType, int i) {
archivingDomainService.updateContentCnt(archivingId, contentType, i);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package allchive.server.domain.domains.archiving.service;

import static allchive.server.core.consts.AllchiveConst.MINUS_ONE;
import static allchive.server.core.consts.AllchiveConst.PLUS_ONE;

import allchive.server.core.annotation.DomainService;
import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ public List<Recycle> queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn(
.fetch();
}

private BooleanExpression userIdEq(
Long userId) {
private BooleanExpression userIdEq(Long userId) {
return recycle.userId.eq(userId);
}


private BooleanExpression archivingIdInOrContentIdIn(
List<Long> archivingIdList, List<Long> contentIdList) {
return recycle.archivingId.in(archivingIdList).or(recycle.contentId.in(contentIdList));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package allchive.server.domain;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.function.Executable;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.function.Executable;

@Slf4j
public class CalculateCurrentExecutionSupporter {
Expand All @@ -33,4 +33,3 @@ public static void execute(Executable executable, AtomicLong successCount)
latch.await();
}
}

Loading
Loading