Skip to content

Commit

Permalink
[Fearture] 아카이브 API 구현 (#42)
Browse files Browse the repository at this point in the history
* chore: 컨벤션 수정 (#38)

* chore: 컨벤션 수정 (#38)

* refactor: 디렉토리 구조 정리 (#38)

* deploy: workflows 업데이트 (#38)

* chore: 컨벤션 수정 (#38)

* chore: 사용하지 않는 어노테이션 삭제 및 컨벤션 수정 (#38)

* refactor: Post API 유효성 검사 추가 (#38)

* chore: 컨벤션 수정 (#38)

* refactor: 디렉토리 구조 변경 (#38)

* fix: @AllArgsConstructor 변경 (#38)

* fix: CurrentUserInfo 에만 적용되도록 수정 (#38)

* feat: 아카이브 생성 API 구현 (#38)

* refactor: util 구조 변경 (#38)

* feat: 아카이브 이름 수정 API 구현 (#38)

* feat: 아카이브 삭제 API 구현 (#38)

* chore: 컨벤션 수정 (#38)

* feat: 아카이브 조회 API 구현 (#38)

* deploy: dev 로 전환 (#38)

* feat: Swagger 추가 (#38)

* refactor: 아카이브 목록 조회 로직 변경 (#38)

* deploy: 배포시 dev 로 전환되도록 설정 (#38)
  • Loading branch information
junseoplee committed Oct 1, 2024
1 parent 8ebf370 commit ad6c882
Show file tree
Hide file tree
Showing 48 changed files with 494 additions and 173 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/someup_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# application-dev.yml
- name: Copy dev Secret
env:
Expand All @@ -55,14 +56,22 @@ jobs:
DEV_SECRET_DIR_FILE_NAME: application-jwt.yml
run: echo $DEV_SECRET | base64 --decode >> $DEV_SECRET_DIR/$DEV_SECRET_DIR_FILE_NAME

# application-ai.yml (새로운 파일 추가)
# application-ai.yml
- name: Copy ai Secret
env:
DEV_SECRET: ${{ secrets.APPLICATION_AI_YML }}
DEV_SECRET_DIR: src/main/resources
DEV_SECRET_DIR_FILE_NAME: application-ai.yml
run: echo $DEV_SECRET | base64 --decode >> $DEV_SECRET_DIR/$DEV_SECRET_DIR_FILE_NAME

# application-swagger.yml
- name: Copy swagger Secret
env:
DEV_SECRET: ${{ secrets.APPLICATION_SWAGGER_YML }}
DEV_SECRET_DIR: src/main/resources
DEV_SECRET_DIR_FILE_NAME: application-swagger.yml
run: echo $DEV_SECRET | base64 --decode >> $DEV_SECRET_DIR/$DEV_SECRET_DIR_FILE_NAME

# ./gradlew 권한 설정
- name: ./gradlew 권한 설정
run: chmod +x ./gradlew
Expand All @@ -73,6 +82,8 @@ jobs:
./gradlew clean
./gradlew compileJava
./gradlew build
env:
SPRING_PROFILES_ACTIVE: dev

# Docker Build하고 DockerHub에 Push
- name: Docker Build & Push to DockerHub
Expand Down Expand Up @@ -124,6 +135,7 @@ jobs:
sudo docker-compose pull
sudo docker-compose up -d
sudo docker image prune -f
# Security Group에서 Github IP를 삭제
- name: Remove Github IP From Security Group
run: |
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
implementation 'org.springframework.ai:spring-ai-vertex-ai-gemini-spring-boot-starter:1.0.0-SNAPSHOT'

//swagger
// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

compileOnly 'org.projectlombok:lombok'
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/project/backend/business/archive/ArchiveService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package project.backend.business.archive;

import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import project.backend.business.archive.implement.ArchiveManager;
import project.backend.business.archive.implement.ArchiveReader;
import project.backend.business.archive.request.CreateUpdateArchiveServiceRequest;
import project.backend.business.archive.respone.ArchiveListResponse;
import project.backend.business.archive.respone.CreateUpdateArchiveResponse;
import project.backend.business.user.implement.UserReader;
import project.backend.entity.archive.Archive;
import project.backend.entity.user.User;

@Slf4j
@Service
@RequiredArgsConstructor
public class ArchiveService {

private final ArchiveManager archiveManager;
private final ArchiveReader archiveReader;
private final UserReader userReader;

@Transactional(readOnly = true)
public ArchiveListResponse getArchives(Long userId) {
List<Archive> archives = archiveReader.readActivatedArchivesByUserId(userId);
return ArchiveListResponse.from(archives);
}

@Transactional
public CreateUpdateArchiveResponse createArchive(Long userId,
CreateUpdateArchiveServiceRequest request) {
User user = userReader.readUserById(userId);

Archive archive = archiveManager.createArchive(user, request.getName());
return CreateUpdateArchiveResponse.from(archive);
}

@Transactional
public CreateUpdateArchiveResponse updateArchiveName(Long userId, Long archiveId,
CreateUpdateArchiveServiceRequest request) {
User user = userReader.readUserById(userId);
Archive archive = archiveReader.readActivatedArchiveById(archiveId);
archiveManager.checkArchiveOwner(archive, user);

Archive updatedArchive = archiveManager.updateArchiveName(archive, request.getName());
return CreateUpdateArchiveResponse.from(updatedArchive);
}

@Transactional
public void deleteArchive(Long userId, Long archiveId) {
User user = userReader.readUserById(userId);
Archive archive = archiveReader.readActivatedArchiveById(archiveId);
archiveManager.checkArchiveOwner(archive, user);
archiveManager.deleteArchive(archive);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package project.backend.business.archive.implement;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import project.backend.common.error.CustomException;
import project.backend.common.error.ErrorCode;
import project.backend.entity.archive.Archive;
import project.backend.entity.user.User;
import project.backend.repository.archive.ArchiveRepository;

@Component
@RequiredArgsConstructor
public class ArchiveManager {

private final ArchiveRepository archiveRepository;

public Archive createArchive(User user, String name) {
Archive newArchive = Archive.createArchive(user, name);
return archiveRepository.save(newArchive);
}

public Archive updateArchiveName(Archive archive, String newName) {
archive.updateName(newName);
return archiveRepository.save(archive);
}

public void checkArchiveOwner(Archive archive, User user) {
if (!archive.getUser().equals(user)) {
throw new CustomException(ErrorCode.BAD_REQUEST);
}
}

public void deleteArchive(Archive archive) {
archive.setActivated(Boolean.FALSE);
archiveRepository.save(archive);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package project.backend.business.archive.implement;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import project.backend.common.error.CustomException;
import project.backend.common.error.ErrorCode;
import project.backend.entity.archive.Archive;
import project.backend.repository.archive.ArchiveRepository;

@Component
@RequiredArgsConstructor
public class ArchiveReader {

private final ArchiveRepository archiveRepository;

public Archive readActivatedArchiveById(Long archiveId) {
return archiveRepository.findByIdAndActivatedTrue(archiveId)
.orElseThrow(() -> new CustomException(ErrorCode.BAD_REQUEST));
}

public List<Archive> readActivatedArchivesByUserId(Long userId) {
return archiveRepository.findByUserIdAndActivatedTrue(userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package project.backend.business.archive.request;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CreateUpdateArchiveServiceRequest {

private final String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package project.backend.business.archive.respone;

import java.util.List;
import lombok.Builder;
import lombok.Getter;
import project.backend.business.archive.respone.dto.ArchiveDto;
import project.backend.entity.archive.Archive;

@Getter
@Builder
public class ArchiveListResponse {

private final List<ArchiveDto> archives;

public static ArchiveListResponse from(List<Archive> archiveList) {
List<ArchiveDto> archiveDtos = archiveList.stream()
.map(archive -> ArchiveDto.builder()
.id(archive.getId())
.name(archive.getName())
.build())
.toList();

return ArchiveListResponse.builder()
.archives(archiveDtos)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package project.backend.business.archive.respone;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import project.backend.entity.archive.Archive;

@Getter
@RequiredArgsConstructor
public class CreateUpdateArchiveResponse {

private final Long archiveId;

public static CreateUpdateArchiveResponse from(Archive archive) {
return new CreateUpdateArchiveResponse(archive.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package project.backend.business.archive.respone.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ArchiveDto {

private final Long id;
private final String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
@AllArgsConstructor
public class TokenServiceRequest {
private String accessToken;
private String refreshToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ public void deleteMemo(Long userId, Long postId) {
Post post = postReader.readActivatedPublishedPost(userId, postId);
memoManager.deleteMemo(post);
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package project.backend.business.memo.implement;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import project.backend.entity.post.Post;
import project.backend.repository.post.PostRepository;

@Slf4j
@Component
@AllArgsConstructor
@RequiredArgsConstructor
public class MemoManager {

private final PostRepository postRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class CreateUpdateMemoServiceRequest {

private Long postId;
private String content;

}
6 changes: 3 additions & 3 deletions src/main/java/project/backend/business/post/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import project.backend.business.post.request.PostDetailServiceRequest;
import project.backend.business.post.request.PostListServiceRequest;
import project.backend.business.post.response.CreateUpdatePostResponse;
import project.backend.business.post.response.PostDetailDto;
import project.backend.business.post.response.dto.PostDetailDto;
import project.backend.business.post.response.PostDetailResponse;
import project.backend.business.post.response.PostListDto;
import project.backend.business.post.response.dto.PostListDto;
import project.backend.business.post.response.PostListResponse;
import project.backend.business.user.implement.UserReader;
import project.backend.common.error.CustomException;
Expand All @@ -40,7 +40,7 @@ public class PostService {
private final SummaryAIManager summaryAIManager;

@Transactional(readOnly = true)
public PostListResponse getPostList(Long userId, PostListServiceRequest postListServiceRequest) {
public PostListResponse getPosts(Long userId, PostListServiceRequest postListServiceRequest) {
Specification<Post> spec =
Specification.where(PostSpecification.getUser(userId))
.and(PostSpecification.getPublished())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package project.backend.business.post.implement;

import jakarta.transaction.Transactional;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import project.backend.business.common.DateTimeManager;
import project.backend.business.post.response.PostDetailDto;
import project.backend.business.post.response.dto.PostDetailDto;
import project.backend.business.post.util.DateTimeManager;
import project.backend.business.tag.implement.TagManager;
import project.backend.entity.post.Post;
import project.backend.entity.post.PostStatus;
Expand Down Expand Up @@ -49,7 +48,6 @@ public void deletePost(Post post) {
postRepository.save(post);
}

@Transactional
public void updateSummary(Post post, String url, String summary) {
post.setContent(summary);
post.setUrl(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import project.backend.business.common.DateTimeManager;
import project.backend.business.post.request.PostDetailServiceRequest;
import project.backend.business.post.response.PostDetailDto;
import project.backend.business.post.response.PostListDto;
import project.backend.business.post.response.dto.PostDetailDto;
import project.backend.business.post.response.dto.PostListDto;
import project.backend.business.post.util.DateTimeManager;
import project.backend.business.tag.implement.TagReader;
import project.backend.common.error.CustomException;
import project.backend.common.error.ErrorCode;
Expand All @@ -20,7 +20,7 @@

@Slf4j
@Component
@AllArgsConstructor
@RequiredArgsConstructor
public class PostReader {

private final PostRepository postRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package project.backend.business.post.response;

import lombok.Builder;
import lombok.Getter;

@Getter
public class CreateUpdatePostResponse {

Long postId;
private final Long postId;

@Builder
public CreateUpdatePostResponse(Long postId) {
this.postId = postId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package project.backend.business.post.response;

import java.util.List;
import lombok.Builder;
import lombok.Getter;

import project.backend.business.post.response.dto.PostDetailDto;

@Getter
public class PostDetailResponse {
Expand All @@ -16,7 +15,6 @@ public class PostDetailResponse {
private final String memoContent;
private final String memoCreatedAt;

@Builder
public PostDetailResponse(PostDetailDto postDetailDto) {
this.title = postDetailDto.getTitle();
this.content = postDetailDto.getContent();
Expand Down
Loading

0 comments on commit ad6c882

Please sign in to comment.