- Timestamp:
- 10/22/25 13:20:23 (11 months ago)
- Branches:
- master
- Children:
- fc7b4b4
- Parents:
- c0a75ab (diff), 9694de9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- iknow-api
- Files:
-
- 2 added
- 1 deleted
- 6 edited
- 3 moved
-
Controllers/UsersControllers.cs (modified) (2 diffs)
-
Data/AppDbContext.cs (modified) (1 diff)
-
Data/AppDbContextFactory.cs (deleted)
-
Migrations/20251021141534_InitialCreate.Designer.cs (moved) (moved from iknow-api/Migrations/20251020130122_InitialCreate.Designer.cs ) (4 diffs)
-
Migrations/20251021141534_InitialCreate.cs (moved) (moved from iknow-api/Migrations/20251020130122_InitialCreate.cs ) (3 diffs)
-
Migrations/AppDbContextModelSnapshot.cs (modified) (3 diffs)
-
Models/User.cs (moved) (moved from iknow-api/Models/Users.cs ) (2 diffs)
-
Program.cs (modified) (3 diffs)
-
Repository/Implementations/UserRepository.cs (added)
-
Repository/Interface/IUserRepository.cs (added)
-
Services/Implementations/UserService.cs (modified) (2 diffs)
-
Services/Interfaces/IUserService.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Controllers/UsersControllers.cs
rc0a75ab raed1148 1 //using iknow_api.Data; 2 using iknow_api.Models; 1 using iknow_api.Core.Models; 3 2 using System.Threading.Tasks; 4 3 using Microsoft.AspNetCore.Mvc; 5 4 using iknow_api.Core.Data; 5 using iknow_api.Repository.Interfaces; 6 using iknow_api.Core.Interfaces; 6 7 7 8 namespace iknow_api.Controllers … … 11 12 public class UsersController : ControllerBase 12 13 { 13 private readonly AppDbContext _context; 14 private readonly IConfiguration _configuration; 14 private readonly IUserService _users; 15 15 16 public UsersController( AppDbContext context, IConfiguration configuration)16 public UsersController(IUserService users) 17 17 { 18 _context = context; 19 _configuration = configuration; 18 _users = users; 20 19 } 21 20 22 21 [HttpPost("add")] 23 public async Task<IActionResult> Add([FromBody] JsonContent body)22 public async Task<IActionResult> Add([FromBody] User user) 24 23 { 25 26 return null;24 var created = await _users.AddUserAsync(user); 25 return Ok(created); 27 26 } 28 27 28 [HttpGet("id/{id}")] 29 public async Task<IActionResult> GetById(int id) 30 { 31 var user = await _users.GetUserByIdAsync(id); 32 if (user == null) 33 return NotFound(); 34 return Ok(user); 35 } 29 36 } 30 37 } -
iknow-api/Data/AppDbContext.cs
rc0a75ab raed1148 1 1 using Microsoft.EntityFrameworkCore; 2 using iknow_api. Models;2 using iknow_api.Core.Models; 3 3 4 public class AppDbContext : DbContext 4 namespace iknow_api.Core.Data 5 5 { 6 public AppDbContext(DbContextOptions<AppDbContext> options) 7 : base(options) { } 6 public class AppDbContext : DbContext 7 { 8 public AppDbContext(DbContextOptions<AppDbContext> options) 9 : base(options) { } 8 10 9 public DbSet<Users> Users { get; set; } 11 public DbSet<User> User { get; set; } 12 } 10 13 } -
iknow-api/Migrations/20251021141534_InitialCreate.Designer.cs
rc0a75ab raed1148 6 6 using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 7 using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 8 using iknow_api.Core.Data; 8 9 9 10 #nullable disable … … 12 13 { 13 14 [DbContext(typeof(AppDbContext))] 14 [Migration("2025102 0130122_InitialCreate")]15 [Migration("20251021141534_InitialCreate")] 15 16 partial class InitialCreate 16 17 { … … 25 26 NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); 26 27 27 modelBuilder.Entity("iknow_api. Models.Users", b =>28 modelBuilder.Entity("iknow_api.Core.Models.User", b => 28 29 { 29 30 b.Property<int>("Id") … … 59 60 b.HasKey("Id"); 60 61 61 b.ToTable("User s");62 b.ToTable("User"); 62 63 }); 63 64 #pragma warning restore 612, 618 -
iknow-api/Migrations/20251021141534_InitialCreate.cs
rc0a75ab raed1148 14 14 { 15 15 migrationBuilder.CreateTable( 16 name: "User s",16 name: "User", 17 17 columns: table => new 18 18 { … … 30 30 constraints: table => 31 31 { 32 table.PrimaryKey("PK_User s", x => x.Id);32 table.PrimaryKey("PK_User", x => x.Id); 33 33 }); 34 34 } … … 38 38 { 39 39 migrationBuilder.DropTable( 40 name: "User s");40 name: "User"); 41 41 } 42 42 } -
iknow-api/Migrations/AppDbContextModelSnapshot.cs
rc0a75ab raed1148 5 5 using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 6 using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; 7 using iknow_api.Core.Data; 7 8 8 9 #nullable disable … … 22 23 NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); 23 24 24 modelBuilder.Entity("iknow_api. Models.Users", b =>25 modelBuilder.Entity("iknow_api.Core.Models.User", b => 25 26 { 26 27 b.Property<int>("Id") … … 56 57 b.HasKey("Id"); 57 58 58 b.ToTable("User s");59 b.ToTable("User"); 59 60 }); 60 61 #pragma warning restore 612, 618 -
iknow-api/Models/User.cs
rc0a75ab raed1148 1 1 2 2 3 namespace iknow_api. Models3 namespace iknow_api.Core.Models 4 4 { 5 5 public enum UserRole … … 10 10 } 11 11 12 public class User s12 public class User 13 13 { 14 14 public int Id { get; set; } -
iknow-api/Program.cs
rc0a75ab raed1148 1 1 using Microsoft.EntityFrameworkCore; 2 using iknow_api.Core.Data; 2 3 3 4 var builder = WebApplication.CreateBuilder(args); … … 9 10 builder.Services.AddOpenApi(); 10 11 12 11 13 builder.Services.AddDbContext<AppDbContext>(options => 12 14 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); 15 16 builder.Services.AddScoped<iknow_api.Repository.Interfaces.IUserRepository, iknow_api.Repository.UserRepository>(); 13 17 14 18 var app = builder.Build(); … … 20 24 } 21 25 22 26 builder.Services.AddDbContext<AppDbContext>(options => 27 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); 23 28 24 29 -
iknow-api/Services/Implementations/UserService.cs
rc0a75ab raed1148 1 using Microsoft.AspNetCore.Mvc; 1 using Microsoft.EntityFrameworkCore; 2 using iknow_api.Core.Models; 3 using iknow_api.Repository.Interfaces; 4 // ...existing code... 2 5 3 6 namespace iknow_api.Core.Services … … 5 8 public class UserService 6 9 { 7 private readonly AppDbContext _context;10 private readonly IUserRepository _users; 8 11 9 public UserService( AppDbContext context)12 public UserService(IUserRepository users) 10 13 { 11 _ context = context;14 _users = users; 12 15 } 13 16 17 public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default) 18 { 19 if (user == null) throw new ArgumentNullException(nameof(user)); 14 20 21 if (!string.IsNullOrWhiteSpace(user.Email)) 22 { 23 user.Email = user.Email.Trim(); 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 } 29 30 return await _users.AddUserAsync(user, cancellationToken); 31 } 15 32 } 16 33 } -
iknow-api/Services/Interfaces/IUserService.cs
rc0a75ab raed1148 1 using System.Threading; 2 using System.Threading.Tasks; 3 using iknow_api.Core.Models; 1 4 2 5 namespace iknow_api.Core.Interfaces … … 4 7 public interface IUserService 5 8 { 6 Task<JsonContent> AddUser(JsonContent newUser); 9 Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default); 10 Task<int> GetUserByIdAsync(int id, CancellationToken cancellationToken = default); 7 11 } 8 12 }
Note:
See TracChangeset
for help on using the changeset viewer.
