use better responses
All checks were successful
deploy / deploy (push) Successful in 41s

This commit is contained in:
Lee
2024-04-08 06:48:21 +01:00
parent a2dfd3fc6d
commit 4b4cc8ae54
9 changed files with 57 additions and 55 deletions

View File

@ -2,6 +2,7 @@ package cc.fascinated.model.player;
import cc.fascinated.config.Config;
import cc.fascinated.util.PlayerUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
@ -33,6 +34,7 @@ public class Skin {
/**
* The skin image for the skin
*/
@JsonIgnore
private final BufferedImage skinImage;
/**

View File

@ -1,40 +0,0 @@
package cc.fascinated.model.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.micrometer.common.lang.NonNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.http.HttpStatus;
import java.util.Date;
@NoArgsConstructor
@Setter
@Getter
@ToString
public final class ErrorResponse {
/**
* The status code of this error.
*/
@NonNull
private HttpStatus status;
/**
* The message of this error.
*/
@NonNull private String message;
/**
* The timestamp this error occurred.
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private Date timestamp;
public ErrorResponse(@NonNull HttpStatus status, @NonNull String message) {
this.status = status;
this.message = message;
timestamp = new Date();
}
}

View File

@ -0,0 +1,31 @@
package cc.fascinated.model.response;
import io.micrometer.common.lang.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.servlet.function.EntityResponse;
@Getter @AllArgsConstructor
public class Response {
/**
* The status code of this error.
*/
private HttpStatus status;
/**
* The message of this error.
*/
private String message;
/**
* Gets this response as a {@link ResponseEntity}.
*
* @return the response entity
*/
public ResponseEntity<?> toResponseEntity() {
return new ResponseEntity<>(this, status);
}
}

View File

@ -0,0 +1,11 @@
package cc.fascinated.model.response.impl;
import cc.fascinated.model.response.Response;
import org.springframework.http.HttpStatus;
public class PlayerNotFoundResponse extends Response {
public PlayerNotFoundResponse() {
super(HttpStatus.NOT_FOUND, "Player not found.");
}
}