Ignore:
Timestamp:
10/22/25 13:20:23 (11 months ago)
Author:
stefansaveski <stefansaveski19@…>
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.
Message:

test

File:
1 edited

Legend:

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

    rc0a75ab raed1148  
    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.