Skip to content

Commit

Permalink
Add-Migration, Set InvariantGlobalization to false for update-database.
Browse files Browse the repository at this point in the history
Register Dependencies.
  • Loading branch information
mohammadKarimi committed Jan 9, 2024
1 parent 077b6cd commit 587b51e
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/SwiftLink.Application/ConfigServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FluentValidation;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using SwiftLink.Application.Behaviors;
using SwiftLink.Application.Common;
using SwiftLink.Application.Common.Interfaces;
using System.Reflection;

namespace SwiftLink.Application;

public static class ConfigServices
{
public static IServiceCollection RegisterApplicationServices(this IServiceCollection services)
{
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
services.AddMediatR(config =>
{
config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
config.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
});

services.AddScoped<IShortCodeGenerator, TimeBasedShortCodeGenerator>();
return services;
}
}
1 change: 1 addition & 0 deletions src/SwiftLink.Application/SwiftLink.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>
Expand Down
36 changes: 36 additions & 0 deletions src/SwiftLink.Infrastructure/ConfigServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SwiftLink.Infrastructure.CacheProvider;
using SwiftLink.Infrastructure.Persistence.Context;

namespace SwiftLink.Infrastructure;

/// <summary>
/// This extention is programmed for registering Infrastructure services .
/// </summary>
public static class ConfigureServices
{
public static IServiceCollection RegisterInfrastructureServices(this IServiceCollection services,
IConfiguration configuration)
{
services.AddDbContext<IApplicationDbContext, ApplicationDbContext>(opt =>
{
opt.UseSqlServer(
configuration.GetConnectionString(nameof(ApplicationDbContext)),
(db) =>
{
db.MigrationsHistoryTable("MigrationHistory");
})
.LogTo(Console.WriteLine, LogLevel.Information);
});

services.AddSingleton<ICacheProvider, RedisCacheService>();
services.AddStackExchangeRedisCache(opt =>
{
opt.Configuration = configuration["AppSettings:RedisCacheUrl"];
});

return services;
}
}

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

113 changes: 113 additions & 0 deletions src/SwiftLink.Infrastructure/Migrations/20240109132423_Init.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SwiftLink.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "Base");

migrationBuilder.CreateTable(
name: "Subscriber",
schema: "Base",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Token = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false),
IsActive = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Base_Subscriber", x => x.Id);
},
comment: "Only these subscribers are allowed to insert a URL to obtain a shorter one.");

migrationBuilder.CreateTable(
name: "Link",
schema: "Base",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SubscriberId = table.Column<int>(type: "int", nullable: false),
ShortCode = table.Column<string>(type: "varchar(16)", unicode: false, maxLength: 16, nullable: false),
OriginalUrl = table.Column<string>(type: "varchar(1500)", unicode: false, maxLength: 1500, nullable: false),
Description = table.Column<string>(type: "varchar(250)", unicode: false, maxLength: 250, nullable: false),
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
IsBanned = table.Column<bool>(type: "bit", nullable: false),
Password = table.Column<string>(type: "varchar(25)", unicode: false, maxLength: 25, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Base_Link", x => x.Id);
table.ForeignKey(
name: "FK_Link_Subscriber_SubscriberId",
column: x => x.SubscriberId,
principalSchema: "Base",
principalTable: "Subscriber",
principalColumn: "Id");
},
comment: "Stores Original links and generated shortCode.");

migrationBuilder.CreateTable(
name: "LinkVisit",
schema: "Base",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
LinkId = table.Column<int>(type: "int", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientMetaData = table.Column<string>(type: "varchar(500)", unicode: false, maxLength: 500, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Base_LinkVisit", x => x.Id);
table.ForeignKey(
name: "FK_LinkVisit_Link_LinkId",
column: x => x.LinkId,
principalSchema: "Base",
principalTable: "Link",
principalColumn: "Id");
},
comment: "analytics, providing insights into the number of users who clicked on a shortened link.");

migrationBuilder.CreateIndex(
name: "IX_Link_SubscriberId",
schema: "Base",
table: "Link",
column: "SubscriberId");

migrationBuilder.CreateIndex(
name: "IX_LinkVisit_LinkId",
schema: "Base",
table: "LinkVisit",
column: "LinkId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LinkVisit",
schema: "Base");

migrationBuilder.DropTable(
name: "Link",
schema: "Base");

migrationBuilder.DropTable(
name: "Subscriber",
schema: "Base");
}
}
}
Loading

0 comments on commit 587b51e

Please sign in to comment.