changed formatter
This commit is contained in:
@@ -2,4 +2,5 @@ package com.vaessl.app.connection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record AuthResponse(String serviceType, Instant expiresAt) {}
|
||||
public record AuthResponse(String serviceType, Instant expiresAt) {
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ public class ConnectionController {
|
||||
private final ConnectionService connectionService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<AuthResponse> login(
|
||||
@Valid @RequestBody ConnectionRequest request,
|
||||
public ResponseEntity<AuthResponse> login(@Valid @RequestBody ConnectionRequest request,
|
||||
HttpServletRequest httpReq) {
|
||||
|
||||
LoginResult result = connectionService.login(request);
|
||||
@@ -53,21 +52,21 @@ public class ConnectionController {
|
||||
}
|
||||
|
||||
List<ConnectionStatusResponse> statuses = new ArrayList<>();
|
||||
Collections.list(session.getAttributeNames()).stream()
|
||||
.filter(k -> k.endsWith(SUFFIX))
|
||||
Collections.list(session.getAttributeNames()).stream().filter(k -> k.endsWith(SUFFIX))
|
||||
.forEach(k -> {
|
||||
String serviceType = k.replace(SUFFIX, "");
|
||||
Long id = (Long) session.getAttribute(k);
|
||||
ConnectionStatusResponse status = connectionService.getConnectionStatus(serviceType, id);
|
||||
if (status != null) statuses.add(status);
|
||||
ConnectionStatusResponse status =
|
||||
connectionService.getConnectionStatus(serviceType, id);
|
||||
if (status != null)
|
||||
statuses.add(status);
|
||||
});
|
||||
|
||||
return ResponseEntity.ok(statuses);
|
||||
}
|
||||
|
||||
@DeleteMapping("/connections/{serviceType}")
|
||||
public ResponseEntity<Void> logout(
|
||||
@PathVariable("serviceType") String serviceType,
|
||||
public ResponseEntity<Void> logout(@PathVariable("serviceType") String serviceType,
|
||||
HttpServletRequest httpReq) {
|
||||
|
||||
HttpSession session = httpReq.getSession(false);
|
||||
|
||||
@@ -14,7 +14,8 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "connections", uniqueConstraints = { @UniqueConstraint(columnNames = { "appUrl", "username" }) })
|
||||
@Table(name = "connections",
|
||||
uniqueConstraints = {@UniqueConstraint(columnNames = {"appUrl", "username"})})
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "service_type")
|
||||
@Getter
|
||||
|
||||
@@ -4,12 +4,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ConnectionRequest(
|
||||
@NotBlank(message = "App URL is mandatory") String appUrl,
|
||||
public record ConnectionRequest(@NotBlank(message = "App URL is mandatory") String appUrl,
|
||||
@NotBlank(message = "Service type is mandatory") String serviceType,
|
||||
String username,
|
||||
String password,
|
||||
String apiKey,
|
||||
String username, String password, String apiKey,
|
||||
@JsonProperty(defaultValue = "false") Boolean stayLoggedIn) {
|
||||
|
||||
public ConnectionRequest {
|
||||
@@ -18,8 +15,8 @@ public record ConnectionRequest(
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionRequest(String appUrl, String serviceType, String username, String password,
|
||||
Boolean stayLoggedIn) {
|
||||
public ConnectionRequest(String appUrl, String serviceType, String username,
|
||||
String password, Boolean stayLoggedIn) {
|
||||
this(appUrl, serviceType, username, password, null, stayLoggedIn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ package com.vaessl.app.connection;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
public record ConnectionResponse(String token, Instant expiresAt, Map<String, Object> extraResponseData) {
|
||||
|
||||
public record ConnectionResponse(String token, Instant expiresAt,
|
||||
Map<String, Object> extraResponseData) {
|
||||
|
||||
public String getExtraVar(String key) {
|
||||
if(extraResponseData == null) {
|
||||
if (extraResponseData == null) {
|
||||
return null;
|
||||
} else {
|
||||
Object value = extraResponseData.get(key);
|
||||
|
||||
@@ -50,13 +50,14 @@ public class ConnectionService {
|
||||
|
||||
public ConnectionStatusResponse getConnectionStatus(String serviceType, Long connectionId) {
|
||||
ConnectionEntity entity = cRepository.findById(connectionId).orElse(null);
|
||||
if (entity == null) return null;
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
ConnectionProvider provider = providerRegistry.get(serviceType);
|
||||
Instant expiresAt = (provider != null) ? provider.getTokenExpiry(entity) : null;
|
||||
boolean connected = expiresAt == null || expiresAt.isAfter(Instant.now());
|
||||
|
||||
return new ConnectionStatusResponse(serviceType, entity.getAppUrl(),
|
||||
entity.getUsername(), expiresAt, connected);
|
||||
return new ConnectionStatusResponse(serviceType, entity.getAppUrl(), entity.getUsername(),
|
||||
expiresAt, connected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.vaessl.app.connection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record ConnectionStatusResponse(
|
||||
String serviceType,
|
||||
String appUrl,
|
||||
String username,
|
||||
Instant expiresAt,
|
||||
boolean connected) {}
|
||||
public record ConnectionStatusResponse(String serviceType, String appUrl, String username,
|
||||
Instant expiresAt, boolean connected) {
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.vaessl.app.connection;
|
||||
|
||||
public enum Endpoint {
|
||||
HOMEBOX_LOGIN("/api/v1/users/login"),
|
||||
LOGIN("/login"),
|
||||
CONNECTION_STATUS("/connections/status");
|
||||
HOMEBOX_LOGIN("/api/v1/users/login"), LOGIN("/login"), CONNECTION_STATUS("/connections/status");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
||||
@@ -2,4 +2,5 @@ package com.vaessl.app.connection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record LoginResult(Long connectionId, Instant expiresAt) {}
|
||||
public record LoginResult(Long connectionId, Instant expiresAt) {
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public enum ServiceType {
|
||||
|
||||
private final String value;
|
||||
|
||||
private ServiceType(String value){
|
||||
private ServiceType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user