Skip to content

Commit

Permalink
Added UserLnurlAuthKey
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Jan 17, 2024
1 parent d62058d commit b6b70cd
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -18,6 +17,7 @@

import static jakarta.persistence.EnumType.STRING;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PACKAGE;

/**
* Application user.
Expand All @@ -26,10 +26,10 @@
@Setter
@ToString
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@AllArgsConstructor(access = PACKAGE)
@Builder
@Entity
@Table(name = "APPLICATION_USER")
@Table(name = "USER")
public class User extends BaseDomain {

/** Unique identifier. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.royllo.explorer.core.domain.user;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import static jakarta.persistence.FetchType.EAGER;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PACKAGE;

/**
* Public key generated by the user's Lightning wallet.
* This key is unique to each user and service combination, ensuring that the user's identity is consistent with each service but not across different services.
*/
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@AllArgsConstructor(access = PACKAGE)
@Builder
@Entity
@Table(name = "APPLICATION_USER_LNURL_AUTH_LINKING_KEY")
public class UserLnurlAuthKey {

/** Unique identifier. */
@Id
@Column(name = "ID")
@GeneratedValue(strategy = IDENTITY)
private Long id;

/** User. */
@ManyToOne(fetch = EAGER)
@JoinColumn(name = "FK_USER_OWNER", nullable = false)
private User owner;

/** Linking key. */
@Column(name = "LINKING_KEY", nullable = false)
private String linkingKey;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.royllo.explorer.core.dto.user;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
import org.royllo.explorer.core.domain.user.User;

import static lombok.AccessLevel.PRIVATE;

/**
* Public key generated by the user's Lightning wallet.
* This key is unique to each user and service combination, ensuring that the user's identity is consistent with each service but not across different services.
*/
@Value
@Builder
@AllArgsConstructor(access = PRIVATE)
public class UserLnurlAuthKeyDTO {

/** Unique identifier. */
Long id;

/** Linking key owner. */
@NotNull(message = "User owner is required")
User owner;

/** Linking key. */
@NotBlank(message = "Linking key is mandatory")
String linkingKey;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.royllo.explorer.core.util.mapper;

import org.mapstruct.Mapper;
import org.royllo.explorer.core.domain.user.UserLnurlAuthKey;
import org.royllo.explorer.core.dto.user.UserLnurlAuthKeyDTO;

import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE;

/**
* User LNURL auth key related mapper.
*/
@Mapper(nullValuePropertyMappingStrategy = IGNORE,
uses = {UserMapper.class})
public interface UserLnurlAuthKeyMapper {

UserLnurlAuthKey mapToUserLnurlAuthKey(UserLnurlAuthKeyDTO source);

UserLnurlAuthKeyDTO mapToUserLnurlAuthKeyDTO(UserLnurlAuthKey source);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<changeSet author="straumat" id="1.0.0-table-constraints-application_user">
<changeSet author="straumat" id="1.0.0-table-constraints-application_user_lnurl_auth_linking_key">

<!-- Foreign key FK_USER > USER.ID -->
<addForeignKeyConstraint constraintName="FOREIGN_KEY_APPLICATION_USER_LNURL_AUTH_LINKING_KEY_USER_OWNER"
baseColumnNames="FK_USER_OWNER"
baseTableName="APPLICATION_USER_LNURL_AUTH_LINKING_KEY"
referencedTableName="APPLICATION_USER"
referencedColumnNames="ID"/>

</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<changeSet author="straumat" id="1.0.0-table-constraints-application_user">

</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<changeSet author="straumat" id="1.0.0-table-application_user_lnurl_auth_linking_key">

<createTable tableName="APPLICATION_USER_LNURL_AUTH_LINKING_KEY"
remarks="Public key generated by the user's Lightning wallet">

<!-- Unique identifier -->
<column name="ID" type="BIGINT"
remarks="Unique identifier">
<constraints nullable="false" primaryKey="true"
primaryKeyName="PRIMARY_KEY_APPLICATION_USER_LNURL_AUTH_LINKING_KEY"/>
</column>

<!-- Table fields -->
<column name="LINKING_KEY" type="VARCHAR(255)"
remarks="Public key generated by the user's Lightning wallet">
<constraints nullable="false" unique="true"
uniqueConstraintName="UNIQUE_APPLICATION_USER_LINKING_KEY"/>
</column>
<column name="FK_USER_OWNER" type="BIGINT"
remarks="The user who owns this linking key">
<constraints nullable="false"/>
</column>

<!-- Technical fields -->
<column name="CREATED_ON" type="TIMESTAMP"
remarks="Data created on"/>
<column name="UPDATED_ON" type="TIMESTAMP"
remarks="Data updated on"/>

</createTable>

<!-- Auto increment on the unique identifier -->
<addAutoIncrement tableName="APPLICATION_USER_LNURL_AUTH_LINKING_KEY"
columnName="ID"
columnDataType="BIGINT"
startWith="2"/>

<!-- Index on FK_USER_OWNER -->
<createIndex indexName="INDEX_APPLICATION_USER_LNURL_AUTH_LINKING_KEY_FK_USER_OWNER"
tableName="APPLICATION_USER_LNURL_AUTH_LINKING_KEY">
<column name="FK_USER_OWNER"/>
</createIndex>

<!-- Index on LINKING_KEY -->
<createIndex indexName="INDEX_APPLICATION_USER_LNURL_AUTH_LINKING_KEY_LINKING_KEY"
tableName="APPLICATION_USER_LNURL_AUTH_LINKING_KEY">
<column name="LINKING_KEY"/>
</createIndex>

</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ databaseChangeLog:

# Users.
- include:
file: /db/changelog/1.0.0/table/table-application_user.xml
file:
/db/changelog/1.0.0/table/table-application_user.xml
- include:
file:
/db/changelog/1.0.0/table/table-application_user_lnurl_auth_linking_key.xml

# Assets.
- include:
Expand Down Expand Up @@ -45,6 +49,8 @@ databaseChangeLog:
file: /db/changelog/1.0.0/table-constraints/table-constraints-bitcoin_transaction_output.xml
- include:
file: /db/changelog/1.0.0/table-constraints/table-constraints-application_user.xml
- include:
file: /db/changelog/1.0.0/table-constraints/table-constraints-application_user_lnurl_auth_linking_key.xml
- include:
file: /db/changelog/1.0.0/table-constraints/table-constraints-universe_server.xml
- include:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<changeSet author="straumat" id="test-data-user">

<!-- straumat user -->
<insert tableName="USER">
<column name="ID" value="2"/>
<column name="USER_ID" value="22222222-2222-2222-2222-222222222222"/>
<column name="USERNAME" value="straumat"/>
<column name="ROLE" value="ADMINISTRATOR"/>
<column name="CREATED_ON"/>
<column name="UPDATED_ON"/>
</insert>

</changeSet>
</databaseChangeLog>

0 comments on commit b6b70cd

Please sign in to comment.