mirror of https://github.com/halo-dev/halo
Support attachment query by media type.
parent
bd9dd69674
commit
e13c617c81
|
@ -15,4 +15,6 @@ public class AttachmentQuery {
|
||||||
* Keyword.
|
* Keyword.
|
||||||
*/
|
*/
|
||||||
private String keyword;
|
private String keyword;
|
||||||
|
|
||||||
|
private String mediaType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
package run.halo.app.repository;
|
package run.halo.app.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import run.halo.app.model.entity.Attachment;
|
import run.halo.app.model.entity.Attachment;
|
||||||
import run.halo.app.repository.base.BaseRepository;
|
import run.halo.app.repository.base.BaseRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attachment repository
|
* Attachment repository
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public interface AttachmentRepository extends BaseRepository<Attachment, Integer>, JpaSpecificationExecutor<Attachment> {
|
public interface AttachmentRepository extends BaseRepository<Attachment, Integer>, JpaSpecificationExecutor<Attachment> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all attachment media type.
|
||||||
|
* @return list of media type.
|
||||||
|
*/
|
||||||
|
@Query(value = "select distinct a.mediaType from Attachment a")
|
||||||
|
List<String> findAllMediaType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package run.halo.app.repository;
|
package run.halo.app.repository;
|
||||||
|
|
||||||
import run.halo.app.model.entity.Post;
|
|
||||||
import run.halo.app.repository.base.BasePostRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import run.halo.app.model.entity.Post;
|
||||||
import run.halo.app.repository.base.BasePostRepository;
|
import run.halo.app.repository.base.BasePostRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ import run.halo.app.model.entity.Attachment;
|
||||||
import run.halo.app.model.params.AttachmentQuery;
|
import run.halo.app.model.params.AttachmentQuery;
|
||||||
import run.halo.app.service.base.CrudService;
|
import run.halo.app.service.base.CrudService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attachment service.
|
* Attachment service.
|
||||||
|
@ -54,4 +56,10 @@ public interface AttachmentService extends CrudService<Attachment, Integer> {
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
AttachmentOutputDTO convertToDto(@NonNull Attachment attachment);
|
AttachmentOutputDTO convertToDto(@NonNull Attachment attachment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all media type.
|
||||||
|
* @return list of media type
|
||||||
|
*/
|
||||||
|
List<String> listAllMediaType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,10 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
||||||
return (Specification<Attachment>) (root, query, criteriaBuilder) -> {
|
return (Specification<Attachment>) (root, query, criteriaBuilder) -> {
|
||||||
List<Predicate> predicates = new LinkedList<>();
|
List<Predicate> predicates = new LinkedList<>();
|
||||||
|
|
||||||
|
if (attachmentQuery.getMediaType() != null) {
|
||||||
|
predicates.add(criteriaBuilder.equal(root.get("mediaType"), attachmentQuery.getMediaType()));
|
||||||
|
}
|
||||||
|
|
||||||
if (attachmentQuery.getKeyword() != null) {
|
if (attachmentQuery.getKeyword() != null) {
|
||||||
|
|
||||||
String likeCondition = String.format("%%%s%%", StringUtils.strip(attachmentQuery.getKeyword()));
|
String likeCondition = String.format("%%%s%%", StringUtils.strip(attachmentQuery.getKeyword()));
|
||||||
|
@ -151,6 +155,11 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
||||||
return attachmentOutputDTO;
|
return attachmentOutputDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> listAllMediaType() {
|
||||||
|
return attachmentRepository.findAllMediaType();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get attachment type from options.
|
* Get attachment type from options.
|
||||||
*
|
*
|
||||||
|
|
|
@ -100,4 +100,10 @@ public class AttachmentController {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("mediaTypes")
|
||||||
|
@ApiOperation("List all of media types")
|
||||||
|
public List<String> mediaTypes(){
|
||||||
|
return attachmentService.listAllMediaType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue