Merge remote-tracking branch 'origin/master' into feature/update-current-user
# Conflicts: # src/Infrastructure/Data/ApplicationDbContextInitializer.cs
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
using Google.Apis.Oauth2.v2.Data;
|
using Google.Apis.Oauth2.v2.Data;
|
||||||
using Hutopy.Application.Common.Models;
|
using Hutopy.Application.Common.Models;
|
||||||
using Hutopy.Application.Users.Models;
|
|
||||||
|
|
||||||
namespace Hutopy.Application.Common.Interfaces;
|
namespace Hutopy.Application.Common.Interfaces;
|
||||||
|
|
||||||
public interface IIdentityService
|
public interface IIdentityService
|
||||||
{
|
{
|
||||||
Task<Result<string>> CreateUserAsync(Userinfo userInfo);
|
Task<Result<string>> CreateUserAsync(Userinfo userInfo);
|
||||||
Task<Result<string>> CreateUserAsync(string email, string userName, string firstName, string lastName, string password);
|
|
||||||
|
Task<Result<string>> CreateUserAsync(string email, string userName, string firstName, string lastName,
|
||||||
|
string password);
|
||||||
|
|
||||||
Task<UserModel?> GetCurrentUserAsync();
|
Task<UserModel?> GetCurrentUserAsync();
|
||||||
Task<Result> UpdateCurrentUserBannerPictureUrlAsync(string url);
|
Task<Result> UpdateCurrentUserBannerPictureUrlAsync(string url);
|
||||||
Task<Result> UpdateCurrentUserProfilePictureUrlAsync(string url);
|
Task<Result> UpdateCurrentUserProfilePictureUrlAsync(string url);
|
||||||
@@ -15,6 +17,7 @@ public interface IIdentityService
|
|||||||
Task<Result<string>> UpdateCurrentUserAsync(UserModel userModel);
|
Task<Result<string>> UpdateCurrentUserAsync(UserModel userModel);
|
||||||
Task<IList<string>> GetCurrentUserRolesAsync();
|
Task<IList<string>> GetCurrentUserRolesAsync();
|
||||||
Task<UserModel?> FindUserByIdAsync(string id);
|
Task<UserModel?> FindUserByIdAsync(string id);
|
||||||
|
Task<UserModel?> FindUserByCreatorAliasAsync(string creatorAlias, CancellationToken cancellationToken);
|
||||||
Task<UserModel?> FindUserByEmailAsync(string email);
|
Task<UserModel?> FindUserByEmailAsync(string email);
|
||||||
Task<UserModel?> GetUserByUserNameAsync(string userName);
|
Task<UserModel?> GetUserByUserNameAsync(string userName);
|
||||||
Task<string?> LoginAsync(string email, string password);
|
Task<string?> LoginAsync(string email, string password);
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
public abstract class Roles
|
public abstract class Roles
|
||||||
{
|
{
|
||||||
public const string Administrator = nameof(Administrator);
|
public const string Administrator = nameof(Administrator);
|
||||||
|
public const string Creator = nameof(Creator);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using Hutopy.Domain.Constants;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Hutopy.Domain.Constants;
|
|
||||||
using Hutopy.Infrastructure.Identity;
|
using Hutopy.Infrastructure.Identity;
|
||||||
|
using Hutopy.Infrastructure.Identity.OwnedEntities;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -28,7 +26,7 @@ public static class InitializerExtensions
|
|||||||
public class ApplicationDbContextInitializer(
|
public class ApplicationDbContextInitializer(
|
||||||
ILogger<ApplicationDbContextInitializer> logger,
|
ILogger<ApplicationDbContextInitializer> logger,
|
||||||
ApplicationDbContext context,
|
ApplicationDbContext context,
|
||||||
UserManager<ApplicationUser> userManager,
|
ApplicationUserManager userManager,
|
||||||
RoleManager<IdentityRole> roleManager)
|
RoleManager<IdentityRole> roleManager)
|
||||||
{
|
{
|
||||||
public async Task InitialiseAsync()
|
public async Task InitialiseAsync()
|
||||||
@@ -61,27 +59,57 @@ public class ApplicationDbContextInitializer(
|
|||||||
{
|
{
|
||||||
// Default roles
|
// Default roles
|
||||||
var administratorRole = new IdentityRole(Roles.Administrator);
|
var administratorRole = new IdentityRole(Roles.Administrator);
|
||||||
|
|
||||||
if (roleManager.Roles.All(r => r.Name != administratorRole.Name))
|
if (roleManager.Roles.All(r => r.Name != administratorRole.Name))
|
||||||
{
|
{
|
||||||
await roleManager.CreateAsync(administratorRole);
|
await roleManager.CreateAsync(administratorRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default users
|
var roleCreator = new IdentityRole(Roles.Creator);
|
||||||
var administrator = new ApplicationUser
|
if (roleManager.Roles.All(r => r.Name != roleCreator.Name))
|
||||||
{
|
{
|
||||||
UserName = "administrator@localhost",
|
await roleManager.CreateAsync(roleCreator);
|
||||||
Email = "administrator@localhost",
|
}
|
||||||
PortraitUrl = "images/usersmedia/anonyme/profilepictures/profilePascal.jpg"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Default users
|
||||||
|
var administrator =
|
||||||
|
new ApplicationUser { UserName = "administrator@localhost", Email = "administrator@localhost" };
|
||||||
if (userManager.Users.All(u => u.UserName != administrator.UserName))
|
if (userManager.Users.All(u => u.UserName != administrator.UserName))
|
||||||
{
|
{
|
||||||
await userManager.CreateAsync(administrator, "Administrator1!");
|
await userManager.CreateAsync(administrator, "Administrator1!");
|
||||||
if (!string.IsNullOrWhiteSpace(administratorRole.Name))
|
await userManager.AddToRolesAsync(administrator, new[] { Roles.Administrator });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADD CREATORS
|
||||||
|
await AddDefaultCreator(new ApplicationUser
|
||||||
|
{
|
||||||
|
UserName = "hutopy@localhost",
|
||||||
|
Email = "hutopy@localhost",
|
||||||
|
CreatorAlias = "hutopy",
|
||||||
|
About = "Page officielle",
|
||||||
|
Description = "Site officiel pour Hutopy. Venez-nous-y retrouver avec tous vos fans!",
|
||||||
|
EmailConfirmed = true,
|
||||||
|
ProfileColors = new ProfileColors { BannerTop = "A30E79", BannerBottom = "6B0065", Accent = "23393B", Menu = "53B93B", },
|
||||||
|
SocialNetworks =
|
||||||
|
new SocialNetworks
|
||||||
|
{
|
||||||
|
XUrl = "https://twitter.com/Hutopyinc",
|
||||||
|
FacebookUrl = "https://www.facebook.com/Hutopy",
|
||||||
|
InstagramUrl = "https://www.instagram.com/hutopy.inc/"
|
||||||
|
},
|
||||||
|
StoredDataUrls = new StoredDataUrls
|
||||||
{
|
{
|
||||||
await userManager.AddToRolesAsync(administrator, new[] { administratorRole.Name });
|
BannerPictureUrl = "/images/usersmedia/HutopyProfile/banners/banner01.png",
|
||||||
|
ProfilePictureUrl = "/images/usersmedia/HutopyProfile/profilepictures/profileHutopyProfile01.png"
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddDefaultCreator(ApplicationUser hutopy)
|
||||||
|
{
|
||||||
|
if (userManager.Users.All(u => u.UserName != hutopy.UserName))
|
||||||
|
{
|
||||||
|
await userManager.CreateAsync(hutopy, "Test123!");
|
||||||
|
await userManager.AddToRolesAsync(hutopy, new[] { Roles.Creator });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
services
|
services
|
||||||
.AddIdentityCore<ApplicationUser>()
|
.AddIdentityCore<ApplicationUser>()
|
||||||
|
.AddUserManager<ApplicationUserManager>()
|
||||||
.AddRoles<IdentityRole>()
|
.AddRoles<IdentityRole>()
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||||
.AddApiEndpoints()
|
.AddApiEndpoints()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class ApplicationUser : IdentityUser
|
|||||||
{
|
{
|
||||||
public string FirstName { get; set; } = string.Empty;
|
public string FirstName { get; set; } = string.Empty;
|
||||||
public string LastName { get; set; } = string.Empty;
|
public string LastName { get; set; } = string.Empty;
|
||||||
|
public string? CreatorAlias { get; set; }
|
||||||
public string Occupation { get; set; } = string.Empty;
|
public string Occupation { get; set; } = string.Empty;
|
||||||
public string BirthDate { get; set; } = string.Empty;
|
public string BirthDate { get; set; } = string.Empty;
|
||||||
public string Country { get; set; } = string.Empty;
|
public string Country { get; set; } = string.Empty;
|
||||||
|
|||||||
42
src/Infrastructure/Identity/ApplicationUserManager.cs
Normal file
42
src/Infrastructure/Identity/ApplicationUserManager.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace Hutopy.Infrastructure.Identity;
|
||||||
|
|
||||||
|
public sealed class ApplicationUserManager(
|
||||||
|
IUserStore<ApplicationUser> store,
|
||||||
|
IOptions<IdentityOptions> optionsAccessor,
|
||||||
|
IPasswordHasher<ApplicationUser> passwordHasher,
|
||||||
|
IEnumerable<IUserValidator<ApplicationUser>> userValidators,
|
||||||
|
IEnumerable<IPasswordValidator<ApplicationUser>> passwordValidators,
|
||||||
|
ILookupNormalizer keyNormalizer,
|
||||||
|
IdentityErrorDescriber errors,
|
||||||
|
IServiceProvider services,
|
||||||
|
ILogger<UserManager<ApplicationUser>> logger)
|
||||||
|
: UserManager<ApplicationUser>(
|
||||||
|
store,
|
||||||
|
optionsAccessor,
|
||||||
|
passwordHasher,
|
||||||
|
userValidators,
|
||||||
|
passwordValidators,
|
||||||
|
keyNormalizer,
|
||||||
|
errors,
|
||||||
|
services,
|
||||||
|
logger)
|
||||||
|
{
|
||||||
|
public async Task<ApplicationUser?> FindByCreatorAliasAsync(string creatorAlias,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentException.ThrowIfNullOrEmpty(creatorAlias);
|
||||||
|
ThrowIfDisposed();
|
||||||
|
|
||||||
|
var user = await Users.SingleOrDefaultAsync(u => EF.Functions.Like(
|
||||||
|
creatorAlias,
|
||||||
|
u.CreatorAlias),
|
||||||
|
cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
namespace Hutopy.Infrastructure.Identity;
|
namespace Hutopy.Infrastructure.Identity;
|
||||||
|
|
||||||
public class IdentityService(
|
public class IdentityService(
|
||||||
UserManager<ApplicationUser> userManager,
|
ApplicationUserManager userManager,
|
||||||
SignInManager<ApplicationUser> signInManager,
|
SignInManager<ApplicationUser> signInManager,
|
||||||
IUserClaimsPrincipalFactory<ApplicationUser> userClaimsPrincipalFactory,
|
IUserClaimsPrincipalFactory<ApplicationUser> userClaimsPrincipalFactory,
|
||||||
IAuthorizationService authorizationService,
|
IAuthorizationService authorizationService,
|
||||||
@@ -167,10 +167,28 @@ public class IdentityService(
|
|||||||
|
|
||||||
public async Task<UserModel?> FindUserByIdAsync(string id)
|
public async Task<UserModel?> FindUserByIdAsync(string id)
|
||||||
{
|
{
|
||||||
var response = await userManager.FindByIdAsync(id);
|
var user = await userManager.FindByIdAsync(id);
|
||||||
|
|
||||||
if (response == null) return null;
|
if (user == null) return null;
|
||||||
|
|
||||||
|
var userModel = BuildModelFrom(user);
|
||||||
|
|
||||||
|
return userModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserModel?> FindUserByCreatorAliasAsync(string creatorAlias, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var user = await userManager.FindByCreatorAliasAsync(creatorAlias, cancellationToken);
|
||||||
|
|
||||||
|
if (user == null) return null;
|
||||||
|
|
||||||
|
var userModel = BuildModelFrom(user);
|
||||||
|
|
||||||
|
return userModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UserModel BuildModelFrom(ApplicationUser response)
|
||||||
|
{
|
||||||
var userModel = new UserModel
|
var userModel = new UserModel
|
||||||
{
|
{
|
||||||
Id = response.Id,
|
Id = response.Id,
|
||||||
@@ -211,7 +229,6 @@ public class IdentityService(
|
|||||||
WebsiteIconUrl = response.StoredDataUrls.WebsiteIconUrl,
|
WebsiteIconUrl = response.StoredDataUrls.WebsiteIconUrl,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return userModel;
|
return userModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
560
src/Infrastructure/Migrations/20240702055858_AddCreatorAliasTouser.Designer.cs
generated
Normal file
560
src/Infrastructure/Migrations/20240702055858_AddCreatorAliasTouser.Designer.cs
generated
Normal file
@@ -0,0 +1,560 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Hutopy.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Hutopy.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
|
[Migration("20240702055858_AddCreatorAliasTouser")]
|
||||||
|
partial class AddCreatorAliasTouser
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Domain.Entities.FutureCreator", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("Created")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("CreatedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("EmailAddress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("LastModified")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("LastModifiedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ReasonToJoin")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("SocialNetworkAccount")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("FutureCreators");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Domain.Entities.UserTransaction", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<decimal>("Amount")
|
||||||
|
.HasPrecision(18, 2)
|
||||||
|
.HasColumnType("decimal(18,2)");
|
||||||
|
|
||||||
|
b.Property<string>("ApplicationUserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("Created")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("CreatedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Currency")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsConfirmed")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("LastModified")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("LastModifiedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<bool>("Paid")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("StripeBillingDetailEmail")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripeBillingDetailName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripeChargeId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripeEventId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripePaymentIntent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripePaymentMethod")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("StripeReceiptUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("TipMessage")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ApplicationUserId");
|
||||||
|
|
||||||
|
b.ToTable("UserTransactions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Infrastructure.Identity.ApplicationUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("About")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("AccessFailedCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Address")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("BirthDate")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("City")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Country")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("CreatorAlias")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailConfirmed")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<bool>("LockoutEnabled")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedEmail")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedUserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Occupation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<bool>("PhoneNumberConfirmed")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityStamp")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<bool>("TwoFactorEnabled")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedEmail")
|
||||||
|
.HasDatabaseName("EmailIndex");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedUserName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("UserNameIndex")
|
||||||
|
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUsers", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("nvarchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("RoleNameIndex")
|
||||||
|
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoles", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoleClaims", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserClaims", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderKey")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderDisplayName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.HasKey("LoginProvider", "ProviderKey");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserLogins", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserRoles", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "LoginProvider", "Name");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserTokens", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Domain.Entities.UserTransaction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hutopy.Infrastructure.Identity.ApplicationUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ApplicationUserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Infrastructure.Identity.ApplicationUser", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("Hutopy.Infrastructure.Identity.OwnedEntities.ProfileColors", "ProfileColors", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("ApplicationUserId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b1.Property<string>("Accent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("BannerBottom")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("BannerTop")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("Menu")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.HasKey("ApplicationUserId");
|
||||||
|
|
||||||
|
b1.ToTable("ApplicationUser_ProfileColors", (string)null);
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ApplicationUserId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.OwnsOne("Hutopy.Infrastructure.Identity.OwnedEntities.SocialNetworks", "SocialNetworks", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("ApplicationUserId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b1.Property<string>("FacebookUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("InstagramUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("LinkedInUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("RedditUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("TikTokUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("XUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("YourWebsiteUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("YoutubeUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.HasKey("ApplicationUserId");
|
||||||
|
|
||||||
|
b1.ToTable("ApplicationUser_SocialNetworks", (string)null);
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ApplicationUserId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.OwnsOne("Hutopy.Infrastructure.Identity.OwnedEntities.StoredDataUrls", "StoredDataUrls", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("ApplicationUserId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b1.Property<string>("BannerPictureUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("ProfilePictureUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.Property<string>("WebsiteIconUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b1.HasKey("ApplicationUserId");
|
||||||
|
|
||||||
|
b1.ToTable("ApplicationUser_StoredDataUrls", (string)null);
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ApplicationUserId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("ProfileColors")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("SocialNetworks")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("StoredDataUrls")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hutopy.Infrastructure.Identity.ApplicationUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hutopy.Infrastructure.Identity.ApplicationUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Hutopy.Infrastructure.Identity.ApplicationUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hutopy.Infrastructure.Identity.ApplicationUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Hutopy.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddCreatorAliasTouser : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "CreatorAlias",
|
||||||
|
table: "AspNetUsers",
|
||||||
|
type: "nvarchar(max)",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CreatorAlias",
|
||||||
|
table: "AspNetUsers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -176,6 +176,9 @@ namespace Hutopy.Infrastructure.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("CreatorAlias")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace Hutopy.Web.Messages;
|
namespace Hutopy.Web.Common;
|
||||||
|
|
||||||
public class Shared(string claimName) : Exception;
|
public class Shared(string claimName) : Exception;
|
||||||
|
|
||||||
13
src/Web/Contents/Data/Content.cs
Normal file
13
src/Web/Contents/Data/Content.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Hutopy.Web.Contents.Data;
|
||||||
|
|
||||||
|
public class Content
|
||||||
|
{
|
||||||
|
public Guid Id { get; init; }
|
||||||
|
public Guid CreatedBy { get; init; }
|
||||||
|
public DateTime CreatedAt { get; }
|
||||||
|
|
||||||
|
public string? Title { get; init; } = null!;
|
||||||
|
public string? Description { get; init; } = null!;
|
||||||
|
public string? Uri { get; init; } = null!;
|
||||||
|
}
|
||||||
|
|
||||||
19
src/Web/Contents/Data/ContentDbContext.cs
Normal file
19
src/Web/Contents/Data/ContentDbContext.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Data;
|
||||||
|
|
||||||
|
public class ContentDbContext(
|
||||||
|
DbContextOptions<ContentDbContext> options)
|
||||||
|
: DbContext(options)
|
||||||
|
{
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder
|
||||||
|
.Entity<Content>()
|
||||||
|
.Property(c => c.CreatedAt)
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<Content> Contents { get; set; }
|
||||||
|
}
|
||||||
30
src/Web/Contents/Handlers/GetContents.cs
Normal file
30
src/Web/Contents/Handlers/GetContents.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Handlers;
|
||||||
|
|
||||||
|
public class GetContents(
|
||||||
|
ContentDbContext context)
|
||||||
|
: EndpointWithoutRequest<Content>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Tags("Contents");
|
||||||
|
Get("/api/contents/{ContentId:guid}");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
var contentId = Route<Guid>("ContentId");
|
||||||
|
|
||||||
|
var comments = await context
|
||||||
|
.Contents
|
||||||
|
.Where(c => c.Id == contentId)
|
||||||
|
.ToListAsync(cancellationToken: ct);
|
||||||
|
|
||||||
|
await SendAsync(comments.First(), cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Web/Contents/Handlers/GetContentsByUser.cs
Normal file
30
src/Web/Contents/Handlers/GetContentsByUser.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Handlers;
|
||||||
|
|
||||||
|
public class GetContentsByUser(
|
||||||
|
ContentDbContext context)
|
||||||
|
: EndpointWithoutRequest<List<Content>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Tags("Contents");
|
||||||
|
Get("/api/contents/user/{UserId:guid}");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
var userId = Route<Guid>("UserId");
|
||||||
|
|
||||||
|
var posts = await context
|
||||||
|
.Contents
|
||||||
|
.Where(c => c.CreatedBy == userId)
|
||||||
|
.ToListAsync(cancellationToken: ct);
|
||||||
|
|
||||||
|
await SendAsync(posts, cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Web/Contents/Handlers/PostMessage.cs
Normal file
39
src/Web/Contents/Handlers/PostMessage.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Common;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Handlers;
|
||||||
|
|
||||||
|
public record struct PostContentRequest(
|
||||||
|
string? Title,
|
||||||
|
string? Description,
|
||||||
|
string? Uri);
|
||||||
|
|
||||||
|
public class PostMessage(
|
||||||
|
ContentDbContext context)
|
||||||
|
: Endpoint<PostContentRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
// TODO: Find how to specify the name we see in Swagger
|
||||||
|
Tags("Contents");
|
||||||
|
Post("/api/contents");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
PostContentRequest req,
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
await context.Contents.AddAsync(
|
||||||
|
new Content
|
||||||
|
{
|
||||||
|
CreatedBy = User.GetUserId(),
|
||||||
|
Title = req.Title,
|
||||||
|
Description = req.Description,
|
||||||
|
Uri = req.Uri
|
||||||
|
},
|
||||||
|
ct);
|
||||||
|
|
||||||
|
await context.SaveChangesAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/Web/Contents/Migrations/20240702034957_Initial.Designer.cs
generated
Normal file
58
src/Web/Contents/Migrations/20240702034957_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ContentDbContext))]
|
||||||
|
[Migration("20240702034957_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Web.Contents.Data.Content", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||||
|
|
||||||
|
b.Property<Guid>("CreatedBy")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Uri")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Contents");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/Web/Contents/Migrations/20240702034957_Initial.cs
Normal file
38
src/Web/Contents/Migrations/20240702034957_Initial.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Contents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||||
|
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
|
||||||
|
Title = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
Uri = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Contents", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Contents");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/Web/Contents/Migrations/ContentDbContextModelSnapshot.cs
Normal file
55
src/Web/Contents/Migrations/ContentDbContextModelSnapshot.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Contents.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ContentDbContext))]
|
||||||
|
partial class ContentDbContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hutopy.Web.Contents.Data.Content", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||||
|
|
||||||
|
b.Property<Guid>("CreatedBy")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Uri")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Contents");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Web/Creators/Handlers/GetCreatorByAlias.cs
Normal file
29
src/Web/Creators/Handlers/GetCreatorByAlias.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Application.Common.Interfaces;
|
||||||
|
using Hutopy.Application.Common.Models;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Creators.Handlers;
|
||||||
|
|
||||||
|
public class GetCreatorByAlias(
|
||||||
|
IIdentityService identityService)
|
||||||
|
: EndpointWithoutRequest<UserModel?>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Tags("Creators");
|
||||||
|
Get("/api/creators/@{CreatorAlias}");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
var creatorAlias = Route<string>("CreatorAlias");
|
||||||
|
|
||||||
|
ArgumentException.ThrowIfNullOrEmpty(creatorAlias);
|
||||||
|
|
||||||
|
var user = await identityService.FindUserByCreatorAliasAsync(creatorAlias, ct);
|
||||||
|
|
||||||
|
await SendAsync(user, cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,6 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Hutopy.Web.Messages.Handlers;
|
namespace Hutopy.Web.Messages.Handlers;
|
||||||
|
|
||||||
public record GetMessagesByUserRequest(
|
|
||||||
[FromRoute] Guid UserId);
|
|
||||||
|
|
||||||
public class GetMessagesByUser(
|
public class GetMessagesByUser(
|
||||||
MessagingDbContext context)
|
MessagingDbContext context)
|
||||||
: EndpointWithoutRequest<List<Message>>
|
: EndpointWithoutRequest<List<Message>>
|
||||||
@@ -15,7 +12,7 @@ public class GetMessagesByUser(
|
|||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Tags("Messages");
|
Tags("Messages");
|
||||||
Get("/api/messages/by-user/{UserId:guid}");
|
Get("/api/messages/user/{UserId:guid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(
|
public override async Task HandleAsync(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Common;
|
||||||
using Hutopy.Web.Messages.Data;
|
using Hutopy.Web.Messages.Data;
|
||||||
|
|
||||||
namespace Hutopy.Web.Messages.Handlers;
|
namespace Hutopy.Web.Messages.Handlers;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Common;
|
||||||
using Hutopy.Web.Messages.Data;
|
using Hutopy.Web.Messages.Data;
|
||||||
|
|
||||||
namespace Hutopy.Web.Messages.Handlers;
|
namespace Hutopy.Web.Messages.Handlers;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
@using Hutopy.Infrastructure.Identity
|
@using Hutopy.Infrastructure.Identity
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@inject SignInManager<ApplicationUser> SignInManager
|
@inject SignInManager<ApplicationUser> SignInManager
|
||||||
@inject UserManager<ApplicationUser> UserManager
|
|
||||||
|
|
||||||
@{
|
@{
|
||||||
string? returnUrl = null;
|
string? returnUrl = null;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Hutopy.Application;
|
|||||||
using Hutopy.Infrastructure;
|
using Hutopy.Infrastructure;
|
||||||
using Hutopy.Infrastructure.Data;
|
using Hutopy.Infrastructure.Data;
|
||||||
using Hutopy.Web;
|
using Hutopy.Web;
|
||||||
|
using Hutopy.Web.Contents.Data;
|
||||||
using Hutopy.Web.Messages.Data;
|
using Hutopy.Web.Messages.Data;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -21,24 +22,24 @@ if (!builder.Environment.IsDevelopment())
|
|||||||
|
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowAll", builder =>
|
options.AddPolicy("AllowAll", policy =>
|
||||||
{
|
{
|
||||||
builder.AllowAnyOrigin()
|
policy.AllowAnyOrigin()
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader();
|
.AllowAnyHeader();
|
||||||
});
|
});
|
||||||
|
|
||||||
options.AddPolicy("AllowHutopyUi", builder =>
|
options.AddPolicy("AllowHutopyUi", policy =>
|
||||||
{
|
{
|
||||||
builder.WithOrigins("https://zealous-bay-08204590f.5.azurestaticapps.net")
|
policy.WithOrigins("https://zealous-bay-08204590f.5.azurestaticapps.net")
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials();
|
.AllowCredentials();
|
||||||
});
|
});
|
||||||
|
|
||||||
options.AddPolicy("AllowHutopyUiPreview", builder =>
|
options.AddPolicy("AllowHutopyUiPreview", policy =>
|
||||||
{
|
{
|
||||||
builder.WithOrigins("https://zealous-bay-08204590f-preview.eastus2.5.azurestaticapps.net")
|
policy.WithOrigins("https://zealous-bay-08204590f-preview.eastus2.5.azurestaticapps.net")
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials();
|
.AllowCredentials();
|
||||||
@@ -83,6 +84,11 @@ builder.Services.AddDbContext<MessagingDbContext>((_, options) =>
|
|||||||
options.UseSqlServer(builder.Configuration.GetConnectionString("CommentStore"));
|
options.UseSqlServer(builder.Configuration.GetConnectionString("CommentStore"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<ContentDbContext>((_, options) =>
|
||||||
|
{
|
||||||
|
options.UseSqlServer(builder.Configuration.GetConnectionString("ContentStore"));
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseForwardedHeaders(
|
app.UseForwardedHeaders(
|
||||||
|
|||||||
@@ -30,8 +30,4 @@
|
|||||||
<PackageReference Include="FluentValidation.AspNetCore" />
|
<PackageReference Include="FluentValidation.AspNetCore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Messages\Migrations\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=localhost,1433;Initial Catalog=Hutopy;User Id=sa;Password=P@ssword123!;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True",
|
"DefaultConnection": "Server=localhost,1433;Initial Catalog=Hutopy;User Id=sa;Password=P@ssword123!;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True",
|
||||||
"CommentStore": "Server=localhost,1433;Initial Catalog=Hutopy;User Id=sa;Password=P@ssword123!;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True"
|
"CommentStore": "Server=localhost,1433;Initial Catalog=Hutopy;User Id=sa;Password=P@ssword123!;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True",
|
||||||
|
"ContentStore": "Server=localhost,1433;Initial Catalog=Hutopy;User Id=sa;Password=P@ssword123!;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True"
|
||||||
},
|
},
|
||||||
"Authentication": {
|
"Authentication": {
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public partial class Testing
|
|||||||
{
|
{
|
||||||
using var scope = _scopeFactory.CreateScope();
|
using var scope = _scopeFactory.CreateScope();
|
||||||
|
|
||||||
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
var userManager = scope.ServiceProvider.GetRequiredService<ApplicationUserManager>();
|
||||||
|
|
||||||
var user = new ApplicationUser { UserName = userName, Email = userName };
|
var user = new ApplicationUser { UserName = userName, Email = userName };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user