mirror of https://github.com/halo-dev/halo
Create gallery api
parent
bade1b7358
commit
f0da4c8cfb
|
@ -0,0 +1,21 @@
|
||||||
|
package cc.ryanc.halo.model.dto;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||||
|
import cc.ryanc.halo.model.entity.Gallery;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GalleryOutputDTO implements OutputConverter<GalleryOutputDTO, Gallery> {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String thumbnail;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
}
|
|
@ -1,7 +1,13 @@
|
||||||
package cc.ryanc.halo.service;
|
package cc.ryanc.halo.service;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.GalleryOutputDTO;
|
||||||
|
import cc.ryanc.halo.model.dto.LinkOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Gallery;
|
import cc.ryanc.halo.model.entity.Gallery;
|
||||||
import cc.ryanc.halo.service.base.CrudService;
|
import cc.ryanc.halo.service.base.CrudService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gallery service.
|
* Gallery service.
|
||||||
|
@ -10,4 +16,11 @@ import cc.ryanc.halo.service.base.CrudService;
|
||||||
*/
|
*/
|
||||||
public interface GalleryService extends CrudService<Gallery, Integer> {
|
public interface GalleryService extends CrudService<Gallery, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List gallery dtos.
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return all galleries
|
||||||
|
*/
|
||||||
|
List<GalleryOutputDTO> listDtos(@NonNull Sort sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package cc.ryanc.halo.service.impl;
|
package cc.ryanc.halo.service.impl;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.GalleryOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Gallery;
|
import cc.ryanc.halo.model.entity.Gallery;
|
||||||
import cc.ryanc.halo.repository.GalleryRepository;
|
import cc.ryanc.halo.repository.GalleryRepository;
|
||||||
import cc.ryanc.halo.service.GalleryService;
|
import cc.ryanc.halo.service.GalleryService;
|
||||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GalleryService implementation class
|
* GalleryService implementation class
|
||||||
|
@ -21,4 +27,17 @@ public class GalleryServiceImpl extends AbstractCrudService<Gallery, Integer> im
|
||||||
super(galleryRepository);
|
super(galleryRepository);
|
||||||
this.galleryRepository = galleryRepository;
|
this.galleryRepository = galleryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List gallery dtos.
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return all galleries
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<GalleryOutputDTO> listDtos(Sort sort) {
|
||||||
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
||||||
|
return listAll(sort).stream().map(gallery -> (GalleryOutputDTO) new GalleryOutputDTO().convertFrom(gallery)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package cc.ryanc.halo.web.controller.admin.api;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.GalleryOutputDTO;
|
||||||
|
import cc.ryanc.halo.service.GalleryService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gallery controller
|
||||||
|
*
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/21
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/api/galleries")
|
||||||
|
public class GalleryController {
|
||||||
|
|
||||||
|
private final GalleryService galleryService;
|
||||||
|
|
||||||
|
public GalleryController(GalleryService galleryService) {
|
||||||
|
this.galleryService = galleryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all galleries
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return all of galleries
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<GalleryOutputDTO> listGalleries(@SortDefault(sort = "updateTime", direction = Sort.Direction.DESC) Sort sort) {
|
||||||
|
return galleryService.listDtos(sort);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue