Changeset d025ba3 for iknow-api/Services
- Timestamp:
- 10/22/25 13:20:23 (11 months ago)
- Branches:
- master
- Children:
- 5b42c8d
- Parents:
- 5aa102d (diff), 9a57e89 (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/Services
- Files:
-
- 2 edited
-
Implementations/UserService.cs (modified) (2 diffs)
-
Interfaces/IUserService.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Services/Implementations/UserService.cs
r5aa102d rd025ba3 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
r5aa102d rd025ba3 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.
