Skip to content

Commit

Permalink
完善动漫网站功能
Browse files Browse the repository at this point in the history
  • Loading branch information
YunlongChen committed Sep 13, 2024
1 parent 05c763e commit 7c509f2
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.anime.episode.dto.creator.EpisodeCreator;
import cn.chenyunlong.qing.domain.anime.episode.dto.query.EpisodeQuery;
import cn.chenyunlong.qing.domain.anime.episode.dto.request.EpisodeCreateRequest;
Expand All @@ -16,7 +15,6 @@
import cn.chenyunlong.qing.domain.anime.episode.service.IEpisodeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -96,11 +94,8 @@ public JsonResult<EpisodeResponse> findById(
return JsonResult.success(response);
}

/**
* findByPage request
*/
@PostMapping("page")
public JsonResult<PageResult<EpisodeResponse>> page(
public JsonResult<Page<EpisodeResponse>> page(
@RequestBody
PageRequestWrapper<EpisodeQueryRequest> request) {
PageRequestWrapper<EpisodeQuery> wrapper = new PageRequestWrapper<>();
Expand All @@ -109,14 +104,6 @@ public JsonResult<PageResult<EpisodeResponse>> page(
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<EpisodeVO> page = episodeService.findByPage(wrapper);
return JsonResult.success(
PageResult.of(
page.getContent().stream()
.map(EpisodeMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
return JsonResult.success(page.map(EpisodeMapper.INSTANCE::vo2CustomResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.anime.anime.service.IAnimeService;
import cn.chenyunlong.qing.domain.anime.recommend.dto.creator.RecommendCreator;
import cn.chenyunlong.qing.domain.anime.recommend.dto.query.RecommendQuery;
Expand All @@ -19,8 +18,6 @@
import cn.chenyunlong.qing.security.util.SpringSecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -87,7 +84,7 @@ public JsonResult<RecommendResponse> findById(
}

@PostMapping("page")
public JsonResult<PageResult<RecommendResponse>> page(
public JsonResult<Page<RecommendResponse>> page(
@RequestBody
PageRequestWrapper<RecommendQueryRequest> request) {
PageRequestWrapper<RecommendQuery> wrapper = new PageRequestWrapper<>();
Expand All @@ -96,15 +93,6 @@ public JsonResult<PageResult<RecommendResponse>> page(
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<RecommendDetailVO> page = recommendService.findByPage(wrapper);
List<RecommendDetailVO> recommendVOList = page.getContent();
return JsonResult.success(
PageResult.of(
recommendVOList.stream()
.map(RecommendMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
return JsonResult.success(page.map(RecommendMapper.INSTANCE::vo2CustomResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.anime.type.dto.creator.TypeCreator;
import cn.chenyunlong.qing.domain.anime.type.dto.query.TypeQuery;
import cn.chenyunlong.qing.domain.anime.type.dto.request.TypeCreateRequest;
Expand All @@ -15,7 +14,6 @@
import cn.chenyunlong.qing.domain.anime.type.mapper.TypeMapper;
import cn.chenyunlong.qing.domain.anime.type.service.ITypeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -96,7 +94,7 @@ public JsonResult<TypeResponse> findById(
* findByPage request
*/
@PostMapping("page")
public JsonResult<PageResult<TypeResponse>> page(
public JsonResult<Page<TypeResponse>> page(
@RequestBody
PageRequestWrapper<TypeQueryRequest> request) {
PageRequestWrapper<TypeQuery> wrapper = new PageRequestWrapper<>();
Expand All @@ -105,14 +103,6 @@ public JsonResult<PageResult<TypeResponse>> page(
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<TypeVO> page = typeService.findByPage(wrapper);
return JsonResult.success(
PageResult.of(
page.getContent().stream()
.map(TypeMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
return JsonResult.success(page.map(TypeMapper.INSTANCE::vo2CustomResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.auth.role.dto.creator.RoleCreator;
import cn.chenyunlong.qing.domain.auth.role.dto.query.RoleQuery;
import cn.chenyunlong.qing.domain.auth.role.dto.request.RoleCreateRequest;
Expand All @@ -15,7 +14,6 @@
import cn.chenyunlong.qing.domain.auth.role.mapper.RoleMapper;
import cn.chenyunlong.qing.domain.auth.role.service.IRoleService;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -63,7 +61,7 @@ public JsonResult<String> updateRole(
*/
@PostMapping("valid/{id}")
public JsonResult<String> validRole(
@PathVariable
@PathVariable("id")
Long id) {
roleService.validRole(id);
return JsonResult.success(CodeEnum.Success.getName());
Expand All @@ -74,7 +72,7 @@ public JsonResult<String> validRole(
*/
@PostMapping("invalid/{id}")
public JsonResult<String> invalidRole(
@PathVariable
@PathVariable("id")
Long id) {
roleService.invalidRole(id);
return JsonResult.success(CodeEnum.Success.getName());
Expand All @@ -85,7 +83,7 @@ public JsonResult<String> invalidRole(
*/
@GetMapping("findById/{id}")
public JsonResult<RoleResponse> findById(
@PathVariable
@PathVariable("id")
Long id) {
RoleVO vo = roleService.findById(id);
RoleResponse response = RoleMapper.INSTANCE.vo2CustomResponse(vo);
Expand All @@ -96,7 +94,7 @@ public JsonResult<RoleResponse> findById(
* findByPage request
*/
@PostMapping("page")
public JsonResult<PageResult<RoleResponse>> page(
public JsonResult<Page<RoleResponse>> page(
@RequestBody
PageRequestWrapper<RoleQueryRequest> request) {
PageRequestWrapper<RoleQuery> wrapper = new PageRequestWrapper<>();
Expand All @@ -105,14 +103,6 @@ public JsonResult<PageResult<RoleResponse>> page(
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<RoleVO> page = roleService.findByPage(wrapper);
return JsonResult.success(
PageResult.of(
page.getContent().stream()
.map(RoleMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
return JsonResult.success(page.map(RoleMapper.INSTANCE::vo2CustomResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.auth.connection.dto.creator.UserConnectionCreator;
import cn.chenyunlong.qing.domain.auth.connection.dto.query.UserConnectionQuery;
import cn.chenyunlong.qing.domain.auth.connection.dto.request.UserConnectionCreateRequest;
Expand All @@ -15,7 +14,6 @@
import cn.chenyunlong.qing.domain.auth.connection.mapper.UserConnectionMapper;
import cn.chenyunlong.qing.domain.auth.connection.service.IUserConnectionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand All @@ -39,7 +37,9 @@ public class UserConnectionController {
* createRequest
*/
@PostMapping
public JsonResult<Long> createUserConnection(@RequestBody UserConnectionCreateRequest request) {
public JsonResult<Long> createUserConnection(
@RequestBody
UserConnectionCreateRequest request) {
UserConnectionCreator creator = UserConnectionMapper.INSTANCE.request2Dto(request);
return JsonResult.success(userConnectionService.createUserConnection(creator));
}
Expand All @@ -60,7 +60,9 @@ public JsonResult<String> updateUserConnection(
* valid
*/
@PostMapping("valid/{id}")
public JsonResult<String> validUserConnection(@PathVariable Long id) {
public JsonResult<String> validUserConnection(
@PathVariable
Long id) {
userConnectionService.validUserConnection(id);
return JsonResult.success(CodeEnum.Success.getName());
}
Expand All @@ -69,7 +71,9 @@ public JsonResult<String> validUserConnection(@PathVariable Long id) {
* invalid
*/
@PostMapping("invalid/{id}")
public JsonResult<String> invalidUserConnection(@PathVariable Long id) {
public JsonResult<String> invalidUserConnection(
@PathVariable
Long id) {
userConnectionService.invalidUserConnection(id);
return JsonResult.success(CodeEnum.Success.getName());
}
Expand All @@ -78,17 +82,16 @@ public JsonResult<String> invalidUserConnection(@PathVariable Long id) {
* findById
*/
@GetMapping("findById/{id}")
public JsonResult<UserConnectionResponse> findById(@PathVariable Long id) {
public JsonResult<UserConnectionResponse> findById(
@PathVariable
Long id) {
UserConnectionVO vo = userConnectionService.findById(id);
UserConnectionResponse response = UserConnectionMapper.INSTANCE.vo2CustomResponse(vo);
return JsonResult.success(response);
}

/**
* findByPage request
*/
@PostMapping("page")
public JsonResult<PageResult<UserConnectionResponse>> page(
public JsonResult<Page<UserConnectionResponse>> page(
@RequestBody
PageRequestWrapper<UserConnectionQueryRequest> request) {
PageRequestWrapper<UserConnectionQuery> wrapper = new PageRequestWrapper<>();
Expand All @@ -97,14 +100,6 @@ public JsonResult<PageResult<UserConnectionResponse>> page(
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<UserConnectionVO> page = userConnectionService.findByPage(wrapper);
return JsonResult.success(
PageResult.of(
page.getContent().stream()
.map(UserConnectionMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
return JsonResult.success(page.map(UserConnectionMapper.INSTANCE::vo2CustomResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import cn.chenyunlong.common.model.AbstractBaseJpaVo;
import cn.chenyunlong.qing.domain.anime.anime.PlayStatus;
import cn.chenyunlong.qing.domain.anime.episode.dto.vo.EpisodeVO;
import cn.chenyunlong.qing.domain.anime.playlist.dto.vo.PlayListVO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
Expand Down Expand Up @@ -105,4 +107,8 @@ public class AnimeDetailVO extends AbstractBaseJpaVo {
private Integer orderNo;

private List<TagVO> tagVOList;

private List<EpisodeVO> episodeList;

private List<PlayListVO> playLists;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
import cn.chenyunlong.qing.domain.anime.attachement.repository.AttachmentRepository;
import cn.chenyunlong.qing.domain.anime.district.District;
import cn.chenyunlong.qing.domain.anime.district.repository.DistrictRepository;
import cn.chenyunlong.qing.domain.anime.episode.Episode;
import cn.chenyunlong.qing.domain.anime.episode.mapper.EpisodeMapper;
import cn.chenyunlong.qing.domain.anime.episode.repository.EpisodeRepository;
import cn.chenyunlong.qing.domain.anime.playlist.PlayList;
import cn.chenyunlong.qing.domain.anime.playlist.dto.vo.PlayListVO;
import cn.chenyunlong.qing.domain.anime.playlist.mapper.PlayListMapper;
import cn.chenyunlong.qing.domain.anime.playlist.repository.PlayListRepository;
import cn.hutool.core.collection.CollUtil;
import jakarta.validation.Validator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand All @@ -49,6 +58,8 @@ public class AnimeServiceImpl extends BaseJpaService implements IAnimeService {
private final AttachmentRepository attachmentRepository;
private final Validator validator;
private final AnimeTagRelRepository animeTagRelRepository;
private final PlayListRepository playListRepository;
private final EpisodeRepository episodeRepository;

/**
* createImpl
Expand Down Expand Up @@ -143,8 +154,22 @@ public AnimeDetailVO findDetailById(Long id) {
return animeRepository.findById(id).map(anime -> {
AnimeDetailVO animeDetailVO = AnimeMapper.INSTANCE.entityToDetailVo(anime);
List<AnimeTagRel> animeTagRelList = animeTagRelRepository.listTagByAnimeId(anime.getId());

List<Tag> tagList = tagRepository.findByIds(animeTagRelList.stream().map(AnimeTagRel::getTagId).collect(Collectors.toList()));
animeDetailVO.setTagVOList(tagList.stream().map(TagMapper.INSTANCE::entityToVo).collect(Collectors.toList()));

List<PlayList> playListList = playListRepository.listByAnime(anime.getId());

List<Episode> episodeList = episodeRepository.listByAnimeId(anime.getId());
Map<Long, List<Episode>> longListMap = episodeList.stream().collect(Collectors.groupingBy(Episode::getPlayListId));

animeDetailVO.setPlayLists(playListList.stream().map(playList -> {
PlayListVO playListVO = PlayListMapper.INSTANCE.entityToVo(playList);
List<Episode> episodes = longListMap.getOrDefault(playList.getId(), CollUtil.toList());
playListVO.setEpisodeList(episodes.stream().map(EpisodeMapper.INSTANCE::entityToVo).collect(Collectors.toList()));
return playListVO;
}).collect(Collectors.toList()));

return animeDetailVO;
}
).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class EpisodeVO extends AbstractBaseJpaVo {
)
private Long animeId;

private String playUrl;

@Schema(
title = "collectionId",
description = "播放源ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import cn.chenyunlong.jpa.support.BaseRepository;
import cn.chenyunlong.qing.domain.anime.episode.Episode;
import java.util.List;

public interface EpisodeRepository extends BaseRepository<Episode, Long> {

Integer findMaxEpisodeNumberByPlayListId(Long playListId);

List<Episode> listByAnimeId(Long animeId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cn.chenyunlong.qing.domain.anime.playlist.dto.vo;

import cn.chenyunlong.common.model.AbstractBaseJpaVo;
import cn.chenyunlong.qing.domain.anime.episode.dto.vo.EpisodeVO;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -31,4 +33,6 @@ public class PlayListVO extends AbstractBaseJpaVo {
title = "icon"
)
private String icon;

private List<EpisodeVO> episodeList;
}
Loading

0 comments on commit 7c509f2

Please sign in to comment.