Create list teams api for photo.

pull/296/head
ruibaby 2019-09-06 11:59:37 +08:00
parent 433f607634
commit e6c6624680
6 changed files with 33 additions and 3 deletions

View File

@ -23,7 +23,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Attachment controller.
*
* @author johnniang
* @date 3/21/19
* @date 2019-03-21
*/
@RestController
@RequestMapping("/api/admin/attachments")

View File

@ -22,7 +22,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Photo controller
*
* @author ryanwang
* @date : 2019/3/21
* @date : 2019-3-21
*/
@RestController
@RequestMapping("/api/admin/photos")
@ -92,4 +92,10 @@ public class PhotoController {
// Update menu in database
return new PhotoDTO().convertFrom(photoService.update(photo));
}
@GetMapping("teams")
@ApiOperation("Lists all of photo teams")
public List<String> listTeams() {
return photoService.listAllTeams();
}
}

View File

@ -12,6 +12,7 @@ import java.util.List;
* Attachment repository
*
* @author johnniang
* @date 2019-04-03
*/
public interface AttachmentRepository extends BaseRepository<Attachment, Integer>, JpaSpecificationExecutor<Attachment> {

View File

@ -2,6 +2,7 @@ package run.halo.app.repository;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import run.halo.app.model.entity.Photo;
import run.halo.app.repository.base.BaseRepository;
@ -11,6 +12,8 @@ import java.util.List;
* Photo repository.
*
* @author johnniang
* @author ryanwang
* @date 2019-04-03
*/
public interface PhotoRepository extends BaseRepository<Photo, Integer>, JpaSpecificationExecutor<Photo> {
@ -22,4 +25,12 @@ public interface PhotoRepository extends BaseRepository<Photo, Integer>, JpaSpec
* @return list of photo
*/
List<Photo> findByTeam(String team, Sort sort);
/**
* Find all photo teams.
*
* @return list of teams.
*/
@Query(value = "select distinct p.team from Photo p")
List<String> findAllTeams();
}

View File

@ -64,4 +64,11 @@ public interface PhotoService extends CrudService<Photo, Integer> {
*/
@NonNull
Photo createBy(@NonNull PhotoParam photoParam);
/**
* List all teams.
*
* @return list of teams
*/
List<String> listAllTeams();
}

View File

@ -100,9 +100,14 @@ public class PhotoServiceImpl extends AbstractCrudService<Photo, Integer> implem
return create(photoParam.convertTo());
}
@Override
public List<String> listAllTeams() {
return photoRepository.findAllTeams();
}
@NonNull
private Specification<Photo> buildSpecByQuery(@NonNull PhotoQuery photoQuery) {
Assert.notNull(photoQuery, "Attachment query must not be null");
Assert.notNull(photoQuery, "Photo query must not be null");
return (Specification<Photo>) (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new LinkedList<>();