feat: 开发中...
This commit is contained in:
@@ -5,7 +5,10 @@ import cn.hamster3.application.blog.vo.PageableVO;
|
||||
import cn.hamster3.application.blog.vo.ResponseVO;
|
||||
import cn.hamster3.application.blog.vo.attach.AttachInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.blog.BlogInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.*;
|
||||
import cn.hamster3.application.blog.vo.user.UserCreateRequireVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserLoginRequireVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserUpdateRequireVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -25,6 +28,7 @@ public class UserController {
|
||||
private IUserService userService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "登录用户")
|
||||
public ResponseVO<Void> loginUser(@RequestBody @Valid UserLoginRequireVO requireVO) {
|
||||
return userService.loginUser(requireVO);
|
||||
}
|
||||
@@ -37,14 +41,17 @@ public class UserController {
|
||||
|
||||
@PostMapping("/")
|
||||
@Operation(summary = "注册用户")
|
||||
public ResponseVO<UserRegisterResponseVO> createUser(@RequestBody @Valid UserCreateRequireVO requireVO) {
|
||||
public ResponseVO<UserInfoResponseVO> createUser(@RequestBody @Valid UserCreateRequireVO requireVO) {
|
||||
return userService.createUser(requireVO);
|
||||
}
|
||||
|
||||
@PutMapping("/")
|
||||
@PutMapping("/{userID}/")
|
||||
@Operation(summary = "更新用户信息")
|
||||
public ResponseVO<Void> updateUser(@RequestBody @Valid UserUpdateRequireVO requireVO) {
|
||||
return userService.updateUser(requireVO);
|
||||
public ResponseVO<Void> updateUser(
|
||||
@Parameter(description = "用户ID") @PathVariable UUID userID,
|
||||
@Parameter(description = "用户信息") @RequestBody @Valid UserUpdateRequireVO requireVO
|
||||
) {
|
||||
return userService.updateUser(userID, requireVO);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
|
@@ -5,9 +5,11 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface AttachRepository extends JpaRepository<AttachEntity, Long>, JpaSpecificationExecutor<AttachEntity> {
|
||||
Page<AttachEntity> findByUploader_IdOrderByCreateTimeDesc(UUID id, Pageable pageable);
|
||||
@Query("select a from AttachEntity a where a.creator.id = ?1 order by a.createTime DESC")
|
||||
Page<AttachEntity> findByCreator_IdOrderByCreateTimeDesc(UUID id, Pageable pageable);
|
||||
}
|
@@ -10,7 +10,9 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface BlogRepository extends JpaRepository<BlogEntity, Long>, JpaSpecificationExecutor<BlogEntity> {
|
||||
Page<BlogEntity> findByUploader_IdOrderByAttachEntities_CreateTimeDesc(UUID id, Pageable pageable);
|
||||
@Query("select b from BlogEntity b where b.creator.id = ?1 order by b.createTime DESC")
|
||||
Page<BlogEntity> findByCreator_IdOrderByCreateTimeDesc(UUID id, Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"content"})
|
||||
@Query("select b from BlogEntity b where b.id = ?1")
|
||||
Optional<BlogEntity> findByIDWithContent(Long id);
|
||||
|
@@ -5,6 +5,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@@ -17,7 +18,7 @@ import java.util.Date;
|
||||
public class AttachEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id", nullable = false)
|
||||
@Column(name = "id", nullable = false, updatable = false)
|
||||
private Long id;
|
||||
|
||||
@Setter
|
||||
@@ -28,13 +29,21 @@ public class AttachEntity {
|
||||
|
||||
@CreatedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "uploader_id", nullable = false)
|
||||
private UserEntity uploader;
|
||||
@JoinColumn(name = "creator", nullable = false)
|
||||
private UserEntity creator;
|
||||
|
||||
@LastModifiedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "updater", nullable = false)
|
||||
private UserEntity updater;
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "create_time", nullable = false)
|
||||
private Date createTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "update_time", nullable = false)
|
||||
private Date updateTime;
|
||||
|
||||
|
@@ -3,7 +3,9 @@ package cn.hamster3.application.blog.entity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -15,7 +17,7 @@ import java.util.Date;
|
||||
public class BlogAttachEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id", nullable = false)
|
||||
@Column(name = "id", nullable = false, updatable = false)
|
||||
private Long id;
|
||||
|
||||
@Lob
|
||||
@@ -24,14 +26,26 @@ public class BlogAttachEntity {
|
||||
private byte[] data;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "blog_entity_id", nullable = false)
|
||||
@JoinColumn(name = "blogID", nullable = false)
|
||||
private BlogEntity blogEntity;
|
||||
|
||||
@CreatedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "creator", nullable = false)
|
||||
private UserEntity creator;
|
||||
|
||||
@LastModifiedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "updater", nullable = false)
|
||||
private UserEntity updater;
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "create_time", nullable = false)
|
||||
private Date createTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "update_time", nullable = false)
|
||||
private Date updateTime;
|
||||
|
||||
|
@@ -3,29 +3,27 @@ package cn.hamster3.application.blog.entity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 博文实体
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "blog_entity")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class BlogEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id", nullable = false)
|
||||
@Column(name = "id", nullable = false, updatable = false)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "title", nullable = false, length = 128)
|
||||
@@ -34,25 +32,44 @@ public class BlogEntity {
|
||||
@Column(name = "abstracts", nullable = false, length = 512)
|
||||
private String abstracts;
|
||||
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
@Column(name = "password", length = 60)
|
||||
@JdbcTypeCode(SqlTypes.VARCHAR)
|
||||
private String password;
|
||||
|
||||
@ToString.Exclude
|
||||
@Lob
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
@Column(name = "content", nullable = false)
|
||||
private String content;
|
||||
|
||||
@Column(name = "top", nullable = false)
|
||||
private Boolean top = false;
|
||||
|
||||
@Column(name = "publish", nullable = false)
|
||||
private Boolean publish = false;
|
||||
|
||||
@Setter
|
||||
@ElementCollection
|
||||
@Column(name = "tag")
|
||||
@CollectionTable(name = "blog_entity_tags")
|
||||
@JoinColumn(name = "blog_id")
|
||||
private Set<String> tags = new LinkedHashSet<>();
|
||||
|
||||
@Setter
|
||||
@ToString.Exclude
|
||||
@OrderBy("create_time DESC")
|
||||
@OneToMany(mappedBy = "blogEntity", orphanRemoval = true)
|
||||
private List<BlogAttachEntity> attachEntities = new ArrayList<>();
|
||||
|
||||
@CreatedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "uploader_id", nullable = false)
|
||||
private UserEntity uploader;
|
||||
@JoinColumn(name = "creator", nullable = false)
|
||||
private UserEntity creator;
|
||||
|
||||
@LastModifiedBy
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "updater", nullable = false)
|
||||
private UserEntity updater;
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
|
@@ -0,0 +1,29 @@
|
||||
package cn.hamster3.application.blog.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Entity
|
||||
public class SiteSetting {
|
||||
@Id
|
||||
@Column(name = "id", nullable = false, updatable = false, length = 64)
|
||||
private String id;
|
||||
|
||||
@Column(name = "content", nullable = false, length = 1024)
|
||||
private String content;
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "create_time", nullable = false)
|
||||
private Date createTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "update_time", nullable = false)
|
||||
private Date updateTime;
|
||||
}
|
@@ -1,19 +1,22 @@
|
||||
package cn.hamster3.application.blog.entity;
|
||||
|
||||
import cn.hamster3.application.blog.constant.UserRole;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "user_entity")
|
||||
@@ -26,13 +29,19 @@ public class UserEntity {
|
||||
private UUID id;
|
||||
|
||||
@Setter
|
||||
@Column(name = "email", nullable = false, unique = true, length = 32)
|
||||
@Column(name = "email", nullable = false, unique = true, length = 64)
|
||||
@Email(message = "邮箱配置不合法!")
|
||||
@NotBlank(message = "邮箱不能为空!")
|
||||
@Length(max = 64, message = "邮箱地址最大长度不能超过 64 字符!")
|
||||
private String email;
|
||||
|
||||
@Setter
|
||||
@Column(name = "nickname", nullable = false, unique = true, length = 32)
|
||||
@NotBlank(message = "昵称不能为空!")
|
||||
@Length(min = 1, max = 32, message = "用户昵称不能超过 32 个字符!")
|
||||
private String nickname;
|
||||
|
||||
@Parameter(name = "密码")
|
||||
@Setter
|
||||
@Column(name = "password", nullable = false, length = 60)
|
||||
private String password;
|
||||
@@ -44,19 +53,21 @@ public class UserEntity {
|
||||
|
||||
@Setter
|
||||
@OrderBy("create_time DESC")
|
||||
@OneToMany(mappedBy = "uploader", orphanRemoval = true)
|
||||
private List<AttachEntity> attachEntities = new ArrayList<>();
|
||||
@OneToMany(mappedBy = "creator", orphanRemoval = true)
|
||||
private List<BlogEntity> blogEntities = new ArrayList<>();
|
||||
|
||||
@Setter
|
||||
@OrderBy("create_time DESC")
|
||||
@OneToMany(mappedBy = "uploader", orphanRemoval = true)
|
||||
private List<BlogEntity> blogEntities = new ArrayList<>();
|
||||
@OneToMany(mappedBy = "creator", orphanRemoval = true)
|
||||
private List<AttachEntity> attachEntities = new ArrayList<>();
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "create_time", nullable = false)
|
||||
private Date createTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "update_time", nullable = false)
|
||||
private Date updateTime;
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package cn.hamster3.application.blog.entity.mapper;
|
||||
import cn.hamster3.application.blog.entity.AttachEntity;
|
||||
import cn.hamster3.application.blog.entity.UserEntity;
|
||||
import cn.hamster3.application.blog.vo.attach.AttachInfoResponseVO;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
@@ -13,7 +14,9 @@ import java.util.UUID;
|
||||
public interface AttachMapper {
|
||||
AttachInfoResponseVO entityToInfoVO(AttachEntity entity);
|
||||
|
||||
default UUID map(UserEntity value) {
|
||||
@NotNull
|
||||
@SuppressWarnings("unused")
|
||||
default UUID map(@NotNull UserEntity value) {
|
||||
return value.getId();
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,9 @@ package cn.hamster3.application.blog.entity.mapper;
|
||||
|
||||
import cn.hamster3.application.blog.entity.BlogEntity;
|
||||
import cn.hamster3.application.blog.entity.UserEntity;
|
||||
import cn.hamster3.application.blog.vo.blog.BlogUpdateRequireVO;
|
||||
import cn.hamster3.application.blog.vo.blog.BlogInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.blog.BlogUpdateRequireVO;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
@@ -16,7 +17,9 @@ public interface BlogMapper {
|
||||
|
||||
BlogInfoResponseVO entityToInfoVO(BlogEntity requireVO);
|
||||
|
||||
default UUID map(UserEntity value) {
|
||||
@NotNull
|
||||
@SuppressWarnings("unused")
|
||||
default UUID map(@NotNull UserEntity value) {
|
||||
return value.getId();
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,6 @@ package cn.hamster3.application.blog.entity.mapper;
|
||||
import cn.hamster3.application.blog.entity.UserEntity;
|
||||
import cn.hamster3.application.blog.vo.user.UserCreateRequireVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserRegisterResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserUpdateRequireVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
@@ -13,9 +11,5 @@ import org.mapstruct.ReportingPolicy;
|
||||
public interface UserMapper {
|
||||
UserEntity voToEntity(UserCreateRequireVO requireVO);
|
||||
|
||||
UserEntity voToEntity(UserUpdateRequireVO requireVO);
|
||||
|
||||
UserInfoResponseVO entityToInfoVO(UserEntity requireVO);
|
||||
|
||||
UserRegisterResponseVO entityToRegisterVO(UserEntity requireVO);
|
||||
UserInfoResponseVO entityToInfoVO(UserEntity entity);
|
||||
}
|
||||
|
@@ -15,13 +15,13 @@ public interface IUserService {
|
||||
|
||||
@NotNull ResponseVO<UserInfoResponseVO> getCurrentUserInfo();
|
||||
|
||||
@NotNull ResponseVO<UserRegisterResponseVO> createUser(@NotNull UserCreateRequireVO requireVO);
|
||||
@NotNull ResponseVO<UserInfoResponseVO> createUser(@NotNull UserCreateRequireVO requireVO);
|
||||
|
||||
@NotNull ResponseVO<Void> updateUser(@NotNull UserUpdateRequireVO requireVO);
|
||||
@NotNull ResponseVO<Void> updateUser(@NotNull UUID userID, @NotNull UserUpdateRequireVO requireVO);
|
||||
|
||||
@NotNull ResponseVO<PageableVO<UserInfoResponseVO>> getAllUserInfo(@NotNull Pageable pageable);
|
||||
|
||||
@NotNull ResponseVO<UserInfoResponseVO> getUserInfo(UUID id);
|
||||
@NotNull ResponseVO<UserInfoResponseVO> getUserInfo(@NotNull UUID id);
|
||||
|
||||
@NotNull ResponseVO<PageableVO<BlogInfoResponseVO>> getUserBlogList(@NotNull UUID userID, @NotNull Pageable pageable);
|
||||
|
||||
|
@@ -15,13 +15,14 @@ import cn.hamster3.application.blog.vo.PageableVO;
|
||||
import cn.hamster3.application.blog.vo.ResponseVO;
|
||||
import cn.hamster3.application.blog.vo.attach.AttachInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.blog.BlogInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.*;
|
||||
import cn.hamster3.application.blog.vo.user.UserCreateRequireVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserInfoResponseVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserLoginRequireVO;
|
||||
import cn.hamster3.application.blog.vo.user.UserUpdateRequireVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -66,7 +67,7 @@ public class UserService implements IUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<UserRegisterResponseVO> createUser(@NotNull UserCreateRequireVO requireVO) {
|
||||
public @NotNull ResponseVO<UserInfoResponseVO> createUser(@NotNull UserCreateRequireVO requireVO) {
|
||||
UserEntity entity = userMapper.voToEntity(requireVO);
|
||||
entity.setEmail(entity.getEmail().toLowerCase());
|
||||
|
||||
@@ -83,21 +84,18 @@ public class UserService implements IUserService {
|
||||
log.info("prepare to save userinfo: {}", entity);
|
||||
UserEntity save = userRepo.save(entity);
|
||||
|
||||
return ResponseVO.success("注册成功!", userMapper.entityToRegisterVO(save));
|
||||
return ResponseVO.success("注册成功!", userMapper.entityToInfoVO(save));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<Void> updateUser(@NotNull UserUpdateRequireVO requireVO) {
|
||||
UserEntity userEntity = userRepo.findById(requireVO.getId()).orElse(null);
|
||||
public @NotNull ResponseVO<Void> updateUser(@NotNull UUID uuid, @NotNull UserUpdateRequireVO requireVO) {
|
||||
UserEntity userEntity = userRepo.findById(uuid).orElse(null);
|
||||
if (userEntity == null) {
|
||||
return ResponseVO.failed("未找到该用户!");
|
||||
}
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
}
|
||||
if (!(authentication.getPrincipal() instanceof BlogUser blogUser)) {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
BlogUser blogUser = UserAuditorAware.currentUser().orElse(null);
|
||||
if (blogUser == null) {
|
||||
return ResponseVO.unauthorized();
|
||||
}
|
||||
if (!blogUser.getId().equals(userEntity.getId())
|
||||
&& !blogUser.getAuthorities().contains(UserRole.ADMIN.getAuthority())) {
|
||||
@@ -141,7 +139,7 @@ public class UserService implements IUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<UserInfoResponseVO> getUserInfo(UUID id) {
|
||||
public @NotNull ResponseVO<UserInfoResponseVO> getUserInfo(@NotNull UUID id) {
|
||||
return userRepo.findById(id)
|
||||
.map(o -> ResponseVO.success(userMapper.entityToInfoVO(o)))
|
||||
.orElse(ResponseVO.failed("未找到该用户!"));
|
||||
@@ -150,7 +148,7 @@ public class UserService implements IUserService {
|
||||
@Override
|
||||
public @NotNull ResponseVO<PageableVO<BlogInfoResponseVO>> getUserBlogList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||
return PageableVO.success(
|
||||
blogRepo.findByUploader_IdOrderByAttachEntities_CreateTimeDesc(userID, pageable)
|
||||
blogRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> blogMapper.entityToInfoVO(o))
|
||||
);
|
||||
}
|
||||
@@ -158,7 +156,7 @@ public class UserService implements IUserService {
|
||||
@Override
|
||||
public @NotNull ResponseVO<PageableVO<AttachInfoResponseVO>> getUserAttachList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||
return PageableVO.success(
|
||||
attachRepo.findByUploader_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
attachRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> attachMapper.entityToInfoVO(o))
|
||||
);
|
||||
}
|
||||
|
@@ -1,14 +1,16 @@
|
||||
package cn.hamster3.application.blog.vo.attach;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class AttachInfoResponseVO {
|
||||
private Long id;
|
||||
private UUID uploader;
|
||||
private UUID creator;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
||||
|
@@ -1,19 +1,27 @@
|
||||
package cn.hamster3.application.blog.vo.blog;
|
||||
|
||||
import cn.hamster3.application.blog.entity.BlogAttachEntity;
|
||||
import cn.hamster3.application.blog.entity.UserEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BlogInfoResponseVO {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String abstracts;
|
||||
private String password;
|
||||
private String content;
|
||||
private UUID uploader;
|
||||
private Boolean top;
|
||||
private Boolean publish;
|
||||
private Set<String> tags;
|
||||
private List<BlogAttachEntity> attachEntities;
|
||||
private UserEntity creator;
|
||||
private UserEntity updater;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,16 @@
|
||||
package cn.hamster3.application.blog.vo.blog;
|
||||
|
||||
import cn.hamster3.application.blog.entity.BlogEntity;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
/**
|
||||
* @see BlogEntity
|
||||
*/
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BlogUpdateRequireVO {
|
||||
@Length(max = 32, message = "标题长度不能超过 32 个字符!")
|
||||
@NotBlank(message = "标题不能为空!")
|
||||
@@ -24,4 +25,11 @@ public class BlogUpdateRequireVO {
|
||||
|
||||
@NotBlank(message = "博客文章内容不能为空!")
|
||||
private String content;
|
||||
|
||||
private Boolean top;
|
||||
|
||||
private Boolean publish;
|
||||
|
||||
@NotNull
|
||||
private Set<String> tags;
|
||||
}
|
||||
|
@@ -1,21 +1,21 @@
|
||||
package cn.hamster3.application.blog.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserCreateRequireVO {
|
||||
@Parameter(name = "邮箱")
|
||||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", message = "邮箱配置不合法!")
|
||||
@Email(message = "邮箱配置不合法!")
|
||||
@NotBlank(message = "邮箱不能为空!")
|
||||
@Length(max = 64, message = "邮箱地址最大长度不能超过 64 字符!")
|
||||
private String email;
|
||||
@Parameter(name = "昵称")
|
||||
@Size(min = 3, max = 16, message = "用户昵称必须包含 3~16 个字符!")
|
||||
@NotBlank(message = "昵称不能为空!")
|
||||
@Length(min = 1, max = 32, message = "用户昵称不能超过 32 个字符!")
|
||||
private String nickname;
|
||||
@Parameter(name = "密码")
|
||||
@Size(min = 8, max = 16, message = "密码必须包含 8~16 个字符!")
|
||||
@Length(min = 8, max = 32, message = "密码长度必须在 8~32 个字符之间!")
|
||||
private String password;
|
||||
}
|
||||
|
@@ -1,9 +1,13 @@
|
||||
package cn.hamster3.application.blog.vo.user;
|
||||
|
||||
import cn.hamster3.application.blog.constant.UserRole;
|
||||
import cn.hamster3.application.blog.entity.AttachEntity;
|
||||
import cn.hamster3.application.blog.entity.BlogEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@@ -13,4 +17,8 @@ public class UserInfoResponseVO {
|
||||
private String email;
|
||||
private String nickname;
|
||||
private UserRole role;
|
||||
private List<BlogEntity> blogEntities;
|
||||
private List<AttachEntity> attachEntities;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
||||
|
@@ -1,15 +1,18 @@
|
||||
package cn.hamster3.application.blog.vo.user;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserLoginRequireVO {
|
||||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", message = "邮箱不合法!")
|
||||
@Max(value = 32, message = "邮箱长度不能超过 32 个字符!")
|
||||
@Email(message = "邮箱配置不合法!")
|
||||
@NotBlank(message = "邮箱不能为空!")
|
||||
@Length(max = 64, message = "邮箱地址最大长度不能超过 64 字符!")
|
||||
private String email;
|
||||
@Size(min = 8, max = 16, message = "密码必须包含 8~16 个字符!")
|
||||
@Length(min = 8, max = 32, message = "密码长度必须在 8~32 个字符之间!")
|
||||
private String password;
|
||||
}
|
||||
|
@@ -1,17 +0,0 @@
|
||||
package cn.hamster3.application.blog.vo.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserRegisterResponseVO {
|
||||
private UUID id;
|
||||
private String email;
|
||||
private String nickname;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
@@ -1,28 +1,16 @@
|
||||
package cn.hamster3.application.blog.vo.user;
|
||||
|
||||
import cn.hamster3.application.blog.constant.UserRole;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserUpdateRequireVO {
|
||||
@Parameter(name = "用户ID")
|
||||
@NotNull(message = "用户id不能为空!")
|
||||
private UUID id;
|
||||
@Parameter(name = "邮箱")
|
||||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", message = "邮箱配置不合法!")
|
||||
private String email;
|
||||
@Parameter(name = "昵称")
|
||||
@Size(min = 3, max = 16, message = "用户昵称必须包含 3~16 个字符!")
|
||||
private String nickname;
|
||||
@Parameter(name = "密码")
|
||||
@Size(min = 8, max = 16, message = "密码必须包含 8~16 个字符!")
|
||||
@Length(min = 8, max = 32, message = "密码长度必须在 8~32 个字符之间!")
|
||||
private String password;
|
||||
@Parameter(name = "角色")
|
||||
private UserRole role;
|
||||
}
|
||||
|
Reference in New Issue
Block a user