Changeset fc7b4b4
- Timestamp:
- 10/22/25 22:40:03 (11 months ago)
- Branches:
- master
- Children:
- 301af3f
- Parents:
- aed1148
- Location:
- iknow-api
- Files:
-
- 4 added
- 9 edited
- 2 moved
-
Controllers/AuthController.cs (added)
-
Controllers/UsersControllers.cs (modified) (1 diff)
-
DTOs/UserDTO.cs (added)
-
Migrations/20251022202014_InitialCreate.Designer.cs (moved) (moved from iknow-api/Migrations/20251021141534_InitialCreate.Designer.cs ) (2 diffs)
-
Migrations/20251022202014_InitialCreate.cs (moved) (moved from iknow-api/Migrations/20251021141534_InitialCreate.cs ) (1 diff)
-
Migrations/AppDbContextModelSnapshot.cs (modified) (1 diff)
-
Models/User.cs (modified) (1 diff)
-
Program.cs (modified) (2 diffs)
-
Repository/Implementations/UserRepository.cs (modified) (2 diffs)
-
Repository/Interface/IUserRepository.cs (modified) (1 diff)
-
Services/Implementations/AuthService.cs (added)
-
Services/Implementations/UserService.cs (modified) (1 diff)
-
Services/Interfaces/IAuthService.cs (added)
-
appsettings.json (modified) (1 diff)
-
iknow-api.csproj (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Controllers/UsersControllers.cs
raed1148 rfc7b4b4 3 3 using Microsoft.AspNetCore.Mvc; 4 4 using iknow_api.Core.Data; 5 using iknow_api.Repository.Interfaces;5 using FinXaccesApi.Repositories; 6 6 using iknow_api.Core.Interfaces; 7 7 -
iknow-api/Migrations/20251022202014_InitialCreate.Designer.cs
raed1148 rfc7b4b4 13 13 { 14 14 [DbContext(typeof(AppDbContext))] 15 [Migration("2025102 1141534_InitialCreate")]15 [Migration("20251022202014_InitialCreate")] 16 16 partial class InitialCreate 17 17 { … … 49 49 .HasColumnType("text"); 50 50 51 b.Property<string>("Password ")51 b.Property<string>("PasswordHash") 52 52 .HasColumnType("text"); 53 53 -
iknow-api/Migrations/20251022202014_InitialCreate.cs
raed1148 rfc7b4b4 23 23 Index = table.Column<string>(type: "text", nullable: true), 24 24 Email = table.Column<string>(type: "text", nullable: true), 25 Password = table.Column<string>(type: "text", nullable: true),25 PasswordHash = table.Column<string>(type: "text", nullable: true), 26 26 Bday = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), 27 27 CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), -
iknow-api/Migrations/AppDbContextModelSnapshot.cs
raed1148 rfc7b4b4 46 46 .HasColumnType("text"); 47 47 48 b.Property<string>("Password ")48 b.Property<string>("PasswordHash") 49 49 .HasColumnType("text"); 50 50 -
iknow-api/Models/User.cs
raed1148 rfc7b4b4 17 17 public string? Index { get; set; } 18 18 public string? Email { get; set; } 19 public string? Password { get; set; }19 public string? PasswordHash { get; set; } 20 20 public DateTime Bday { get; set; } 21 21 public DateTime CreatedAt { get; set; } -
iknow-api/Program.cs
raed1148 rfc7b4b4 1 1 using Microsoft.EntityFrameworkCore; 2 2 using iknow_api.Core.Data; 3 using FinXaccesApi.Services; 4 using FinXaccesApi.Repositories; 3 5 4 6 var builder = WebApplication.CreateBuilder(args); 5 7 6 8 // Add services to the container. 7 8 9 builder.Services.AddControllers(); 9 // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi10 10 builder.Services.AddOpenApi(); 11 11 12 12 // Register DbContext 13 13 builder.Services.AddDbContext<AppDbContext>(options => 14 14 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); 15 15 16 builder.Services.AddScoped<iknow_api.Repository.Interfaces.IUserRepository, iknow_api.Repository.UserRepository>(); 16 // Register your services 17 builder.Services.AddScoped<IAuthService, AuthService>(); 18 builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation 17 19 18 20 var app = builder.Build(); … … 24 26 } 25 27 26 builder.Services.AddDbContext<AppDbContext>(options =>27 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));28 29 30 28 app.UseHttpsRedirection(); 31 32 29 app.UseAuthorization(); 33 34 30 app.MapControllers(); 35 31 -
iknow-api/Repository/Implementations/UserRepository.cs
raed1148 rfc7b4b4 1 using System.Threading; 2 using System.Threading.Tasks; 1 using iknow_api.Core.Models; 2 using iknow_api.Core.Data; 3 using iknow_api.Core.Data; 4 using iknow_api.Core.Models; 3 5 using Microsoft.EntityFrameworkCore; 4 using iknow_api.Core.Models;5 using iknow_api.Repository.Interfaces;6 using iknow_api.Core.Data;7 6 8 namespace iknow_api.Repository7 namespace FinXaccesApi.Repositories 9 8 { 10 9 public class UserRepository : IUserRepository … … 17 16 } 18 17 19 public Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default) 20 => _context.User.AnyAsync(u => u.Email == email, cancellationToken); 21 22 public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default) 18 public async Task<bool> UserExistsAsync(string username) 23 19 { 24 await _context.User.AddAsync(user, cancellationToken); 25 await _context.SaveChangesAsync(cancellationToken); 26 return user; 20 return await _context.User.AnyAsync(u => u.Email == username); 27 21 } 28 22 29 public Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default) 30 => _context.User.FindAsync(new object[] { id }, cancellationToken).AsTask(); 23 public async Task<User?> GetUserByUsernameAsync(string username) 24 { 25 return await _context.User.FirstOrDefaultAsync(u => u.Email == username); 26 } 27 28 public async Task AddUserAsync(User user) 29 { 30 _context.User.Add(user); 31 await _context.SaveChangesAsync(); 32 } 33 34 public async Task<int> GetUsersCountAsync() 35 { 36 return await _context.User.CountAsync(); 37 } 31 38 } 32 39 } -
iknow-api/Repository/Interface/IUserRepository.cs
raed1148 rfc7b4b4 1 using System.Threading;2 using System.Threading.Tasks;3 1 using iknow_api.Core.Models; 4 5 namespace iknow_api.Repository.Interfaces 2 namespace FinXaccesApi.Repositories 6 3 { 7 4 public interface IUserRepository 8 5 { 9 Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default); 10 Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default); 11 Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default); 6 Task<bool> UserExistsAsync(string username); 7 Task<User?> GetUserByUsernameAsync(string username); 8 Task AddUserAsync(User user); 9 Task<int> GetUsersCountAsync(); 12 10 } 13 11 } -
iknow-api/Services/Implementations/UserService.cs
raed1148 rfc7b4b4 1 using Microsoft.EntityFrameworkCore;2 using iknow_api.Core.Models;3 using iknow_api.Repository.Interfaces;4 // ...existing code...1 //using Microsoft.EntityFrameworkCore; 2 //using iknow_api.Core.Models; 3 //using iknow_api.Repository.Interfaces; 4 //// ...existing code... 5 5 6 namespace iknow_api.Core.Services7 {8 public class UserService9 {10 private readonly IUserRepository _users;6 //namespace iknow_api.Core.Services 7 //{ 8 // public class UserService 9 // { 10 // private readonly IUserRepository _users; 11 11 12 public UserService(IUserRepository users)13 {14 _users = users;15 }12 // public UserService(IUserRepository users) 13 // { 14 // _users = users; 15 // } 16 16 17 public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)18 {19 if (user == null) throw new ArgumentNullException(nameof(user));17 // public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default) 18 // { 19 // if (user == null) throw new ArgumentNullException(nameof(user)); 20 20 21 if (!string.IsNullOrWhiteSpace(user.Email))22 {23 user.Email = user.Email.Trim();21 // if (!string.IsNullOrWhiteSpace(user.Email)) 22 // { 23 // user.Email = user.Email.Trim(); 24 24 25 var exists = await _users.EmailExistsAsync(user.Email, cancellationToken);26 if (exists)27 throw new InvalidOperationException("A user with this email already exists.");28 }25 // var exists = await _users.EmailExistsAsync(user.Email, cancellationToken); 26 // if (exists) 27 // throw new InvalidOperationException("A user with this email already exists."); 28 // } 29 29 30 return await _users.AddUserAsync(user, cancellationToken);31 }32 }33 }30 // return await _users.AddUserAsync(user, cancellationToken); 31 // } 32 // } 33 //} -
iknow-api/appsettings.json
raed1148 rfc7b4b4 6 6 } 7 7 }, 8 "ConnectionStrings": { 9 "DefaultConnection": "Host=localhost;Port=3306;Database=myappdb;Username=root;Password=REDACTED_ROTATE_ME" 10 } 8 "ConnectionStrings": { 9 "DefaultConnection": "Host=localhost;Port=55432;Database=myappdb;Username=postgres;Password=REDACTED_ROTATE_ME" 10 }, 11 "Jwt": { 12 "Key": "REDACTED_SET_VIA_USER_SECRETS" 13 } 11 14 } -
iknow-api/iknow-api.csproj
raed1148 rfc7b4b4 9 9 10 10 <ItemGroup> 11 <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> 11 12 <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" /> 12 13 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.10"> … … 15 16 </PackageReference> 16 17 <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> 18 <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" /> 17 19 </ItemGroup> 18 20
Note:
See TracChangeset
for help on using the changeset viewer.
