mirror of https://github.com/halo-dev/halo
Refactor GalleryTagDirective.
parent
2ae70e1760
commit
d1da6880f6
|
@ -20,4 +20,6 @@ public class GalleryOutputDTO implements OutputConverter<GalleryOutputDTO, Galle
|
||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
private String team;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,12 @@ public class Gallery extends BaseEntity {
|
||||||
@Column(name = "url", columnDefinition = "varchar(1023) not null")
|
@Column(name = "url", columnDefinition = "varchar(1023) not null")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gallery team name.
|
||||||
|
*/
|
||||||
|
@Column(name = "team", columnDefinition = "varchar(255) default ''")
|
||||||
|
private String team;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prePersist() {
|
public void prePersist() {
|
||||||
super.prePersist();
|
super.prePersist();
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class Link extends BaseEntity {
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link group name.
|
* Link team name.
|
||||||
*/
|
*/
|
||||||
@Column(name = "team", columnDefinition = "varchar(255) default ''")
|
@Column(name = "team", columnDefinition = "varchar(255) default ''")
|
||||||
private String team;
|
private String team;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.model.freemarker.tag;
|
||||||
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.service.GalleryService;
|
import run.halo.app.service.GalleryService;
|
||||||
|
@ -9,6 +10,8 @@ import run.halo.app.service.GalleryService;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Freemarker custom tag of gallery.
|
* Freemarker custom tag of gallery.
|
||||||
*
|
*
|
||||||
|
@ -30,12 +33,16 @@ public class GalleryTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||||
|
String team = params.get("team").toString();
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "list":
|
case "list":
|
||||||
env.setVariable("galleries", builder.build().wrap(galleryService.listAll()));
|
env.setVariable("galleries", builder.build().wrap(galleryService.listAll()));
|
||||||
break;
|
break;
|
||||||
case "listTeamVos":
|
case "listTeams":
|
||||||
env.setVariable("galleries", builder.build().wrap(null));
|
env.setVariable("teams", builder.build().wrap(galleryService.listDtos(Sort.by(DESC, "createTime"))));
|
||||||
|
break;
|
||||||
|
case "listByTeam":
|
||||||
|
env.setVariable("galleries", builder.build().wrap(galleryService.listByTeam(team, Sort.by(DESC, "createTime"))));
|
||||||
break;
|
break;
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(galleryService.count()));
|
env.setVariable("count", builder.build().wrap(galleryService.count()));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.model.freemarker.tag;
|
||||||
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.service.LinkService;
|
import run.halo.app.service.LinkService;
|
||||||
|
@ -9,6 +10,8 @@ import run.halo.app.service.LinkService;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Freemarker custom tag of link.
|
* Freemarker custom tag of link.
|
||||||
*
|
*
|
||||||
|
@ -34,8 +37,8 @@ public class LinkTagDirective implements TemplateDirectiveModel {
|
||||||
case "list":
|
case "list":
|
||||||
env.setVariable("links", builder.build().wrap(linkService.listAll()));
|
env.setVariable("links", builder.build().wrap(linkService.listAll()));
|
||||||
break;
|
break;
|
||||||
case "listTeamVos":
|
case "listTeams":
|
||||||
env.setVariable("links", builder.build().wrap(null));
|
env.setVariable("teams", builder.build().wrap(linkService.listTeamVos(Sort.by(DESC, "createTime"))));
|
||||||
break;
|
break;
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(linkService.count()));
|
env.setVariable("count", builder.build().wrap(linkService.count()));
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package run.halo.app.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
import run.halo.app.model.dto.GalleryOutputDTO;
|
||||||
|
import run.halo.app.model.dto.LinkOutputDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link team vo.
|
||||||
|
*
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
public class GalleryTeamVO {
|
||||||
|
|
||||||
|
private String team;
|
||||||
|
|
||||||
|
private List<GalleryOutputDTO> galleries;
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package run.halo.app.repository;
|
package run.halo.app.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import run.halo.app.model.entity.Gallery;
|
import run.halo.app.model.entity.Gallery;
|
||||||
import run.halo.app.repository.base.BaseRepository;
|
import run.halo.app.repository.base.BaseRepository;
|
||||||
import run.halo.app.repository.base.BaseRepository;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gallery repository.
|
* Gallery repository.
|
||||||
|
@ -10,4 +12,13 @@ import run.halo.app.repository.base.BaseRepository;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public interface GalleryRepository extends BaseRepository<Gallery, Integer> {
|
public interface GalleryRepository extends BaseRepository<Gallery, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query galleries by team
|
||||||
|
*
|
||||||
|
* @param team team
|
||||||
|
* @param sort sort
|
||||||
|
* @return list of gallery
|
||||||
|
*/
|
||||||
|
List<Gallery> findByTeam(String team, Sort sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package run.halo.app.service;
|
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.data.domain.Sort;
|
||||||
import org.springframework.lang.NonNull;
|
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 run.halo.app.service.base.CrudService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,4 +23,21 @@ public interface GalleryService extends CrudService<Gallery, Integer> {
|
||||||
* @return all galleries
|
* @return all galleries
|
||||||
*/
|
*/
|
||||||
List<GalleryOutputDTO> listDtos(@NonNull Sort sort);
|
List<GalleryOutputDTO> listDtos(@NonNull Sort sort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists gallery team vos.
|
||||||
|
*
|
||||||
|
* @param sort must not be null
|
||||||
|
* @return a list of gallery team vo
|
||||||
|
*/
|
||||||
|
List<GalleryTeamVO> listTeamVos(@NonNull Sort sort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List galleries by team.
|
||||||
|
*
|
||||||
|
* @param team team
|
||||||
|
* @param sort sort
|
||||||
|
* @return list of galleries
|
||||||
|
*/
|
||||||
|
List<GalleryOutputDTO> listByTeam(@NonNull String team, Sort sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,6 @@ public interface LinkService extends CrudService<Link, Integer> {
|
||||||
@NonNull
|
@NonNull
|
||||||
List<LinkOutputDTO> listDtos(@NonNull Sort sort);
|
List<LinkOutputDTO> listDtos(@NonNull Sort sort);
|
||||||
|
|
||||||
/**
|
|
||||||
* List link by group
|
|
||||||
*
|
|
||||||
* @return a list of link team vo
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
List<LinkTeamVO> listTeamVos();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists link team vos.
|
* Lists link team vos.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
package run.halo.app.service.impl;
|
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.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
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.repository.GalleryRepository;
|
||||||
|
import run.halo.app.service.GalleryService;
|
||||||
import run.halo.app.service.base.AbstractCrudService;
|
import run.halo.app.service.base.AbstractCrudService;
|
||||||
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,4 +45,51 @@ public class GalleryServiceImpl extends AbstractCrudService<Gallery, Integer> im
|
||||||
|
|
||||||
return listAll(sort).stream().map(gallery -> (GalleryOutputDTO) new GalleryOutputDTO().convertFrom(gallery)).collect(Collectors.toList());
|
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<GalleryTeamVO> listTeamVos(Sort sort) {
|
||||||
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
||||||
|
// List all galleries
|
||||||
|
List<GalleryOutputDTO> galleries = listDtos(sort);
|
||||||
|
|
||||||
|
// Get teams
|
||||||
|
Set<String> teams = ServiceUtils.fetchProperty(galleries, GalleryOutputDTO::getTeam);
|
||||||
|
|
||||||
|
Map<String, List<GalleryOutputDTO>> teamGalleryListMap = ServiceUtils.convertToListMap(teams, galleries, GalleryOutputDTO::getTeam);
|
||||||
|
|
||||||
|
List<GalleryTeamVO> 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<GalleryOutputDTO> listByTeam(String team, Sort sort) {
|
||||||
|
List<Gallery> galleries = galleryRepository.findByTeam(team, sort);
|
||||||
|
return galleries.stream().map(gallery -> (GalleryOutputDTO) new GalleryOutputDTO().convertFrom(gallery)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,6 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
|
||||||
return convertTo(listAll(sort));
|
return convertTo(listAll(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* List link by group
|
|
||||||
*
|
|
||||||
* @return List<LinkTeamVO>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<LinkTeamVO> listTeamVos() {
|
|
||||||
// TODO list team
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<LinkTeamVO> listTeamVos(Sort sort) {
|
public List<LinkTeamVO> listTeamVos(Sort sort) {
|
||||||
Assert.notNull(sort, "Sort info must not be null");
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
Loading…
Reference in New Issue