-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(access-tokens): added endpoint and separate table for external a…
…ccess tokens
- Loading branch information
1 parent
18a5520
commit 25a3702
Showing
27 changed files
with
300 additions
and
99 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...n/java/dev/cloudeko/zenei/application/web/model/response/ExternalAccessTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dev.cloudeko.zenei.application.web.model.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import dev.cloudeko.zenei.domain.model.account.ExternalAccessToken; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RegisterForReflection | ||
@Schema(name = "External Access Token", description = "Represents an access token from an external provider") | ||
public class ExternalAccessTokenResponse { | ||
|
||
@JsonProperty("id_token") | ||
@Schema(description = "ID token") | ||
private String idToken; | ||
|
||
@JsonProperty("refresh_token") | ||
@Schema(description = "Refresh token") | ||
private String refreshToken; | ||
|
||
@JsonProperty("access_token") | ||
@Schema(description = "Access token") | ||
private String accessToken; | ||
|
||
@JsonProperty("token_type") | ||
@Schema(description = "Token type") | ||
private String tokenType; | ||
|
||
@JsonProperty("scope") | ||
@Schema(description = "Scope") | ||
private String scope; | ||
|
||
@JsonProperty("access_token_expires_at") | ||
private Long accessTokenExpiresAt; | ||
|
||
public ExternalAccessTokenResponse(ExternalAccessToken externalAccessToken) { | ||
this.idToken = externalAccessToken.getIdToken(); | ||
this.refreshToken = externalAccessToken.getRefreshToken(); | ||
this.accessToken = externalAccessToken.getAccessToken(); | ||
this.tokenType = externalAccessToken.getTokenType(); | ||
this.scope = externalAccessToken.getScope(); | ||
this.accessTokenExpiresAt = externalAccessToken.getAccessTokenExpiresAt(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../java/dev/cloudeko/zenei/application/web/model/response/ExternalAccessTokensResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.cloudeko.zenei.application.web.model.response; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
import lombok.NoArgsConstructor; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@NoArgsConstructor | ||
@RegisterForReflection | ||
@Schema(name = "External Access Token List", description = "Represents a list of external access tokens") | ||
public class ExternalAccessTokensResponse extends ArrayList<ExternalAccessTokenResponse> { | ||
|
||
public ExternalAccessTokensResponse(List<ExternalAccessTokenResponse> externalAccessTokens) { | ||
super(externalAccessTokens); | ||
} | ||
} |
14 changes: 5 additions & 9 deletions
14
...src/main/java/dev/cloudeko/zenei/application/web/model/response/PrivateUsersResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
package dev.cloudeko.zenei.application.web.model.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@RegisterForReflection | ||
@Schema(name = "Users", description = "Represents a list of users") | ||
public class PrivateUsersResponse { | ||
public class PrivateUsersResponse extends ArrayList<PrivateUserResponse> { | ||
|
||
@JsonProperty("users") | ||
@Schema(description = "A list of users") | ||
private List<PrivateUserResponse> users; | ||
public PrivateUsersResponse(List<PrivateUserResponse> users) { | ||
super(users); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/src/main/java/dev/cloudeko/zenei/domain/feature/ListExternalAccessTokens.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.cloudeko.zenei.domain.feature; | ||
|
||
import dev.cloudeko.zenei.domain.model.account.ExternalAccessToken; | ||
|
||
import java.util.List; | ||
|
||
public interface ListExternalAccessTokens { | ||
List<ExternalAccessToken> listByProvider(long userId, String provider); | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/dev/cloudeko/zenei/domain/feature/impl/ListExternalAccessTokensImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.cloudeko.zenei.domain.feature.impl; | ||
|
||
import dev.cloudeko.zenei.domain.feature.ListExternalAccessTokens; | ||
import dev.cloudeko.zenei.domain.mapping.ExternalAccessTokenMapper; | ||
import dev.cloudeko.zenei.domain.model.account.ExternalAccessToken; | ||
import dev.cloudeko.zenei.domain.model.account.ExternalAccessTokenRepository; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import lombok.AllArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@ApplicationScoped | ||
@AllArgsConstructor | ||
public class ListExternalAccessTokensImpl implements ListExternalAccessTokens { | ||
|
||
private final ExternalAccessTokenMapper externalAccessTokenMapper; | ||
private final ExternalAccessTokenRepository externalAccessTokenRepository; | ||
|
||
@Override | ||
public List<ExternalAccessToken> listByProvider(long userId, String provider) { | ||
return externalAccessTokenRepository.listByProvider(userId, provider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/java/dev/cloudeko/zenei/domain/mapping/ExternalAccessTokenMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.cloudeko.zenei.domain.mapping; | ||
|
||
import dev.cloudeko.zenei.domain.model.account.ExternalAccessToken; | ||
import dev.cloudeko.zenei.infrastructure.repository.hibernate.entity.ExternalAccessTokenEntity; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.MappingTarget; | ||
|
||
import java.util.List; | ||
|
||
@Mapper(config = QuarkusMappingConfig.class) | ||
public interface ExternalAccessTokenMapper { | ||
List<ExternalAccessToken> toDomainList(List<ExternalAccessTokenEntity> entities); | ||
|
||
ExternalAccessToken toDomain(ExternalAccessTokenEntity entity); | ||
|
||
void updateDomainFromEntity(ExternalAccessTokenEntity entity, @MappingTarget ExternalAccessToken domain); | ||
|
||
ExternalAccessTokenEntity toEntity(ExternalAccessToken domain); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/java/dev/cloudeko/zenei/domain/model/account/ExternalAccessToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.cloudeko.zenei.domain.model.account; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ExternalAccessToken { | ||
private String idToken; | ||
private String refreshToken; | ||
private String accessToken; | ||
private String tokenType; | ||
private String scope; | ||
private Long accessTokenExpiresAt; | ||
} |
8 changes: 8 additions & 0 deletions
8
.../src/main/java/dev/cloudeko/zenei/domain/model/account/ExternalAccessTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.cloudeko.zenei.domain.model.account; | ||
|
||
import java.util.List; | ||
|
||
public interface ExternalAccessTokenRepository { | ||
|
||
List<ExternalAccessToken> listByProvider(long userId, String provider); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
.../cloudeko/zenei/infrastructure/repository/hibernate/entity/ExternalAccessTokenEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,40 @@ | ||
package dev.cloudeko.zenei.infrastructure.repository.hibernate.entity; | ||
|
||
public class ExternalAccessTokenEntity { | ||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "external_access_tokens") | ||
@NamedQueries({ | ||
@NamedQuery(name = "ExternalAccessTokenEntity.listByProvider", query = "SELECT e FROM ExternalAccessTokenEntity e WHERE e.account.user.id = :user AND e.account.provider = :provider") | ||
}) | ||
public class ExternalAccessTokenEntity extends PanacheEntity { | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "external_account_id", referencedColumnName = "id", nullable = false) | ||
private ExternalAccountEntity account; | ||
|
||
@Column(name = "id_token") | ||
private String idToken; | ||
|
||
@Column(name = "refresh_token") | ||
private String refreshToken; | ||
|
||
@Column(name = "access_token") | ||
private String accessToken; | ||
|
||
@Column(name = "token_type") | ||
private String tokenType; | ||
|
||
@Column(name = "scope") | ||
private String scope; | ||
|
||
@Column(name = "access_token_expires_at") | ||
private Long accessTokenExpiresAt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.