mirror of https://github.com/halo-dev/halo
Complete update profile api
parent
9c4b2c309d
commit
63f87204bb
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -92,4 +93,16 @@ public class Attachment {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -70,4 +71,16 @@ public class Category {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -113,4 +114,16 @@ public class Comment {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -81,4 +82,16 @@ public class Gallery {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -74,4 +75,16 @@ public class Link {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.model.entity;
|
|||
|
||||
|
||||
import cc.ryanc.halo.model.enums.LogType;
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -72,4 +73,16 @@ public class Log {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -74,4 +75,16 @@ public class Menu {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -58,4 +59,16 @@ public class Option {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.model.entity;
|
|||
import cc.ryanc.halo.model.enums.PostCreateFrom;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -149,4 +150,16 @@ public class Post {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -58,4 +59,16 @@ public class PostCategory {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -54,4 +55,16 @@ public class PostTag {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
@ -56,4 +57,16 @@ public class Tag {
|
|||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,4 +93,11 @@ public class User {
|
|||
public void prePersist() {
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package cc.ryanc.halo.model.params;
|
||||
|
||||
import cc.ryanc.halo.model.dto.base.InputConverter;
|
||||
import cc.ryanc.halo.model.entity.User;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* User param.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/19/19
|
||||
*/
|
||||
@Data
|
||||
public class UserParam implements InputConverter<User> {
|
||||
|
||||
@NotBlank(message = "Username must not be blank")
|
||||
@Size(max = 50, message = "Length of username must not be more than {max}")
|
||||
private String username;
|
||||
|
||||
@NotBlank(message = "Nickname must not be blank")
|
||||
@Size(max = 255, message = "Length of nickname must not be more than {max}")
|
||||
private String nickname;
|
||||
|
||||
@Email(message = "The email format is incorrect")
|
||||
@NotBlank(message = "Email must not be blank")
|
||||
@Size(max = 127, message = "Length of email must not be more than {max}")
|
||||
private String email;
|
||||
|
||||
@Size(max = 1023, message = "Length of avatar link must not be more than {max}")
|
||||
private String avatar;
|
||||
|
||||
@Size(max = 1023, message = "Length of description must not be more than {max}")
|
||||
private String description;
|
||||
}
|
|
@ -2,10 +2,11 @@ package cc.ryanc.halo.web.controller.admin.api;
|
|||
|
||||
import cc.ryanc.halo.model.dto.UserOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.User;
|
||||
import cc.ryanc.halo.model.params.UserParam;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author johnniang
|
||||
|
@ -21,8 +22,17 @@ public class UserController {
|
|||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("me")
|
||||
public UserOutputDTO getOwnDetail(User user) {
|
||||
@GetMapping("profile")
|
||||
public UserOutputDTO getProfile(User user) {
|
||||
return new UserOutputDTO().convertFrom(user);
|
||||
}
|
||||
|
||||
@PutMapping("profile")
|
||||
public UserOutputDTO updateProfile(@Valid @RequestBody UserParam userParam, User user) {
|
||||
// Update properties
|
||||
userParam.update(user);
|
||||
|
||||
// Update user and convert to dto
|
||||
return new UserOutputDTO().convertFrom(userService.update(user));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue