Redo controllers
This commit is contained in:
@@ -28,7 +28,10 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(u => u.FullName)
|
||||
builder.Property(u => u.FirstName)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(u => u.LastName)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(u => u.PhoneNumber)
|
||||
|
||||
@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Imprink.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20250609202250_InitialSetup")]
|
||||
[Migration("20250610225629_InitialSetup")]
|
||||
partial class InitialSetup
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -743,11 +743,6 @@ namespace Imprink.Infrastructure.Migrations
|
||||
b.ToTable("Roles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = new Guid("11111111-1111-1111-1111-111111111111"),
|
||||
RoleName = "User"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("22222222-2222-2222-2222-222222222222"),
|
||||
@@ -775,7 +770,7 @@ namespace Imprink.Infrastructure.Migrations
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
b.Property<string>("FirstName")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
@@ -784,6 +779,10 @@ namespace Imprink.Infrastructure.Migrations
|
||||
.HasColumnType("bit")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
@@ -85,7 +85,8 @@ namespace Imprink.Infrastructure.Migrations
|
||||
Nickname = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
|
||||
EmailVerified = table.Column<bool>(type: "bit", maxLength: 100, nullable: false),
|
||||
FullName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
FirstName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
LastName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
PhoneNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true)
|
||||
},
|
||||
@@ -339,7 +340,6 @@ namespace Imprink.Infrastructure.Migrations
|
||||
columns: new[] { "Id", "RoleName" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ new Guid("11111111-1111-1111-1111-111111111111"), "User" },
|
||||
{ new Guid("22222222-2222-2222-2222-222222222222"), "Merchant" },
|
||||
{ new Guid("33333333-3333-3333-3333-333333333333"), "Admin" }
|
||||
});
|
||||
@@ -740,11 +740,6 @@ namespace Imprink.Infrastructure.Migrations
|
||||
b.ToTable("Roles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = new Guid("11111111-1111-1111-1111-111111111111"),
|
||||
RoleName = "User"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("22222222-2222-2222-2222-222222222222"),
|
||||
@@ -772,7 +767,7 @@ namespace Imprink.Infrastructure.Migrations
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
b.Property<string>("FirstName")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
@@ -781,6 +776,10 @@ namespace Imprink.Infrastructure.Migrations
|
||||
.HasColumnType("bit")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using Imprink.Domain.Models;
|
||||
using Imprink.Domain.Repositories;
|
||||
using Imprink.Domain.Repositories.Users;
|
||||
using Imprink.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -8,7 +9,7 @@ namespace Imprink.Infrastructure.Repositories.Users;
|
||||
|
||||
public class UserRepository(ApplicationDbContext context) : IUserRepository
|
||||
{
|
||||
public async Task<bool> UpdateOrCreateUserAsync(Auth0User user, CancellationToken cancellationToken = default)
|
||||
public async Task<User?> UpdateOrCreateUserAsync(Auth0User user, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var userToUpdate = await context.Users
|
||||
.Where(u => u.Id.Equals(user.Sub))
|
||||
@@ -27,16 +28,15 @@ public class UserRepository(ApplicationDbContext context) : IUserRepository
|
||||
};
|
||||
|
||||
context.Users.Add(newUser);
|
||||
return newUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
userToUpdate.Email = user.Email;
|
||||
userToUpdate.Name = user.Name;
|
||||
userToUpdate.Nickname = user.Nickname;
|
||||
userToUpdate.EmailVerified = user.EmailVerified;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
userToUpdate.Email = user.Email;
|
||||
userToUpdate.Name = user.Name;
|
||||
userToUpdate.Nickname = user.Nickname;
|
||||
userToUpdate.EmailVerified = user.EmailVerified;
|
||||
|
||||
return userToUpdate;
|
||||
}
|
||||
|
||||
public async Task<User?> GetUserByIdAsync(string userId, CancellationToken cancellationToken = default)
|
||||
@@ -92,4 +92,27 @@ public class UserRepository(ApplicationDbContext context) : IUserRepository
|
||||
.Include(u => u.Orders)
|
||||
.FirstOrDefaultAsync(u => u.Id == userId, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<User?> SetUserPhoneAsync(string userId, string phoneNumber, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await context.Users
|
||||
.FirstOrDefaultAsync(u => u.Id == userId, cancellationToken);
|
||||
|
||||
if (user == null) return null;
|
||||
|
||||
user.PhoneNumber = phoneNumber;
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User?> SetUserFullNameAsync(string userId, string firstName, string lastName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await context.Users
|
||||
.FirstOrDefaultAsync(u => u.Id == userId, cancellationToken);
|
||||
|
||||
if (user == null) return null;
|
||||
|
||||
user.FirstName = firstName;
|
||||
user.LastName = lastName;
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user