Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ CREATE TABLE `fi_tour` (
`longitude` varchar(40) NOT NULL COMMENT '经度',
`latitude` varchar(40) NOT NULL COMMENT '纬度',
`location_id` varchar(255) NOT NULL COMMENT '景点id',

`drama_id` varchar(255) NOT NULL COMMENT '关联影视id',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public interface UserConstants {

String DEFAULT_USER = "https://cetide-1325039295.cos.ap-chengdu.myqcloud.com/codeforge/course/Docker/default-avatar.png";

String DEFAULT_THUMB_USER = "暂未设置";

String USER_LANGUAGE_DEFAULT = "zh-CN";

Boolean USER_NOTIFICATIONS_DEFAULT = true;
Expand Down
56 changes: 45 additions & 11 deletions src/main/java/cn/cxdproject/coder/controller/ArticleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import cn.cxdproject.coder.model.dto.CreateArticleDTO;
import cn.cxdproject.coder.model.dto.UpdateArticleDTO;
import cn.cxdproject.coder.model.entity.Article;
import cn.cxdproject.coder.model.entity.Banner;
import cn.cxdproject.coder.model.entity.User;
import cn.cxdproject.coder.model.vo.ArticleVO;
import cn.cxdproject.coder.model.vo.BannerVO;
import cn.cxdproject.coder.model.vo.CursorPageResponseVO;
import cn.cxdproject.coder.service.ArticleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.resilience4j.bulkhead.annotation.Bulkhead;
Expand All @@ -19,6 +22,9 @@

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;

/**
* 文章控制器
Expand Down Expand Up @@ -54,18 +60,29 @@ public ApiResponse<ArticleVO> getArticleById(@PathVariable @NotNull(message = "
*/
@GetMapping("/page")
@PublicAccess
public PageResponse<ArticleVO> getArticlePage(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
public CursorPageResponseVO<ArticleVO> page(
@RequestParam(required = false) String cursor,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Page<Article> page = new Page<>(current, size);
Page<ArticleVO> articlePage = articleService.getArticlePage(page, keyword);
return PageResponse.of(
(int) articlePage.getCurrent(),
(int) articlePage.getSize(),
articlePage.getTotal(),
articlePage.getRecords()
);

Long lastId = null;
if (cursor != null && !cursor.trim().isEmpty()) {
try {
lastId = Long.parseLong(cursor.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid cursor");
}
}

List<ArticleVO> list = articleService.getArticlePage(lastId, size, keyword);

String nextCursor = null;
if (list.size() == size && !list.isEmpty()) {
// 升序:最后一条是最大的 id
nextCursor = String.valueOf(list.get(list.size() - 1).getId());
}

return new CursorPageResponseVO<>(list, nextCursor);
}

// ==================== 管理员接口 ====================
Expand All @@ -79,6 +96,23 @@ public ApiResponse<ArticleVO> createArticleByAdmin(@Valid @RequestBody CreateArt
return ApiResponse.success(articleVO);
}

@GetMapping("/admin/page")
public PageResponse<ArticleVO> getArticlePageAdmin(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String keyword) {

Page<Article> page = new Page<>(current, size);
Page<ArticleVO> articlePage = articleService.getArticlePagAdmine(page, keyword);

return PageResponse.of(
(int) articlePage.getCurrent(),
(int) articlePage.getSize(),
articlePage.getTotal(),
articlePage.getRecords()
);
}

/**
* 管理员更新文章
*/
Expand Down
54 changes: 43 additions & 11 deletions src/main/java/cn/cxdproject/coder/controller/DramaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import cn.cxdproject.coder.common.context.AuthContext;
import cn.cxdproject.coder.model.dto.CreateDramaDTO;
import cn.cxdproject.coder.model.dto.UpdateDramaDTO;
import cn.cxdproject.coder.model.entity.Article;
import cn.cxdproject.coder.model.entity.Drama;
import cn.cxdproject.coder.model.entity.User;
import cn.cxdproject.coder.model.vo.ArticleVO;
import cn.cxdproject.coder.model.vo.CursorPageResponseVO;
import cn.cxdproject.coder.model.vo.DramaVO;
import cn.cxdproject.coder.service.DramaService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
Expand All @@ -18,6 +21,7 @@

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* 电视剧备案控制器
Expand Down Expand Up @@ -53,18 +57,29 @@ public ApiResponse<DramaVO> getDramaById(@PathVariable @NotNull(message = "ID不
*/
@GetMapping("/page")
@PublicAccess
public PageResponse<DramaVO> getDramaPage(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
public CursorPageResponseVO<DramaVO> page(
@RequestParam(required = false) String cursor,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Page<Drama> page = new Page<>(current, size);
Page<DramaVO> dramaPage = dramaService.getDramaPage(page, keyword);
return PageResponse.of(
(int) dramaPage.getCurrent(),
(int) dramaPage.getSize(),
dramaPage.getTotal(),
dramaPage.getRecords()
);

Long lastId = null;
if (cursor != null && !cursor.trim().isEmpty()) {
try {
lastId = Long.parseLong(cursor.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid cursor");
}
}

List<DramaVO> list = dramaService.getDramaPage(lastId, size, keyword);

String nextCursor = null;
if (list.size() == size && !list.isEmpty()) {
// 升序:最后一条是最大的 id
nextCursor = String.valueOf(list.get(list.size() - 1).getId());
}

return new CursorPageResponseVO<>(list, nextCursor);
}

// ==================== 普通用户接口 ====================
Expand All @@ -83,6 +98,23 @@ public ApiResponse<DramaVO> updateDramaByAdmin(
return ApiResponse.success(dramaVO);
}

@GetMapping("/admin/page")
public PageResponse<DramaVO> getDramaPageAdmin(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String keyword) {

Page<Drama> page = new Page<>(current, size);
Page<DramaVO> dramaPage = dramaService.getDramaPageAdmin(page, keyword);

return PageResponse.of(
(int) dramaPage.getCurrent(),
(int) dramaPage.getSize(),
dramaPage.getTotal(),
dramaPage.getRecords()
);
}

/**
* 创建电视剧备案
*/
Expand Down
59 changes: 46 additions & 13 deletions src/main/java/cn/cxdproject/coder/controller/HotelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import cn.cxdproject.coder.common.context.AuthContext;
import cn.cxdproject.coder.model.dto.CreateHotelDTO;
import cn.cxdproject.coder.model.dto.UpdateHotelDTO;
import cn.cxdproject.coder.model.entity.Article;
import cn.cxdproject.coder.model.entity.Hotel;
import cn.cxdproject.coder.model.entity.User;
import cn.cxdproject.coder.model.vo.ArticleVO;
import cn.cxdproject.coder.model.vo.CursorPageResponseVO;
import cn.cxdproject.coder.model.vo.HotelVO;
import cn.cxdproject.coder.service.HotelService;
import cn.cxdproject.coder.service.impl.HotelServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -17,16 +21,17 @@

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/hotel")
@Validated
public class HotelController {

private final HotelServiceImpl hotelService;
private final HotelService hotelService;

public HotelController(HotelServiceImpl hotelService) {
public HotelController(HotelService hotelService) {
this.hotelService = hotelService;
}

Expand All @@ -44,18 +49,29 @@ public ApiResponse<HotelVO> getHotelById(@PathVariable @NotNull(message = "旅
*/
@GetMapping("/page")
@PublicAccess
public PageResponse<HotelVO> getHotelPage(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
public CursorPageResponseVO<HotelVO> page(
@RequestParam(required = false) String cursor,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Page<Hotel> page = new Page<>(current, size);
Page<HotelVO> hotelPage = hotelService.getHotelPage(page, keyword);
return PageResponse.of(
(int) hotelPage.getCurrent(),
(int) hotelPage.getSize(),
hotelPage.getTotal(),
hotelPage.getRecords()
);

Long lastId = null;
if (cursor != null && !cursor.trim().isEmpty()) {
try {
lastId = Long.parseLong(cursor.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid cursor");
}
}

List<HotelVO> list = hotelService.getHotelPage(lastId, size, keyword);

String nextCursor = null;
if (list.size() == size && !list.isEmpty()) {
// 升序:最后一条是最大的 id
nextCursor = String.valueOf(list.get(list.size() - 1).getId());
}

return new CursorPageResponseVO<>(list, nextCursor);
}

// ==================== 管理员接口 ====================
Expand All @@ -73,6 +89,23 @@ public ApiResponse<HotelVO> createHotelByAdmin(@Valid @RequestBody CreateHotelDT
return ApiResponse.success(hotelVO);
}

@GetMapping("/admin/page")
public PageResponse<HotelVO> getHotelPageAdmin(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String keyword) {

Page<Hotel> page = new Page<>(current, size);
Page<HotelVO> hotelPage = hotelService.getHotelPageAdmin(page, keyword);

return PageResponse.of(
(int) hotelPage.getCurrent(),
(int) hotelPage.getSize(),
hotelPage.getTotal(),
hotelPage.getRecords()
);
}

/**
* 管理员更新旅店
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import cn.cxdproject.coder.common.context.AuthContext;
import cn.cxdproject.coder.model.dto.CreateLocationDTO;
import cn.cxdproject.coder.model.dto.UpdateLocationDTO;
import cn.cxdproject.coder.model.entity.Hotel;
import cn.cxdproject.coder.model.entity.Location;
import cn.cxdproject.coder.model.entity.User;
import cn.cxdproject.coder.model.vo.CursorPageResponseVO;
import cn.cxdproject.coder.model.vo.DramaVO;
import cn.cxdproject.coder.model.vo.HotelVO;
import cn.cxdproject.coder.model.vo.LocationVO;
import cn.cxdproject.coder.service.LocationService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
Expand All @@ -18,6 +22,7 @@

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* 拍摄场地控制器
Expand Down Expand Up @@ -53,20 +58,30 @@ public ApiResponse<LocationVO> getLocationById(@PathVariable @NotNull(message =
*/
@GetMapping("/page")
@PublicAccess
public PageResponse<LocationVO> getLocationPage(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
public CursorPageResponseVO<LocationVO> page(
@RequestParam(required = false) String cursor,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Page<Location> page = new Page<>(current, size);
Page<LocationVO> locationPage = locationService.getLocationPage(page, keyword);
return PageResponse.of(
(int) locationPage.getCurrent(),
(int) locationPage.getSize(),
locationPage.getTotal(),
locationPage.getRecords()
);
}

Long lastId = null;
if (cursor != null && !cursor.trim().isEmpty()) {
try {
lastId = Long.parseLong(cursor.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid cursor");
}
}

List<LocationVO> list = locationService.getLocationPage(lastId, size, keyword);

String nextCursor = null;
if (list.size() == size && !list.isEmpty()) {
// 升序:最后一条是最大的 id
nextCursor = String.valueOf(list.get(list.size() - 1).getId());
}

return new CursorPageResponseVO<>(list, nextCursor);
}
// ==================== 普通用户接口 ====================

// ==================== 管理员接口 ====================
Expand All @@ -85,6 +100,23 @@ public ApiResponse<LocationVO> createLocation(@Valid @RequestBody CreateLocation
return ApiResponse.success(locationVO);
}

@GetMapping("/admin/page")
public PageResponse<LocationVO> getLocationPageAdmin(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String keyword) {

Page<Location> page = new Page<>(current, size);
Page<LocationVO> locationPage = locationService.getLocationPageAdmin(page, keyword);

return PageResponse.of(
(int) locationPage.getCurrent(),
(int) locationPage.getSize(),
locationPage.getTotal(),
locationPage.getRecords()
);
}

/**
* 管理员更新拍摄场地
*/
Expand Down
Loading