View Javadoc
1   package de.dlr.shepard.auth.apikey.io;
2   
3   import com.fasterxml.jackson.annotation.JsonFormat;
4   import de.dlr.shepard.auth.apikey.entities.ApiKey;
5   import jakarta.validation.constraints.NotBlank;
6   import java.util.Date;
7   import java.util.UUID;
8   import lombok.Data;
9   import lombok.NoArgsConstructor;
10  import org.eclipse.microprofile.openapi.annotations.media.Schema;
11  
12  @Data
13  @NoArgsConstructor
14  @Schema(name = "ApiKey")
15  public class ApiKeyIO {
16  
17    @Schema(readOnly = true, required = true)
18    private UUID uid;
19  
20    @NotBlank
21    @Schema(required = true)
22    private String name;
23  
24    @JsonFormat(shape = JsonFormat.Shape.STRING)
25    @Schema(readOnly = true, required = true, format = "date-time", example = "2024-08-15T11:18:44.632+00:00")
26    private Date createdAt;
27  
28    @Schema(readOnly = true, required = true)
29    private String belongsTo;
30  
31    public ApiKeyIO(ApiKey key) {
32      this.uid = key.getUid();
33      this.name = key.getName();
34      this.createdAt = key.getCreatedAt();
35      this.belongsTo = key.getBelongsTo() != null ? key.getBelongsTo().getUsername() : null;
36    }
37  }