parent
5a58c834db
commit
010cf3dc0f
@ -0,0 +1,9 @@
|
||||
package com.luojia_channel.common.domain.page;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PageRequest {
|
||||
private Long current = 1L;
|
||||
private Long size = 10L;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.luojia_channel.common.domain.page;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PageResponse<T> {
|
||||
private Long current;
|
||||
private Long size = 10L;
|
||||
private Long total;
|
||||
private List<T> records = Collections.emptyList();
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.luojia_channel.common.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreatePostDTO {
|
||||
private String title;
|
||||
private String content;
|
||||
private Long userId;
|
||||
private Long categoryId;
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.luojia_channel.common.utils;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.luojia_channel.common.domain.page.PageRequest;
|
||||
import com.luojia_channel.common.domain.page.PageResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PageUtil {
|
||||
public static <R,T> PageResponse<R> convert(IPage<T> page, Function<? super T,? extends R> mapper) {
|
||||
List<R> targetList = page.getRecords().stream()
|
||||
.map(mapper)
|
||||
.collect(Collectors.toList());
|
||||
return PageResponse.<R>builder()
|
||||
.current(page.getCurrent())
|
||||
.size(page.getSize())
|
||||
.records(targetList)
|
||||
.total(page.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static <R,T> PageResponse<R> convert(IPage<T> page, Class<R> clazz) {
|
||||
List<R> targetList = page.getRecords().stream()
|
||||
.map(each -> BeanUtil.copyProperties(each, clazz))
|
||||
.collect(Collectors.toList());
|
||||
return PageResponse.<R>builder()
|
||||
.current(page.getCurrent())
|
||||
.size(page.getSize())
|
||||
.records(targetList)
|
||||
.total(page.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Page convert(PageRequest request){
|
||||
return new Page(request.getCurrent(), request.getSize());
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.luojia_channel.modules.post.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import com.luojia_channel.common.domain.Result;
|
||||
import com.luojia_channel.common.domain.page.PageResponse;
|
||||
import com.luojia_channel.modules.file.dto.UploadFileDTO;
|
||||
import com.luojia_channel.modules.post.dto.req.PostCreateDTO;
|
||||
import com.luojia_channel.modules.post.dto.req.PostPageQueryDTO;
|
||||
import com.luojia_channel.modules.post.dto.req.PostUpdateDTO;
|
||||
import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO;
|
||||
import com.luojia_channel.modules.post.entity.Post;
|
||||
import com.luojia_channel.modules.post.service.PostService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/post")
|
||||
public class PostController {
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
// 创建帖子
|
||||
@PostMapping
|
||||
public Result<Void> createPost(@RequestBody PostCreateDTO postCreateDTO) {
|
||||
postService.createPost(postCreateDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 设置帖子封面
|
||||
@PostMapping("/cover")
|
||||
public Result<Void> setCover(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("fileType") String fileType,
|
||||
@RequestParam("fileMd5") String fileMd5){
|
||||
UploadFileDTO fileDTO = UploadFileDTO.builder()
|
||||
.file(file).fileType(fileType).fileMd5(fileMd5)
|
||||
.build();
|
||||
postService.setCover(fileDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 更新帖子
|
||||
@PutMapping()
|
||||
public Result<Void> updatePost(@RequestBody PostUpdateDTO postUpdateDTO) {
|
||||
postService.updatePost(postUpdateDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 删除帖子
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deletePost(@PathVariable Long id) {
|
||||
postService.deletePost(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 根据ID获取帖子详情
|
||||
@GetMapping("/{id}")
|
||||
public Post getPostById(@PathVariable Long id) {
|
||||
return postService.getById(id);
|
||||
}
|
||||
|
||||
// 分页查询帖子
|
||||
@GetMapping
|
||||
public Result<PageResponse<PostBasicInfoDTO>> pagePost(PostPageQueryDTO postPageQueryDTO) {
|
||||
return Result.success(postService.pagePost(postPageQueryDTO));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.luojia_channel.modules.post.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PostCreateDTO {
|
||||
private String title;
|
||||
private String content;
|
||||
private Long userId;
|
||||
private Long categoryId;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.luojia_channel.modules.post.dto.req;
|
||||
|
||||
import com.luojia_channel.common.domain.page.PageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PostPageQueryDTO extends PageRequest {
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.luojia_channel.modules.post.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PostUpdateDTO {
|
||||
private String title;
|
||||
private String content;
|
||||
private Long categoryId;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.luojia_channel.modules.post.dto.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PostBasicInfoDTO {
|
||||
private Long id;
|
||||
private String coverUrl;
|
||||
private String title;
|
||||
private Integer likeCount;
|
||||
private Integer commentCount;
|
||||
private Integer favoriteCount;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.luojia_channel.modules.post.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@TableName("post")
|
||||
public class Post {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String title;
|
||||
private Long coverId;
|
||||
private String content;
|
||||
private Integer likeCount;
|
||||
private Integer commentCount;
|
||||
private Integer favoriteCount;
|
||||
private Integer viewCount;
|
||||
private Long userId;
|
||||
private Long categoryId;
|
||||
private String createTime;
|
||||
private String updateTime;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.luojia_channel.modules.post.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.luojia_channel.modules.post.entity.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper extends BaseMapper<Post> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.luojia_channel.modules.post.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.luojia_channel.modules.post.entity.Post;
|
||||
|
||||
public interface PostService extends IService<Post> {
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.luojia_channel.modules.post.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.luojia_channel.modules.file.mapper.LjFileMapper;
|
||||
import com.luojia_channel.modules.post.entity.Post;
|
||||
import com.luojia_channel.modules.post.mapper.PostMapper;
|
||||
import com.luojia_channel.modules.post.service.PostService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {
|
||||
|
||||
private final PostMapper postMapper;
|
||||
private final LjFileMapper fileMapper;
|
||||
private String getUrlById(String id){
|
||||
return fileMapper.selectById(id).getFileUrl();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.luojia_channel.modules.post.utils;
|
||||
|
||||
public class ValidatePostUtil {
|
||||
}
|
@ -1,19 +1,36 @@
|
||||
# 本地开发环境
|
||||
# lj:
|
||||
# db:
|
||||
# host: localhost
|
||||
# password: 123456
|
||||
# redis:
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
# password: 123456
|
||||
# rabbitmq:
|
||||
# host: localhost
|
||||
# port: 15672
|
||||
# username: root
|
||||
# password: 123456
|
||||
# minio:
|
||||
# endpoint: http://localhost:9000
|
||||
# accessKey: minioadmin
|
||||
# secretKey: minioadmin
|
||||
|
||||
lj:
|
||||
db:
|
||||
host: localhost
|
||||
password: 123456
|
||||
host: 192.168.59.129
|
||||
password: Forely123!
|
||||
redis:
|
||||
host: localhost
|
||||
host: 192.168.59.129
|
||||
port: 6379
|
||||
password: 123456
|
||||
password: Forely123!
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 15672
|
||||
username: root
|
||||
password: 123456
|
||||
host: 192.168.59.129
|
||||
port: 5672
|
||||
username: admin
|
||||
password: Forely123!
|
||||
minio:
|
||||
endpoint: http://localhost:9000
|
||||
accessKey: minioadmin
|
||||
secretKey: minioadmin
|
||||
|
||||
endpoint: http://192.168.59.129:9000
|
||||
accessKey: forely
|
||||
secretKey: Forely123!
|
||||
|
Loading…
Reference in new issue