Skip to content

Commit

Permalink
API - v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdtkdgns committed May 14, 2024
1 parent d0b7d24 commit dfb27a2
Show file tree
Hide file tree
Showing 66 changed files with 526 additions and 184 deletions.
2 changes: 2 additions & 0 deletions Api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'

// swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.6.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import allchive.server.api.common.slice.SliceResponse;
import allchive.server.api.config.security.SecurityUtil;
import allchive.server.domain.domains.archiving.domain.enums.Category;
import allchive.server.domain.domains.content.domain.enums.ContentType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
Expand Down Expand Up @@ -67,7 +69,9 @@ public void deleteArchiving(@PathVariable("archivingId") Long archivingId) {

@Operation(
summary = "주제별 아카이빙 리스트를 가져옵니다.",
description = "sort parameter는 입력하지 말아주세요! sorting : 스크랩 여부 -> 스크랩 수 -> 생성일자")
description =
"sort parameter는 입력하지 말아주세요! sorting : 스크랩 여부 -> 스크랩 수 -> 생성일자"
+ "\nsort에 popular쓰면 최신순 안쓰면 인기순 입니다!")
@GetMapping()
public SliceResponse<ArchivingResponse> getArchiving(
@RequestParam("category") Category category,
Expand Down Expand Up @@ -111,8 +115,10 @@ public ArchivingsResponse getPopularArchiving() {
@GetMapping(value = "/{archivingId}/contents")
public ArchivingContentsResponse getArchivingContents(
@PathVariable("archivingId") Long archivingId,
@ParameterObject @PageableDefault(size = 10) Pageable pageable) {
return getArchivingContentsUseCase.execute(archivingId, pageable);
@ParameterObject @PageableDefault(size = 10) Pageable pageable,
@RequestParam(value = "type", required = false) ContentType contentType,
@RequestParam(value = "tagIds", required = false) List<Long> tagIds) {
return getArchivingContentsUseCase.execute(archivingId, pageable, contentType, tagIds);
}

@Operation(summary = "아카이빙을 스크랩합니다.", description = "스크랩 취소면 cancel에 true 값 보내주세요")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import allchive.server.domain.domains.recycle.domain.Recycle;
import allchive.server.domain.domains.recycle.service.RecycleDomainService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -21,7 +20,6 @@ public class DeleteArchivingUseCase {
private final RecycleMapper recycleMapper;
private final RecycleDomainService recycleDomainService;

@Transactional
@DistributedLock(
lockType = DistributedLockType.ARCHIVING,
identifier = {"archivingId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
import allchive.server.domain.domains.content.adaptor.ContentTagGroupAdaptor;
import allchive.server.domain.domains.content.domain.Content;
import allchive.server.domain.domains.content.domain.ContentTagGroup;
import allchive.server.domain.domains.content.domain.enums.ContentType;
import allchive.server.domain.domains.user.adaptor.ScrapAdaptor;
import allchive.server.domain.domains.user.adaptor.UserAdaptor;
import allchive.server.domain.domains.user.domain.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@UseCase
@RequiredArgsConstructor
public class GetArchivingContentsUseCase {
Expand All @@ -35,13 +38,14 @@ public class GetArchivingContentsUseCase {
private final ScrapAdaptor scrapAdaptor;

@Transactional(readOnly = true)
public ArchivingContentsResponse execute(Long archivingId, Pageable pageable) {
public ArchivingContentsResponse execute(
Long archivingId, Pageable pageable, ContentType contentType, List<Long> tagIds) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(archivingId, userId);
Archiving archiving = archivingAdaptor.findById(archivingId);
User owner = userAdaptor.findById(archiving.getUserId());
Slice<ContentResponse> contentResponseSlice =
getContentResponseSlice(archivingId, pageable);
getContentResponseSlice(archivingId, pageable, contentType, tagIds);
return ArchivingContentsResponse.of(
SliceResponse.of(contentResponseSlice),
archiving,
Expand All @@ -55,9 +59,18 @@ private void validateExecution(Long archivingId, Long userId) {
archivingValidator.validateNotDeleteExceptUser(archivingId, userId);
}

private Slice<ContentResponse> getContentResponseSlice(Long archivingId, Pageable pageable) {
private Slice<ContentResponse> getContentResponseSlice(
Long archivingId, Pageable pageable, ContentType contentType, List<Long> tagIds) {
List<Long> contentIds = null;
if (tagIds != null) {
contentIds =
contentTagGroupAdaptor.queryContentTagGroupByTagIdInWithContent(tagIds).stream()
.map(contentTagGroup -> contentTagGroup.getContent().getId())
.toList();
}
Slice<Content> contentList =
contentAdaptor.querySliceContentByArchivingId(archivingId, pageable);
contentAdaptor.querySliceContentByArchivingIdAndContentTypeAndIdIn(
archivingId, pageable, contentType, contentIds);
List<ContentTagGroup> contentTagGroupList =
contentTagGroupAdaptor.queryContentTagGroupByContentIn(contentList.getContent());
return contentList.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import allchive.server.domain.domains.archiving.service.ArchivingDomainService;
import allchive.server.domain.domains.archiving.validator.ArchivingValidator;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
public class UpdateArchivingPinUseCase {
private final ArchivingValidator archivingValidator;
private final ArchivingDomainService archivingDomainService;

@Transactional
@DistributedLock(
lockType = DistributedLockType.ARCHIVING_PIN,
identifier = {"archivingId", "userId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import allchive.server.domain.domains.user.service.ScrapDomainService;
import allchive.server.domain.domains.user.validator.ScrapValidator;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -25,7 +24,6 @@ public class UpdateArchivingScrapUseCase {
private final ArchivingDomainService archivingDomainService;
private final ScrapValidator scrapValidator;

@Transactional
@DistributedLock(
lockType = DistributedLockType.ARCHIVING_SCRAP,
identifier = {"archivingId", "userId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import allchive.server.api.config.security.SecurityUtil;
import allchive.server.core.annotation.UseCase;
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.event.S3ImageDeleteEvent;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -24,7 +23,6 @@ public class UpdateArchivingUseCase {
private final ArchivingAdaptor archivingAdaptor;
private final ArchivingValidator archivingValidator;

@Transactional
@DistributedLock(
lockType = DistributedLockType.ARCHIVING,
identifier = {"archivingId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import allchive.server.api.auth.service.TokenRefreshUseCase;
import allchive.server.api.auth.service.WithdrawUserUseCase;
import allchive.server.api.config.security.SecurityUtil;
import allchive.server.domain.domains.quitReason.domain.enums.Reason;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,9 +27,10 @@ public class AuthController {
@DeleteMapping("/withdrawal")
public void withDrawUser(
@RequestParam(required = false, name = "appleCode", value = "") String appleCode,
@RequestHeader(value = "referer", required = false) String referer) {
@RequestHeader(value = "referer", required = false) String referer,
@RequestParam("quitReason") Reason reason) {
Long userId = SecurityUtil.getCurrentUserId();
withdrawUserUseCase.execute(appleCode, referer, userId);
withdrawUserUseCase.execute(appleCode, referer, userId, reason);
}

@Operation(summary = "회원탈퇴를 합니다. (개발용)", deprecated = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import allchive.server.domain.domains.content.service.ContentDomainService;
import allchive.server.domain.domains.content.service.ContentTagGroupDomainService;
import allchive.server.domain.domains.content.service.TagDomainService;
import allchive.server.domain.domains.quitReason.domain.QuitReason;
import allchive.server.domain.domains.quitReason.domain.enums.Reason;
import allchive.server.domain.domains.quitReason.service.QuitReasonDomainService;
import allchive.server.domain.domains.recycle.service.RecycleDomainService;
import allchive.server.domain.domains.report.service.ReportDomainService;
import allchive.server.domain.domains.search.service.LatestSearchDomainService;
Expand Down Expand Up @@ -47,13 +50,14 @@ public class WithdrawUserUseCase {
private final ReportDomainService reportDomainService;
private final UserDomainService userDomainService;
private final ArchivingDomainService archivingDomainService;
private final QuitReasonDomainService quitReasonDomainService;

@Transactional
@DistributedLock(
lockType = DistributedLockType.USER,
identifier = {"userId"})
public void execute(String appleAccessToken, String referer, Long userId) {
public void execute(String appleAccessToken, String referer, Long userId, Reason reason) {
User user = userAdaptor.findById(userId);
quitReasonDomainService.save(QuitReason.of(userId, reason));
// oauth쪽 탈퇴
withdrawOauth(user.getOauthInfo().getProvider(), appleAccessToken, user, referer);
// 우리쪽 탈퇴
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import allchive.server.domain.domains.user.adaptor.UserAdaptor;
import allchive.server.domain.domains.user.validator.UserValidator;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -22,7 +21,6 @@ public class DeleteBlockUseCase {
private final BlockDomainService blockDomainService;
private final UserAdaptor userAdaptor;

@Transactional
@DistributedLock(
lockType = DistributedLockType.BLOCK,
identifier = {"fromUserId", "toUserId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public void errorExample(

@Operation(hidden = true)
@GetMapping(value = "health")
public void errorExample() {}
public void healthCheck() {}
}
35 changes: 0 additions & 35 deletions Api/src/main/java/allchive/server/api/common/aop/TestTimerAop.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package allchive.server.api.common.filter;


import com.amazonaws.util.IOUtils;
import java.io.*;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.tomcat.util.http.fileupload.IOUtils;

public class MultiReadInputStream extends HttpServletRequestWrapper {
private ByteArrayOutputStream cachedBytes;
Expand Down

This file was deleted.

30 changes: 30 additions & 0 deletions Api/src/main/java/allchive/server/api/common/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package allchive.server.api.common.util;


import allchive.server.core.error.exception.EmptyParamValueException;
import org.springframework.stereotype.Component;

import static allchive.server.core.consts.AllchiveConst.HANGUL_BASE;
import static allchive.server.core.consts.AllchiveConst.KOREAN_ALPHA;

@Component
public class StringUtil {
public static void checkEmptyString(String param) {
if (param.equals("")) {
throw EmptyParamValueException.EXCEPTION;
}
}

public static char extractKoreanInitial(char ch) {
int index = (ch - HANGUL_BASE) / (21 * 28); // 21개의 중성, 28개의 종성
return KOREAN_ALPHA[index];
}

public static boolean isEnglish(char ch) {
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
}

public static boolean isKorean(char ch) {
return (ch >= '\uAC00' && ch <= '\uD7A3');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import allchive.server.core.error.ErrorResponse;
import allchive.server.core.error.GlobalErrorCode;
import allchive.server.core.event.Event;
import allchive.server.core.event.events.slack.SlackErrorEvent;
import allchive.server.infrastructure.slack.event.SlackErrorEvent;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import allchive.server.domain.domains.recycle.domain.enums.RecycleType;
import allchive.server.domain.domains.recycle.service.RecycleDomainService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -28,7 +27,6 @@ public class DeleteContentUseCase {
private final ContentAdaptor contentAdaptor;
private final ArchivingAsyncDomainService archivingAsyncDomainService;

@Transactional
@DistributedLock(
lockType = DistributedLockType.CONTENT,
identifier = {"contentId"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import allchive.server.api.content.model.mapper.ContentMapper;
import allchive.server.core.annotation.UseCase;
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.service.ArchivingAsyncDomainService;
Expand All @@ -25,9 +24,9 @@
import allchive.server.domain.domains.content.service.TagAsyncDomainService;
import allchive.server.domain.domains.content.validator.ContentValidator;
import allchive.server.domain.domains.content.validator.TagValidator;
import allchive.server.infrastructure.s3.event.S3ImageDeleteEvent;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@RequiredArgsConstructor
Expand All @@ -43,7 +42,6 @@ public class UpdateContentUseCase {
private final ContentTagGroupAdaptor contentTagGroupAdaptor;
private final ArchivingAsyncDomainService archivingAsyncDomainService;

@Transactional
@DistributedLock(
lockType = DistributedLockType.CONTENT,
identifier = {"contentId"})
Expand Down
Loading

0 comments on commit dfb27a2

Please sign in to comment.