diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4cc9fec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM eclipse-temurin:17 + +WORKDIR /app + +COPY build/libs/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "app.jar"] diff --git a/src/main/java/com/wooteco/wiki/admin/controller/AdminController.java b/src/main/java/com/wooteco/wiki/admin/controller/AdminController.java index a6226b5..07ce2be 100644 --- a/src/main/java/com/wooteco/wiki/admin/controller/AdminController.java +++ b/src/main/java/com/wooteco/wiki/admin/controller/AdminController.java @@ -4,6 +4,7 @@ import com.wooteco.wiki.global.common.ApiResponse; import com.wooteco.wiki.global.common.ApiResponseGenerator; import io.swagger.v3.oas.annotations.Operation; +import java.util.UUID; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -20,10 +21,10 @@ public AdminController(AdminService adminService) { this.adminService = adminService; } - @Operation(summary = "문서 삭제", description = "문서 ID로 문서를 삭제합니다.") - @DeleteMapping("/documents/{documentId}") - public ApiResponse> deleteDocumentByDocumentId(@PathVariable Long documentId) { - adminService.deleteDocumentByDocumentId(documentId); + @Operation(summary = "문서 삭제", description = "문서 Uuid로 문서를 삭제합니다.") + @DeleteMapping("/documents/{documentUuid}") + public ApiResponse> deleteDocumentByDocumentId(@PathVariable UUID documentUuid) { + adminService.deleteDocumentByDocumentUuid(documentUuid); return ApiResponseGenerator.success(HttpStatus.NO_CONTENT); } } diff --git a/src/main/java/com/wooteco/wiki/admin/service/AdminService.java b/src/main/java/com/wooteco/wiki/admin/service/AdminService.java index e947a3a..53d27e3 100644 --- a/src/main/java/com/wooteco/wiki/admin/service/AdminService.java +++ b/src/main/java/com/wooteco/wiki/admin/service/AdminService.java @@ -1,8 +1,7 @@ package com.wooteco.wiki.admin.service; import com.wooteco.wiki.document.service.DocumentService; -import com.wooteco.wiki.global.exception.ErrorCode; -import com.wooteco.wiki.global.exception.WikiException; +import java.util.UUID; import org.springframework.stereotype.Service; @Service @@ -14,7 +13,7 @@ public AdminService(DocumentService documentService) { this.documentService = documentService; } - public void deleteDocumentByDocumentId(Long documentId) { - documentService.deleteById(documentId); + public void deleteDocumentByDocumentUuid(UUID documentUuid) { + documentService.deleteByUuid(documentUuid); } } diff --git a/src/main/java/com/wooteco/wiki/document/repository/DocumentRepository.java b/src/main/java/com/wooteco/wiki/document/repository/DocumentRepository.java index 628297b..d1e1e1a 100644 --- a/src/main/java/com/wooteco/wiki/document/repository/DocumentRepository.java +++ b/src/main/java/com/wooteco/wiki/document/repository/DocumentRepository.java @@ -26,4 +26,6 @@ public interface DocumentRepository extends JpaRepository { Optional findIdByUuid(@Param("uuid") UUID documentUuid); List findAllByUuidIn(Set uuids); + + void deleteByUuid(UUID documentUuid); } diff --git a/src/main/java/com/wooteco/wiki/document/service/DocumentService.java b/src/main/java/com/wooteco/wiki/document/service/DocumentService.java index d42c524..7344526 100644 --- a/src/main/java/com/wooteco/wiki/document/service/DocumentService.java +++ b/src/main/java/com/wooteco/wiki/document/service/DocumentService.java @@ -106,12 +106,6 @@ public DocumentResponse put(UUID uuid, DocumentUpdateRequest request) { return mapToResponse(document); } - public void deleteById(Long id) { - documentRepository.findById(id) - .orElseThrow(() -> new WikiException(ErrorCode.DOCUMENT_NOT_FOUND)); - documentRepository.deleteById(id); - } - public void flushViews(Map views) { List documents = documentRepository.findAllByUuidIn(views.keySet()); @@ -126,6 +120,12 @@ public void flushViews(Map views) { documentRepository.saveAll(documents); } + public void deleteByUuid(UUID documentUuid) { + documentRepository.findByUuid(documentUuid) + .orElseThrow(() -> new WikiException(ErrorCode.DOCUMENT_NOT_FOUND)); + documentRepository.deleteByUuid(documentUuid); + } + private DocumentResponse mapToResponse(Document document) { long latestVersion = historyService.findLatestVersionByDocument(document); List organizationDocumentResponses = diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..773f800 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,22 @@ +server: + port: 8080 + +spring: + datasource: + url: ${DEV_DB_URL} + username: ${DEV_DB_USERNAME} + password: ${DEV_DB_PASSWORD} + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: update + properties: + hibernate: + dialect: org.hibernate.dialect.MySQL8Dialect + +cors: + allowed-origins: http://localhost:3000, https://dev.crew-wiki.site, https://dev.api.crew-wiki.site + +swagger: + server-url: https://dev.api.crew-wiki.site diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..100b669 --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,24 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb;MODE=MySQL + driver-class-name: org.h2.Driver + + jpa: + hibernate: + ddl-auto: update + open-in-view: false + properties: + hibernate: + dialect: org.hibernate.dialect.H2Dialect + + h2: + console: + enabled: true + path: /h2-console + + +cors: + allowed-origins: http://localhost:3000, https://dev.crew-wiki.site, https://dev.api.crew-wiki.site + +swagger: + server-url: https://dev.api.crew-wiki.site diff --git a/src/main/resources/application-private.yml b/src/main/resources/application-private.yml new file mode 100644 index 0000000..fa7b38c --- /dev/null +++ b/src/main/resources/application-private.yml @@ -0,0 +1,17 @@ +security: + jwt: + token: + secret-key: ${JWT_SECRET_KEY} + expire-length: ${JWT_SECRET_EXPIRE_LENGTH} + +cloud: + aws: + credentials: + access-key: ${AWS_CREDENTIALS_ACCESS_KEY} + secret-key: ${AWS_CREDENTIALS_SECRET_KEY} + s3: + bucket: ${S3_BUCKET} + region: + static: ap-northeast-2 + stack: + auto: false diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e3c312c..713047c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: include: private - active: dev # prod (배포 환경) + active: local # prod (배포 환경) diff --git a/src/test/java/com/wooteco/wiki/document/service/DocumentServiceTest.java b/src/test/java/com/wooteco/wiki/document/service/DocumentServiceTest.java index ac7502b..87cfd7c 100644 --- a/src/test/java/com/wooteco/wiki/document/service/DocumentServiceTest.java +++ b/src/test/java/com/wooteco/wiki/document/service/DocumentServiceTest.java @@ -246,8 +246,8 @@ void findAll_throwsException_byNegativeNumber() { } @Nested - @DisplayName("문서 id로 삭제 기능") - class deleteById { + @DisplayName("문서 uuid로 삭제 기능") + class deleteByUuid { @DisplayName("존재하는 문서 id일 경우 문서가 로그들과 함께 삭제된다") @Test @@ -262,7 +262,7 @@ void deleteById_success_byExistsId() { assertThat(historyRepository.findAll()).hasSize(1); // when - documentService.deleteById(documentResponse.getDocumentId()); + documentService.deleteByUuid(documentResponse.getDocumentUUID()); // after then assertThat(documentRepository.findAll()).hasSize(0); @@ -274,7 +274,7 @@ void deleteById_success_byExistsId() { void deleteById_throwsException_byNonExistsId() { // when & then WikiException ex = assertThrows(WikiException.class, - () -> documentService.deleteById(Long.MAX_VALUE)); + () -> documentService.deleteByUuid(UUID.randomUUID())); assertThat(ex.getErrorCode()).isEqualTo(DOCUMENT_NOT_FOUND); } }