feat: create get attahcment types api.

pull/435/head
ruibaby 2019-12-20 22:38:21 +08:00
parent 6941cd4c32
commit 19862b0f79
4 changed files with 30 additions and 0 deletions

View File

@ -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<String> listMediaTypes() {
return attachmentService.listAllMediaType();
}
@GetMapping("types")
@ApiOperation("Lists all of types.")
public List<AttachmentType> listTypes() {
return attachmentService.listAllType();
}
}

View File

@ -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<Attachment, Integer>, JpaSpecificationExecutor<Attachment> {
@ -24,6 +26,14 @@ public interface AttachmentRepository extends BaseRepository<Attachment, Integer
@Query(value = "select distinct a.mediaType from Attachment a")
List<String> findAllMediaType();
/**
* Find all attachment type.
*
* @return list of type.
*/
@Query(value = "select distinct a.type from Attachment a")
List<AttachmentType> findAllType();
/**
* Counts by attachment path.
*

View File

@ -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<Attachment, Integer> {
* @return list of media type
*/
List<String> listAllMediaType();
/**
* List all type.
*
* @return list of type.
*/
List<AttachmentType> listAllType();
}

View File

@ -178,6 +178,11 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
return attachmentRepository.findAllMediaType();
}
@Override
public List<AttachmentType> listAllType() {
return attachmentRepository.findAllType();
}
@Override
public Attachment create(Attachment attachment) {
Assert.notNull(attachment, "Attachment must not be null");