From 19862b0f791eaaa3a1af1762f3ed56fd8aa52aa8 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Fri, 20 Dec 2019 22:38:21 +0800 Subject: [PATCH] feat: create get attahcment types api. --- .../app/controller/admin/api/AttachmentController.java | 7 +++++++ .../run/halo/app/repository/AttachmentRepository.java | 10 ++++++++++ .../java/run/halo/app/service/AttachmentService.java | 8 ++++++++ .../halo/app/service/impl/AttachmentServiceImpl.java | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java b/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java index 7bbb7a433..60a851006 100644 --- a/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import run.halo.app.model.dto.AttachmentDTO; import run.halo.app.model.entity.Attachment; +import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.params.AttachmentParam; import run.halo.app.model.params.AttachmentQuery; import run.halo.app.service.AttachmentService; @@ -112,4 +113,10 @@ public class AttachmentController { public List listMediaTypes() { return attachmentService.listAllMediaType(); } + + @GetMapping("types") + @ApiOperation("Lists all of types.") + public List listTypes() { + return attachmentService.listAllType(); + } } diff --git a/src/main/java/run/halo/app/repository/AttachmentRepository.java b/src/main/java/run/halo/app/repository/AttachmentRepository.java index 0adaef8f2..210676f49 100644 --- a/src/main/java/run/halo/app/repository/AttachmentRepository.java +++ b/src/main/java/run/halo/app/repository/AttachmentRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.lang.NonNull; import run.halo.app.model.entity.Attachment; +import run.halo.app.model.enums.AttachmentType; import run.halo.app.repository.base.BaseRepository; import java.util.List; @@ -12,6 +13,7 @@ import java.util.List; * Attachment repository * * @author johnniang + * @author ryanwang * @date 2019-04-03 */ public interface AttachmentRepository extends BaseRepository, JpaSpecificationExecutor { @@ -24,6 +26,14 @@ public interface AttachmentRepository extends BaseRepository findAllMediaType(); + /** + * Find all attachment type. + * + * @return list of type. + */ + @Query(value = "select distinct a.type from Attachment a") + List findAllType(); + /** * Counts by attachment path. * diff --git a/src/main/java/run/halo/app/service/AttachmentService.java b/src/main/java/run/halo/app/service/AttachmentService.java index 095abf3d3..a62a93c0e 100644 --- a/src/main/java/run/halo/app/service/AttachmentService.java +++ b/src/main/java/run/halo/app/service/AttachmentService.java @@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile; import run.halo.app.exception.FileOperationException; import run.halo.app.model.dto.AttachmentDTO; import run.halo.app.model.entity.Attachment; +import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.params.AttachmentQuery; import run.halo.app.service.base.CrudService; @@ -74,4 +75,11 @@ public interface AttachmentService extends CrudService { * @return list of media type */ List listAllMediaType(); + + /** + * List all type. + * + * @return list of type. + */ + List listAllType(); } diff --git a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java index 326b1408d..ed19dcb83 100644 --- a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java @@ -178,6 +178,11 @@ public class AttachmentServiceImpl extends AbstractCrudService listAllType() { + return attachmentRepository.findAllType(); + } + @Override public Attachment create(Attachment attachment) { Assert.notNull(attachment, "Attachment must not be null");