mirror of https://github.com/halo-dev/halo
feat: add links sort by random (#912)
* feat: add links sort by random * feat: add links sort by randompull/915/head
parent
ccea5ed6c3
commit
4ee9e151d4
|
@ -38,6 +38,9 @@ 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 "listByDisruption":
|
||||||
|
env.setVariable("links", builder.build().wrap(linkService.listAllByDisruption()));
|
||||||
|
break;
|
||||||
case "listTeams":
|
case "listTeams":
|
||||||
env.setVariable("teams", builder.build().wrap(linkService.listTeamVos(Sort.by(DESC, "createTime"))));
|
env.setVariable("teams", builder.build().wrap(linkService.listTeamVos(Sort.by(DESC, "createTime"))));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -60,4 +60,7 @@ public interface LinkService extends CrudService<Link, Integer> {
|
||||||
* @return a list of teams.
|
* @return a list of teams.
|
||||||
*/
|
*/
|
||||||
List<String> listAllTeams();
|
List<String> listAllTeams();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
List<Link> listAllByDisruption();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,13 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
|
||||||
return linkRepository.findAllTeams();
|
return linkRepository.findAllTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Link> listAllByDisruption() {
|
||||||
|
List<Link> allLink = linkRepository.findAll();
|
||||||
|
Collections.shuffle(allLink);
|
||||||
|
return allLink;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<LinkDTO> convertTo(@Nullable List<Link> links) {
|
private List<LinkDTO> convertTo(@Nullable List<Link> links) {
|
||||||
if (CollectionUtils.isEmpty(links)) {
|
if (CollectionUtils.isEmpty(links)) {
|
||||||
|
|
Loading…
Reference in New Issue