|
Last change
on this file since cab02ad was cab02ad, checked in by stefansaveski <stefansaveski19@…>, 11 months ago |
|
Add user-related models, services, and JWT validation
Added ContactInfo, EnrollmentInfo, and HighSchool models with relationships to the User entity. Updated AppDbContext and migrations to reflect these changes. Introduced UserService and IUserService for handling user data retrieval via JWT validation. Added UserController with a getUser endpoint to fetch user data based on JWT.
Enhanced IUserRepository and UserRepository with a method to fetch users by ID. Registered UserService in the DI container. Defined enums for EnrollmentInfo and HighSchool. Removed outdated migration files and performed general refactoring and cleanup.
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [e49c3ed] | 1 | using iknow_api.Models;
|
|---|
| 2 | using iknow_api.Data;
|
|---|
| 3 | using iknow_api.Models;
|
|---|
| [5b42c8d] | 4 | using Microsoft.EntityFrameworkCore;
|
|---|
| [9a57e89] | 5 |
|
|---|
| [277bd72] | 6 | namespace iknow_api.Repositories
|
|---|
| [9a57e89] | 7 | {
|
|---|
| 8 | public class UserRepository : IUserRepository
|
|---|
| 9 | {
|
|---|
| 10 | private readonly AppDbContext _context;
|
|---|
| 11 |
|
|---|
| 12 | public UserRepository(AppDbContext context)
|
|---|
| 13 | {
|
|---|
| 14 | _context = context;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| [5b42c8d] | 17 | public async Task<bool> UserExistsAsync(string username)
|
|---|
| 18 | {
|
|---|
| 19 | return await _context.User.AnyAsync(u => u.Email == username);
|
|---|
| 20 | }
|
|---|
| [9a57e89] | 21 |
|
|---|
| [5b42c8d] | 22 | public async Task<User?> GetUserByUsernameAsync(string username)
|
|---|
| [9a57e89] | 23 | {
|
|---|
| [5b42c8d] | 24 | return await _context.User.FirstOrDefaultAsync(u => u.Email == username);
|
|---|
| [9a57e89] | 25 | }
|
|---|
| [cab02ad] | 26 |
|
|---|
| 27 | public async Task<User> GetUserByIdAsync(int id)
|
|---|
| 28 | {
|
|---|
| 29 | return await _context.User.FirstOrDefaultAsync(u => u.Id == id);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| [9a57e89] | 32 |
|
|---|
| [5b42c8d] | 33 | public async Task AddUserAsync(User user)
|
|---|
| 34 | {
|
|---|
| 35 | _context.User.Add(user);
|
|---|
| 36 | await _context.SaveChangesAsync();
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | public async Task<int> GetUsersCountAsync()
|
|---|
| 40 | {
|
|---|
| 41 | return await _context.User.CountAsync();
|
|---|
| 42 | }
|
|---|
| [9a57e89] | 43 | }
|
|---|
| 44 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.