Ignore:
Timestamp:
10/21/25 17:21:47 (11 months ago)
Author:
imbrsk <boris696boris@…>
Branches:
master
Children:
d025ba3
Parents:
2859225
Message:

Refactor user management: update models, repositories, and services; remove obsolete files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Services/Implementations/UserService.cs

    r2859225 r9a57e89  
    1 using Microsoft.AspNetCore.Mvc;
     1using Microsoft.EntityFrameworkCore;
     2using iknow_api.Core.Models;
     3using iknow_api.Repository.Interfaces;
     4// ...existing code...
    25
    36namespace iknow_api.Core.Services
     
    58    public class UserService
    69    {
    7         private readonly AppDbContext _context;
     10        private readonly IUserRepository _users;
    811
    9         public UserService(AppDbContext context)
     12        public UserService(IUserRepository users)
    1013        {
    11             _context = context;
     14            _users = users;
    1215        }
    1316
     17        public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)
     18        {
     19            if (user == null) throw new ArgumentNullException(nameof(user));
    1420
     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        }
    1532    }
    1633}
Note: See TracChangeset for help on using the changeset viewer.