-
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.
- Loading branch information
Showing
58 changed files
with
1,943 additions
and
289 deletions.
There are no files selected for viewing
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
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
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
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
This file was deleted.
Oops, something went wrong.
49 changes: 44 additions & 5 deletions
49
.../20231017125833_InitialCreate.Designer.cs → .../20231021080634_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,75 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace App.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class InitialCreate : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Users", | ||
columns: table => new | ||
{ | ||
Id = table.Column<string>(type: "text", nullable: false), | ||
Username = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Users", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Tokens", | ||
columns: table => new | ||
{ | ||
Id = table.Column<Guid>(type: "uuid", nullable: false), | ||
Name = table.Column<string>(type: "text", nullable: false), | ||
ApiToken = table.Column<string>(type: "text", nullable: false), | ||
Revoked = table.Column<bool>(type: "boolean", nullable: false), | ||
UserId = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Tokens", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_Tokens_Users_UserId", | ||
column: x => x.UserId, | ||
principalTable: "Users", | ||
principalColumn: "Id", | ||
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Tokens_ApiToken", | ||
table: "Tokens", | ||
column: "ApiToken", | ||
unique: true); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Tokens_UserId", | ||
table: "Tokens", | ||
column: "UserId"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Users_Username", | ||
table: "Users", | ||
column: "Username", | ||
unique: true); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Tokens"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "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
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
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
using CSharp_Result; | ||
using Domain.Model; | ||
|
||
namespace App.Modules.Users.API.V1; | ||
|
||
public static class TokenMapper | ||
{ | ||
public static TokenRecord ToRecord(this CreateTokenReq req) => | ||
new() { Name = req.Name, Revoked = false, }; | ||
|
||
public static TokenRecord ToRecord(this UpdateTokenReq req) => | ||
new() { Name = req.Name, Revoked = false, }; | ||
|
||
public static TokenPrincipalResp ToResp(this TokenPrincipal token) => | ||
new(token.Id, token.Record.Name); | ||
|
||
public static TokenOTPrincipalResp ToOTResp(this TokenPrincipal token) => | ||
new(token.Id, token.Record.Name, token.Property.ApiToken); | ||
|
||
public static TokenOTResp ToOTResp(this Token token) => | ||
new(token.Principal.ToOTResp(), token.UserPrincipal.ToResp()); | ||
|
||
public static TokenResp ToResp(this Token token) => | ||
new(token.Principal.ToResp(), token.UserPrincipal.ToResp()); | ||
} |
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 @@ | ||
namespace App.Modules.Users.API.V1; | ||
|
||
public record CreateTokenReq(string Name); | ||
|
||
public record UpdateTokenReq(string Name); | ||
|
||
public record TokenPrincipalResp(Guid Id, string Name); | ||
|
||
/** | ||
* One Time Token, only first time on creation | ||
*/ | ||
public record TokenOTPrincipalResp(Guid Id, string Name, string ApiKey); | ||
|
||
/** | ||
* One time Token with owner, only first time on creation | ||
*/ | ||
public record TokenOTResp(TokenOTPrincipalResp Token, UserPrincipalResp Owner); | ||
|
||
public record TokenResp(TokenPrincipalResp Token, UserPrincipalResp Owner); |
Oops, something went wrong.