Skip to content

Commit

Permalink
merge with V1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
matinayo committed Aug 8, 2024
2 parents 6695cd3 + 1d38d5c commit 88cbbb3
Show file tree
Hide file tree
Showing 173 changed files with 2,198 additions and 2,184 deletions.
Empty file.
11 changes: 11 additions & 0 deletions HalceraAPI.Common/AppsettingsOptions/EmailSenderOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace HalceraAPI.Common.AppsettingsOptions
{
public class EmailSenderOptions
{
public string? SendGridKey { get; set; }

public string? SendGridUser { get; set; }

public string? SendGridEmail { get; set; }
}
}
8 changes: 8 additions & 0 deletions HalceraAPI.Common/Enums/AccountAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HalceraAPI.Common.Enums
{
public enum AccountAction
{
Lock,
Unlock
}
}
9 changes: 9 additions & 0 deletions HalceraAPI.Common/Enums/ComponentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace HalceraAPI.Common.Enums
{
public enum ComponentType
{
materials,
care,
details,
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HalceraAPI.Models.Enums
namespace HalceraAPI.Common.Enums
{
public enum Currency
{
Expand Down
12 changes: 12 additions & 0 deletions HalceraAPI.Common/Enums/MediaType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace HalceraAPI.Common.Enums
{
public enum MediaType : int
{
image = 1,
svg = 2,
video = 3,
audio = 4,
document = 5,
model = 6
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HalceraAPI.Models.Enums
namespace HalceraAPI.Common.Enums
{
public enum OrderStatus : int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HalceraAPI.Models.Enums
namespace HalceraAPI.Common.Enums
{
public enum PaymentProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HalceraAPI.Models.Enums
namespace HalceraAPI.Common.Enums
{
public enum PaymentStatus : int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HalceraAPI.Models.Enums
namespace HalceraAPI.Common.Enums
{
/// <summary>
/// Order Shipping Status
Expand Down
2 changes: 1 addition & 1 deletion HalceraAPI.Common/Utilities/Defaults.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HalceraAPI.Models.Enums;
using HalceraAPI.Common.Enums;

namespace HalceraAPI.Common.Utilities
{
Expand Down
19 changes: 19 additions & 0 deletions HalceraAPI.Common/Utilities/EmailConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HalceraAPI.Common.Utilities
{
public static class EmailConstants
{
public const string ForgotPasswordSubject = "Request to change password";

public static string ForgotPasswordPlainTextMessage(string userPasswordResetToken)
{
return $"Request to change password {userPasswordResetToken}";
}
public const string ForgotPasswordHtmlMessage = "Request to change password";
}
}
6 changes: 4 additions & 2 deletions HalceraAPI.DataAccess/ApplicationDBContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : ba
public DbSet<ShoppingCart>? ShoppingCart { get; set; }
public DbSet<Category>? Categories { get; set; }
public DbSet<Composition>? Compositions { get; set; }
public DbSet<CompositionData>? CompositionData { get; set; }
public DbSet<ComponentData>? ComponentData { get; set; }
public DbSet<Media>? Medias { get; set; }
public DbSet<Price>? Prices { get; set; }
public DbSet<Rating>? Ratings { get; set; }
Expand All @@ -26,6 +26,8 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : ba
public DbSet<PurchaseDetails>? PurchaseDetails { get; set; }
public DbSet<PaymentDetails>? PaymentDetails { get; set; }
public DbSet<ShippingDetails>? ShippingDetails { get; set; }

public DbSet<OrderProductSize>? OrderProductSizes { get; set; }
public DbSet<OrderComposition>? OrderCompositions { get; set; }
public DbSet<OrderProduct>? OrderProducts { get; set; }
}
}
6 changes: 3 additions & 3 deletions HalceraAPI.DataAccess/Contract/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace HalceraAPI.DataAccess.Contract
public interface IRepository<T>
where T : class
{
Task<IEnumerable<T>> GetAll(Expression<Func<T, bool>>? filter = null, Func<IQueryable<T>,
Task<IList<T>> GetAll(Expression<Func<T, bool>>? filter = null, Func<IQueryable<T>,
IOrderedQueryable<T>>? orderBy = null, int? skip = null, int? take = null, string? includeProperties = null);

/// <summary>
/// Select with defined Entity of different types: T and TResult
/// </summary>
Task<IEnumerable<TResult>> GetAll<TResult>(Expression<Func<T, bool>>? filter = null, Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null, int? skip = null, int? take = null, string? includeProperties = null);
Task<IList<TResult>> GetAll<TResult>(Expression<Func<T, bool>>? filter = null, Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null, int? skip = null, int? take = null, string? includeProperties = null);

Task<T?> GetFirstOrDefault(
Expression<Func<T, bool>>? filter = null,
Expand All @@ -30,7 +30,7 @@ Task<IEnumerable<T>> GetAll(Expression<Func<T, bool>>? filter = null, Func<IQuer

Task Add(T entity);

Task AddRange(IEnumerable<T> entities);
Task AddRange(IList<T> entities);

void Update(T entity);

Expand Down
3 changes: 2 additions & 1 deletion HalceraAPI.DataAccess/Contract/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ public interface IUnitOfWork
IRepository<BaseAddress> BaseAddress { get; }
IRepository<Category> Category { get; }
IRepository<Composition> Composition { get; }
IRepository<CompositionData> CompositionData { get; }
IRepository<ComponentData> ComponentData { get; }
IRepository<Media> Media { get; }
IRepository<Price> Price { get; }
IRepository<Product> Product { get; }
IRepository<ProductSize> ProductSize { get; }
IRepository<Rating> Rating { get; }
IRepository<ShoppingCart> ShoppingCart { get; }
IRepository<Roles> Roles { get; }
Expand Down
5 changes: 2 additions & 3 deletions HalceraAPI.DataAccess/DbInitializer/DbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void Initialize()

private List<Roles> LoadApplicationRoles()
{
// Create all roles required
List<Roles> applicationRoles = new()
{
new() {
Expand All @@ -62,8 +61,8 @@ private void LoadAdminUser(Roles? roleId)
ApplicationUser applicationUser = new()
{
Name = "Admin",
Email = "admin@halcera.com",
PasswordHash = BCrypt.Net.BCrypt.HashPassword("MASTER123*"),
Email = "user@example.com",
PasswordHash = BCrypt.Net.BCrypt.HashPassword("string"),
Roles = roleId != null ? new List<Roles>() { roleId } : null
};

Expand Down
10 changes: 5 additions & 5 deletions HalceraAPI.DataAccess/Repository/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task Add(T entity)
await dbSet.AddAsync(entity);
}

public async Task AddRange(IEnumerable<T> entities)
public async Task AddRange(IList<T> entities)
{
await dbSet.AddRangeAsync(entities);
}
Expand All @@ -43,7 +43,7 @@ public async Task<int> CountAsync(Expression<Func<T, bool>>? filter = null)
return await dbSet.CountAsync(filter);
}

public async Task<IEnumerable<T>> GetAll(
public async Task<IList<T>> GetAll(
Expression<Func<T, bool>>? filter = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
int? skip = null,
Expand All @@ -54,15 +54,15 @@ public async Task<IEnumerable<T>> GetAll(
return await query.ToListAsync();
}

public async Task<IEnumerable<TResult>> GetAll<TResult>(
public async Task<IList<TResult>> GetAll<TResult>(
Expression<Func<T, bool>>? filter = null,
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
int? skip = null,
int? take = null,
string? includeProperties = null)
{
IQueryable<T> query = GetAllQuery(filter, orderBy, skip, take, includeProperties);
return await _mapper.ProjectTo<TResult>(query).ToListAsync();
return await _mapper.ProjectTo<TResult>(query.AsNoTracking()).ToListAsync();
}

public async Task<T?> GetFirstOrDefault(Expression<Func<T, bool>>? filter = null, string? includeProperties = null)
Expand All @@ -74,7 +74,7 @@ public async Task<IEnumerable<TResult>> GetAll<TResult>(
public async Task<TResult?> GetFirstOrDefault<TResult>(Expression<Func<T, bool>>? filter = null, string? includeProperties = null)
{
IQueryable<T> query = GetFirstOrDefaultQuery(filter, includeProperties);
return await _mapper.ProjectTo<TResult>(query).FirstOrDefaultAsync();
return await _mapper.ProjectTo<TResult>(query.AsNoTracking()).FirstOrDefaultAsync();
}

public void Remove(T entity)
Expand Down
6 changes: 4 additions & 2 deletions HalceraAPI.DataAccess/Repository/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public UnitOfWork(ApplicationDbContext context, IMapper mapper)
BaseAddress = new Repository<BaseAddress>(_context, mapper);
Category = new Repository<Category>(_context, mapper);
Composition = new Repository<Composition>(_context, mapper);
CompositionData = new Repository<CompositionData>(_context, mapper);
ComponentData = new Repository<ComponentData>(_context, mapper);
Media = new Repository<Media>(_context, mapper);
Price = new Repository<Price>(_context, mapper);
Product = new Repository<Product>(_context, mapper);
ProductSize = new Repository<ProductSize>(_context, mapper);
Rating = new Repository<Rating>(_context, mapper);
ShoppingCart = new Repository<ShoppingCart>(_context, mapper);
Roles = new Repository<Roles>(_context, mapper);
Expand All @@ -38,10 +39,11 @@ public UnitOfWork(ApplicationDbContext context, IMapper mapper)
public IRepository<BaseAddress> BaseAddress { get; private set; }
public IRepository<Category> Category { get; private set; }
public IRepository<Composition> Composition { get; private set; }
public IRepository<CompositionData> CompositionData { get; private set; }
public IRepository<ComponentData> ComponentData { get; private set; }
public IRepository<Media> Media { get; private set; }
public IRepository<Price> Price { get; private set; }
public IRepository<Product> Product { get; private set; }
public IRepository<ProductSize> ProductSize { get; private set; }
public IRepository<Rating> Rating { get; private set; }
public IRepository<ShoppingCart> ShoppingCart { get; private set; }
public IRepository<Roles> Roles { get; private set; }
Expand Down
53 changes: 27 additions & 26 deletions HalceraAPI.Model/ApplicationUser.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using BCrypt.Net;
using HalceraAPI.Models.Requests.ApplicationUser;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography;
using System.Text.RegularExpressions;

namespace HalceraAPI.Models
{
/// <summary>
/// Application User Models
/// </summary>
public class ApplicationUser
{
[Key]
Expand All @@ -26,21 +21,34 @@ public class ApplicationUser
public string PasswordHash { get; set; } = string.Empty;

public bool Active { get; set; } = true;
/// <summary>
/// End date if account is locked
/// </summary>

public DateTime? LockoutEnd { get; set; }

public DateTime? UserCreatedDate { get; set; } = DateTime.UtcNow;

public DateTime? DateLastModified { get; set; }

public DateTime? LastLoginDate { get; set; }

public ICollection<Roles>? Roles { get; set; }

public int? RefreshTokenId { get; set; }

[ForeignKey(nameof(RefreshTokenId))]
public RefreshToken? RefreshToken { get; set; }

public bool AccountDeleted { get; set; }

public DateTime? DateAccountDeleted { get; set; }

public string? PasswordResetToken { get; set; }

public DateTime? ResetTokenExpires { get; set; }

public DateTime? PasswordResetDate { get; set; }

public int? AddressId { get; set; }

[ForeignKey(nameof(AddressId))]
public BaseAddress? Address { get; set; }

Expand Down Expand Up @@ -77,11 +85,16 @@ public void Register(string? password)
LastLoginDate = DateTime.UtcNow;
}

/// <summary>
/// Set created password hash
/// </summary>
/// <param name="password">Password string request</param>
/// <returns>Password Hash</returns>
public void ResetPassword(string password)
{
ValidateAccountStatus();
SetPasswordHash(password);
PasswordResetDate = DateTime.UtcNow;
DateLastModified = DateTime.UtcNow;
PasswordResetToken = null;
ResetTokenExpires = null;
}

private void SetPasswordHash(string? password)
{
if (string.IsNullOrWhiteSpace(password))
Expand All @@ -92,10 +105,6 @@ private void SetPasswordHash(string? password)
PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);
}

/// <summary>
/// Verify user password
/// </summary>
/// <param name="requestedPassword">Input password from user</param>
private void VerifyPassword(string? requestedPassword)
{
if (string.IsNullOrWhiteSpace(requestedPassword)
Expand All @@ -105,10 +114,6 @@ private void VerifyPassword(string? requestedPassword)
}
}

/// <summary>
/// Validating Account status and preferences
/// </summary>
/// <param name="applicationUser">Application User from db</param>
private void ValidateAccountStatus()
{
bool accountIsInactive = !Active;
Expand All @@ -128,10 +133,6 @@ private void ValidateAccountStatus()
}
}

/// <summary>
/// Generate Refresh Token
/// </summary>
/// <returns>New refresh token</returns>
public void GenerateRefreshToken()
{
RefreshToken = new RefreshToken
Expand Down
7 changes: 2 additions & 5 deletions HalceraAPI.Model/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ public class Category
/// </summary>
public ICollection<Media>? MediaCollection { get; set; }

public ICollection<Product>? Products { get; set; }

public bool Active { get; set; } = true;

public bool? Featured { get; set; }

/// <summary>
/// Product Categories
/// </summary>
public ICollection<Product>? Products { get; set; }

public DateTime? DateAdded { get; set; } = DateTime.UtcNow;

public DateTime? DateLastModified { get; set; }
Expand Down
22 changes: 22 additions & 0 deletions HalceraAPI.Model/ComponentData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using HalceraAPI.Common.Enums;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace HalceraAPI.Models
{
public class ComponentData
{
[Key]
public int Id { get; set; }

public ComponentType? ItemDetails { get; set; }

[Required]
[StringLength(20, ErrorMessage = "Data field has a maximum length of '20'")]
public string? Data { get; set; }

public int? ProductId { get; set; }
[ForeignKey(nameof(ProductId))]
public Product? Product { get; set; }
}
}
Loading

0 comments on commit 88cbbb3

Please sign in to comment.