-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
8ebf370
commit ad6c882
Showing
48 changed files
with
494 additions
and
173 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
59 changes: 59 additions & 0 deletions
59
src/main/java/project/backend/business/archive/ArchiveService.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,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); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/project/backend/business/archive/implement/ArchiveManager.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,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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/project/backend/business/archive/implement/ArchiveReader.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,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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...main/java/project/backend/business/archive/request/CreateUpdateArchiveServiceRequest.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,11 @@ | ||
package project.backend.business.archive.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CreateUpdateArchiveServiceRequest { | ||
|
||
private final String name; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/project/backend/business/archive/respone/ArchiveListResponse.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,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(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/project/backend/business/archive/respone/CreateUpdateArchiveResponse.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,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()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/project/backend/business/archive/respone/dto/ArchiveDto.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,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; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/main/java/project/backend/business/memo/implement/MemoManager.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
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 |
---|---|---|
|
@@ -9,5 +9,4 @@ public class CreateUpdateMemoServiceRequest { | |
|
||
private Long postId; | ||
private String content; | ||
|
||
} |
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
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
4 changes: 1 addition & 3 deletions
4
src/main/java/project/backend/business/post/response/CreateUpdatePostResponse.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
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
Oops, something went wrong.