Skip to content

Commit

Permalink
Implemented Region, Generation & Type synchronization. (#4)
Browse files Browse the repository at this point in the history
* Implemented Region synchronization.

* Implemented Region, Generation & Type synchronization.
  • Loading branch information
Utar94 authored Dec 29, 2023
1 parent bdd9b71 commit a5bd4ee
Show file tree
Hide file tree
Showing 36 changed files with 1,223 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Implemented Pokémon species import.
- CI/CD build pipeline.
- Implemented Region, Generation & Type synchronization.
13 changes: 12 additions & 1 deletion PokeData.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PokeData.EntityFrameworkCor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PokeData", "src\PokeData\PokeData.csproj", "{C90A7D50-2763-4345-9CFD-5EF3F05B6388}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokeData.ETL", "src\PokeData.ETL\PokeData.ETL.csproj", "{9155019E-35B2-471D-B227-F1AEA104ECE8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PokeData.ETL", "src\PokeData.ETL\PokeData.ETL.csproj", "{9155019E-35B2-471D-B227-F1AEA104ECE8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{6017B644-B8B7-422A-8D1F-049300B7C42E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokeData.Tools.Synchronization", "tools\PokeData.Tools.Synchronization\PokeData.Tools.Synchronization.csproj", "{90AF9D86-E895-4B77-B7C5-36760B619EB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -74,10 +78,17 @@ Global
{9155019E-35B2-471D-B227-F1AEA104ECE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9155019E-35B2-471D-B227-F1AEA104ECE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9155019E-35B2-471D-B227-F1AEA104ECE8}.Release|Any CPU.Build.0 = Release|Any CPU
{90AF9D86-E895-4B77-B7C5-36760B619EB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90AF9D86-E895-4B77-B7C5-36760B619EB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90AF9D86-E895-4B77-B7C5-36760B619EB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90AF9D86-E895-4B77-B7C5-36760B619EB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{90AF9D86-E895-4B77-B7C5-36760B619EB8} = {6017B644-B8B7-422A-8D1F-049300B7C42E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AE600868-6420-4204-8CA6-35B3E1C0CEC9}
EndGlobalSection
Expand Down
24 changes: 19 additions & 5 deletions src/PokeData.Domain/Resources/ResourceId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ namespace PokeData.Domain.Resources;

public record ResourceId
{
private const char Separator = ':';

public AggregateId AggregateId { get; }

public string Type { get; }
public string Identifier { get; }

public ResourceId(AggregateId aggregateId)
{
AggregateId = aggregateId;

string[] parts = aggregateId.Value.Split(Separator);
if (parts.Length != 2)
{
throw new ArgumentException($"The value '{aggregateId}' is not a valid resource identifier.", nameof(aggregateId));
}
Type = parts[0];
Identifier = parts[1];
}

public static ResourceId Create<T>(string identifier)
private ResourceId(string type, string identifier)
{
string value = string.Join(':', new[] { typeof(T).Name, identifier });
AggregateId aggregateId = new(value);

return new ResourceId(aggregateId);
AggregateId = new(string.Join(Separator, type, identifier));
Type = type;
Identifier = identifier;
}

public static ResourceId Create<T>(string identifier) => new(typeof(T).Name, identifier);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace PokeData.EntityFrameworkCore.PostgreSQL.Migrations
{
/// <inheritdoc />
public partial class CreateRegionTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Regions",
columns: table => new
{
RegionId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UniqueName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
DisplayName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Regions", x => x.RegionId);
});

migrationBuilder.CreateIndex(
name: "IX_Regions_DisplayName",
table: "Regions",
column: "DisplayName");

migrationBuilder.CreateIndex(
name: "IX_Regions_UniqueName",
table: "Regions",
column: "UniqueName",
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Regions");
}
}
}
Loading

0 comments on commit a5bd4ee

Please sign in to comment.