From d1da6880f6fe00947ad3f32c894f2f40ff51a9d0 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 22 Apr 2019 17:36:12 +0800 Subject: [PATCH] Refactor GalleryTagDirective. --- .../halo/app/model/dto/GalleryOutputDTO.java | 2 + .../run/halo/app/model/entity/Gallery.java | 6 ++ .../java/run/halo/app/model/entity/Link.java | 2 +- .../freemarker/tag/GalleryTagDirective.java | 11 +++- .../freemarker/tag/LinkTagDirective.java | 7 ++- .../run/halo/app/model/vo/GalleryTeamVO.java | 23 +++++++ .../app/repository/GalleryRepository.java | 13 +++- .../run/halo/app/service/GalleryService.java | 23 ++++++- .../run/halo/app/service/LinkService.java | 8 --- .../app/service/impl/GalleryServiceImpl.java | 60 +++++++++++++++++-- .../app/service/impl/LinkServiceImpl.java | 11 ---- 11 files changed, 133 insertions(+), 33 deletions(-) create mode 100644 src/main/java/run/halo/app/model/vo/GalleryTeamVO.java diff --git a/src/main/java/run/halo/app/model/dto/GalleryOutputDTO.java b/src/main/java/run/halo/app/model/dto/GalleryOutputDTO.java index 2ac50069f..cfa28b06f 100644 --- a/src/main/java/run/halo/app/model/dto/GalleryOutputDTO.java +++ b/src/main/java/run/halo/app/model/dto/GalleryOutputDTO.java @@ -20,4 +20,6 @@ public class GalleryOutputDTO implements OutputConverter galleries; +} diff --git a/src/main/java/run/halo/app/repository/GalleryRepository.java b/src/main/java/run/halo/app/repository/GalleryRepository.java index be4711910..7000ba945 100644 --- a/src/main/java/run/halo/app/repository/GalleryRepository.java +++ b/src/main/java/run/halo/app/repository/GalleryRepository.java @@ -1,8 +1,10 @@ package run.halo.app.repository; +import org.springframework.data.domain.Sort; import run.halo.app.model.entity.Gallery; import run.halo.app.repository.base.BaseRepository; -import run.halo.app.repository.base.BaseRepository; + +import java.util.List; /** * Gallery repository. @@ -10,4 +12,13 @@ import run.halo.app.repository.base.BaseRepository; * @author johnniang */ public interface GalleryRepository extends BaseRepository { + + /** + * Query galleries by team + * + * @param team team + * @param sort sort + * @return list of gallery + */ + List findByTeam(String team, Sort sort); } diff --git a/src/main/java/run/halo/app/service/GalleryService.java b/src/main/java/run/halo/app/service/GalleryService.java index 4cec5fe60..445b0c782 100644 --- a/src/main/java/run/halo/app/service/GalleryService.java +++ b/src/main/java/run/halo/app/service/GalleryService.java @@ -1,10 +1,10 @@ package run.halo.app.service; -import run.halo.app.model.dto.GalleryOutputDTO; -import run.halo.app.model.entity.Gallery; -import run.halo.app.service.base.CrudService; import org.springframework.data.domain.Sort; import org.springframework.lang.NonNull; +import run.halo.app.model.dto.GalleryOutputDTO; +import run.halo.app.model.entity.Gallery; +import run.halo.app.model.vo.GalleryTeamVO; import run.halo.app.service.base.CrudService; import java.util.List; @@ -23,4 +23,21 @@ public interface GalleryService extends CrudService { * @return all galleries */ List listDtos(@NonNull Sort sort); + + /** + * Lists gallery team vos. + * + * @param sort must not be null + * @return a list of gallery team vo + */ + List listTeamVos(@NonNull Sort sort); + + /** + * List galleries by team. + * + * @param team team + * @param sort sort + * @return list of galleries + */ + List listByTeam(@NonNull String team, Sort sort); } diff --git a/src/main/java/run/halo/app/service/LinkService.java b/src/main/java/run/halo/app/service/LinkService.java index 3098f314a..7b5732c73 100755 --- a/src/main/java/run/halo/app/service/LinkService.java +++ b/src/main/java/run/halo/app/service/LinkService.java @@ -27,14 +27,6 @@ public interface LinkService extends CrudService { @NonNull List listDtos(@NonNull Sort sort); - /** - * List link by group - * - * @return a list of link team vo - */ - @NonNull - List listTeamVos(); - /** * Lists link team vos. * diff --git a/src/main/java/run/halo/app/service/impl/GalleryServiceImpl.java b/src/main/java/run/halo/app/service/impl/GalleryServiceImpl.java index 4f64283a8..731f42209 100644 --- a/src/main/java/run/halo/app/service/impl/GalleryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/GalleryServiceImpl.java @@ -1,17 +1,20 @@ package run.halo.app.service.impl; -import run.halo.app.model.dto.GalleryOutputDTO; -import run.halo.app.model.entity.Gallery; -import run.halo.app.repository.GalleryRepository; -import run.halo.app.service.GalleryService; -import run.halo.app.service.base.AbstractCrudService; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import run.halo.app.model.dto.GalleryOutputDTO; +import run.halo.app.model.entity.Gallery; +import run.halo.app.model.vo.GalleryTeamVO; import run.halo.app.repository.GalleryRepository; +import run.halo.app.service.GalleryService; import run.halo.app.service.base.AbstractCrudService; +import run.halo.app.utils.ServiceUtils; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -42,4 +45,51 @@ public class GalleryServiceImpl extends AbstractCrudService im return listAll(sort).stream().map(gallery -> (GalleryOutputDTO) new GalleryOutputDTO().convertFrom(gallery)).collect(Collectors.toList()); } + + /** + * Lists gallery team vos. + * + * @param sort must not be null + * @return a list of gallery team vo + */ + @Override + public List listTeamVos(Sort sort) { + Assert.notNull(sort, "Sort info must not be null"); + + // List all galleries + List galleries = listDtos(sort); + + // Get teams + Set teams = ServiceUtils.fetchProperty(galleries, GalleryOutputDTO::getTeam); + + Map> teamGalleryListMap = ServiceUtils.convertToListMap(teams, galleries, GalleryOutputDTO::getTeam); + + List result = new LinkedList<>(); + + // Wrap gallery team vo list + teamGalleryListMap.forEach((team, galleryList) -> { + // Build gallery team vo + GalleryTeamVO galleryTeamVO = new GalleryTeamVO(); + galleryTeamVO.setTeam(team); + galleryTeamVO.setGalleries(galleryList); + + // Add it to result + result.add(galleryTeamVO); + }); + + return result; + } + + /** + * List galleries by team. + * + * @param team team + * @param sort sort + * @return list of galleries + */ + @Override + public List listByTeam(String team, Sort sort) { + List galleries = galleryRepository.findByTeam(team, sort); + return galleries.stream().map(gallery -> (GalleryOutputDTO) new GalleryOutputDTO().convertFrom(gallery)).collect(Collectors.toList()); + } } diff --git a/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java b/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java index 4efd3f9bf..157aa2c7c 100644 --- a/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java @@ -52,17 +52,6 @@ public class LinkServiceImpl extends AbstractCrudService implemen return convertTo(listAll(sort)); } - /** - * List link by group - * - * @return List - */ - @Override - public List listTeamVos() { - // TODO list team - return null; - } - @Override public List listTeamVos(Sort sort) { Assert.notNull(sort, "Sort info must not be null");