173 lines
4.4 KiB
Java
173 lines
4.4 KiB
Java
package ru.mtusi.messenger.dto;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import com.fasterxml.jackson.annotation.JsonValue;
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.NotNull;
|
|
import jakarta.validation.constraints.Size;
|
|
|
|
import java.time.Instant;
|
|
import java.util.Objects;
|
|
|
|
public class SessionDTO {
|
|
|
|
private String token;
|
|
|
|
public enum TokenTypeEnum {
|
|
BEARER("Bearer");
|
|
|
|
private String value;
|
|
|
|
TokenTypeEnum(String value) {
|
|
this.value = value;
|
|
}
|
|
|
|
@JsonValue
|
|
public String getValue() {
|
|
return value;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return String.valueOf(value);
|
|
}
|
|
|
|
@JsonCreator
|
|
public static TokenTypeEnum fromValue(String value) {
|
|
for (TokenTypeEnum b : TokenTypeEnum.values()) {
|
|
if (b.value.equals(value)) {
|
|
return b;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
|
}
|
|
}
|
|
|
|
private TokenTypeEnum tokenType;
|
|
|
|
private Instant expiresAt;
|
|
|
|
private UserDTO user;
|
|
|
|
public SessionDTO() {
|
|
super();
|
|
}
|
|
|
|
public SessionDTO(String token, TokenTypeEnum tokenType, Instant expiresAt, UserDTO user) {
|
|
this.token = token;
|
|
this.tokenType = tokenType;
|
|
this.expiresAt = expiresAt;
|
|
this.user = user;
|
|
}
|
|
|
|
public SessionDTO token(String token) {
|
|
this.token = token;
|
|
return this;
|
|
}
|
|
|
|
@NotNull
|
|
@Size(min = 32)
|
|
@Schema(name = "token", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("token")
|
|
public String getToken() {
|
|
return token;
|
|
}
|
|
|
|
public void setToken(String token) {
|
|
this.token = token;
|
|
}
|
|
|
|
public SessionDTO tokenType(TokenTypeEnum tokenType) {
|
|
this.tokenType = tokenType;
|
|
return this;
|
|
}
|
|
|
|
@NotNull
|
|
@Schema(name = "token_type", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("token_type")
|
|
public TokenTypeEnum getTokenType() {
|
|
return tokenType;
|
|
}
|
|
|
|
public void setTokenType(TokenTypeEnum tokenType) {
|
|
this.tokenType = tokenType;
|
|
}
|
|
|
|
public SessionDTO expiresAt(Instant expiresAt) {
|
|
this.expiresAt = expiresAt;
|
|
return this;
|
|
}
|
|
|
|
@NotNull
|
|
@Valid
|
|
@Schema(name = "expires_at", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("expires_at")
|
|
public Instant getExpiresAt() {
|
|
return expiresAt;
|
|
}
|
|
|
|
public void setExpiresAt(Instant expiresAt) {
|
|
this.expiresAt = expiresAt;
|
|
}
|
|
|
|
public SessionDTO user(UserDTO user) {
|
|
this.user = user;
|
|
return this;
|
|
}
|
|
|
|
@NotNull
|
|
@Valid
|
|
@Schema(name = "user", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@JsonProperty("user")
|
|
public UserDTO getUser() {
|
|
return user;
|
|
}
|
|
|
|
public void setUser(UserDTO user) {
|
|
this.user = user;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) {
|
|
return true;
|
|
}
|
|
if (o == null || getClass() != o.getClass()) {
|
|
return false;
|
|
}
|
|
SessionDTO sessionDTO = (SessionDTO) o;
|
|
return Objects.equals(this.token, sessionDTO.token)
|
|
&& Objects.equals(this.tokenType, sessionDTO.tokenType)
|
|
&& Objects.equals(this.expiresAt, sessionDTO.expiresAt)
|
|
&& Objects.equals(this.user, sessionDTO.user);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(token, tokenType, expiresAt, user);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("class SessionDTO {\n");
|
|
sb.append(" token: ").append(toIndentedString(token)).append("\n");
|
|
sb.append(" tokenType: ").append(toIndentedString(tokenType)).append("\n");
|
|
sb.append(" expiresAt: ").append(toIndentedString(expiresAt)).append("\n");
|
|
sb.append(" user: ").append(toIndentedString(user)).append("\n");
|
|
sb.append("}");
|
|
return sb.toString();
|
|
}
|
|
|
|
private String toIndentedString(Object o) {
|
|
if (o == null) {
|
|
return "null";
|
|
}
|
|
return o.toString().replace("\n", "\n ");
|
|
}
|
|
}
|