forked from mtusi2026/mtusi2026lab4
163 lines
4.0 KiB
Java
163 lines
4.0 KiB
Java
package ru.mtusi.messenger.dto;
|
|
|
|
import java.time.Instant;
|
|
import java.util.Objects;
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.*;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import org.hibernate.validator.constraints.CodePointLength;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* UserDTO
|
|
*/
|
|
|
|
public class UserDTO {
|
|
|
|
private UUID id;
|
|
|
|
private String username;
|
|
|
|
private String displayName;
|
|
|
|
private Instant createdAt;
|
|
|
|
public UserDTO() {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* Constructor with only required parameters
|
|
*/
|
|
public UserDTO(String username, String displayName) {
|
|
this.username = username;
|
|
this.displayName = displayName;
|
|
}
|
|
|
|
public UserDTO username(String username) {
|
|
this.username = username;
|
|
return this;
|
|
}
|
|
|
|
@Valid
|
|
@Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
|
@JsonProperty("id")
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public UserDTO id(UUID id) {
|
|
this.id = id;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get username
|
|
* @return username
|
|
*/
|
|
@NotNull @Pattern(regexp = "^[a-z0-9_]{3,32}$")
|
|
@Schema(name = "username", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("username")
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public UserDTO displayName(String displayName) {
|
|
this.displayName = displayName;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get displayName
|
|
* @return displayName
|
|
*/
|
|
@NotNull
|
|
@CodePointLength(min = 1, max = 100)
|
|
@Schema(name = "display_name", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("display_name")
|
|
public String getDisplayName() {
|
|
return displayName;
|
|
}
|
|
|
|
public void setDisplayName(String displayName) {
|
|
this.displayName = displayName;
|
|
}
|
|
|
|
/**
|
|
* Get password
|
|
* @return password
|
|
*/
|
|
|
|
public UserDTO createdAt(Instant createdAt) {
|
|
this.createdAt = createdAt;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get createdAt
|
|
* @return createdAt
|
|
*/
|
|
@NotNull
|
|
@Schema(name = "created_at", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("created_at")
|
|
public Instant getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
|
|
public void setCreatedAt(Instant createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) {
|
|
return true;
|
|
}
|
|
if (o == null || getClass() != o.getClass()) {
|
|
return false;
|
|
}
|
|
UserDTO userDTO = (UserDTO) o;
|
|
return Objects.equals(this.id, userDTO.id) &&
|
|
Objects.equals(this.username, userDTO.username) &&
|
|
Objects.equals(this.displayName, userDTO.displayName) &&
|
|
Objects.equals(this.createdAt, userDTO.createdAt);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(id, username, displayName, createdAt);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("class UserDTO {\n");
|
|
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
|
sb.append(" username: ").append(toIndentedString(username)).append("\n");
|
|
sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n");
|
|
sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n");
|
|
sb.append("}");
|
|
return sb.toString();
|
|
}
|
|
|
|
/**
|
|
* Convert the given object to string with each line indented by 4 spaces
|
|
* (except the first line).
|
|
*/
|
|
private String toIndentedString(Object o) {
|
|
if (o == null) {
|
|
return "null";
|
|
}
|
|
return o.toString().replace("\n", "\n ");
|
|
}
|
|
} |