Changeset 4f5d8fd for iknow-api


Ignore:
Timestamp:
10/27/25 15:20:33 (11 months ago)
Author:
stefansaveski <stefansaveski19@…>
Branches:
master
Children:
c0256f3
Parents:
5eb7847
Message:

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.

Location:
iknow-api
Files:
8 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/DTOs/UserDTO.cs

    r5eb7847 r4f5d8fd  
    66        public string Email { get; set; } = string.Empty;
    77        public string Password { get; set; } = string.Empty;
     8    }
     9    public class GetUserDataDto
     10    {
     11        public string JWT { get; set; }
    812    }
    913
  • iknow-api/Data/AppDbContext.cs

    r5eb7847 r4f5d8fd  
    1010
    1111        public DbSet<User> User { get; set; }
     12        public DbSet<ContactInfo> ContactInfo { get; set; }
     13        public DbSet<HighSchool> HighSchool { get; set; }
     14        public DbSet<EnrollmentInfo> EnrollmentInfo { get; set; }
    1215    }
    1316}
  • iknow-api/Migrations/AppDbContextModelSnapshot.cs

    r5eb7847 r4f5d8fd  
    2323            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
    2424
    25             modelBuilder.Entity("iknow_api.Core.Models.User", b =>
     25            modelBuilder.Entity("iknow_api.Models.ContactInfo", b =>
     26                {
     27                    b.Property<int>("Id")
     28                        .ValueGeneratedOnAdd()
     29                        .HasColumnType("integer");
     30
     31                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
     32
     33                    b.Property<int>("UserId")
     34                        .HasColumnType("integer");
     35
     36                    b.Property<string>("address")
     37                        .HasColumnType("text");
     38
     39                    b.Property<string>("city")
     40                        .HasColumnType("text");
     41
     42                    b.Property<string>("microsoftEmail")
     43                        .HasColumnType("text");
     44
     45                    b.Property<string>("municipality")
     46                        .HasColumnType("text");
     47
     48                    b.Property<string>("phoneNumber")
     49                        .HasColumnType("text");
     50
     51                    b.HasKey("Id");
     52
     53                    b.HasIndex("UserId");
     54
     55                    b.ToTable("ContactInfo");
     56                });
     57
     58            modelBuilder.Entity("iknow_api.Models.EnrollmentInfo", b =>
     59                {
     60                    b.Property<int>("Id")
     61                        .ValueGeneratedOnAdd()
     62                        .HasColumnType("integer");
     63
     64                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
     65
     66                    b.Property<int>("UserId")
     67                        .HasColumnType("integer");
     68
     69                    b.Property<int>("enrollmentYear")
     70                        .HasColumnType("integer");
     71
     72                    b.Property<int>("major")
     73                        .HasColumnType("integer");
     74
     75                    b.HasKey("Id");
     76
     77                    b.HasIndex("UserId");
     78
     79                    b.ToTable("EnrollmentInfo");
     80                });
     81
     82            modelBuilder.Entity("iknow_api.Models.HighSchool", b =>
     83                {
     84                    b.Property<int>("Id")
     85                        .ValueGeneratedOnAdd()
     86                        .HasColumnType("integer");
     87
     88                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
     89
     90                    b.Property<float>("GPA")
     91                        .HasColumnType("real");
     92
     93                    b.Property<int>("UserId")
     94                        .HasColumnType("integer");
     95
     96                    b.Property<int>("tip")
     97                        .HasColumnType("integer");
     98
     99                    b.HasKey("Id");
     100
     101                    b.HasIndex("UserId");
     102
     103                    b.ToTable("HighSchool");
     104                });
     105
     106            modelBuilder.Entity("iknow_api.Models.User", b =>
    26107                {
    27108                    b.Property<int>("Id")
     
    59140                    b.ToTable("User");
    60141                });
     142
     143            modelBuilder.Entity("iknow_api.Models.ContactInfo", b =>
     144                {
     145                    b.HasOne("iknow_api.Models.User", "User")
     146                        .WithMany()
     147                        .HasForeignKey("UserId")
     148                        .OnDelete(DeleteBehavior.Cascade)
     149                        .IsRequired();
     150
     151                    b.Navigation("User");
     152                });
     153
     154            modelBuilder.Entity("iknow_api.Models.EnrollmentInfo", b =>
     155                {
     156                    b.HasOne("iknow_api.Models.User", "User")
     157                        .WithMany()
     158                        .HasForeignKey("UserId")
     159                        .OnDelete(DeleteBehavior.Cascade)
     160                        .IsRequired();
     161
     162                    b.Navigation("User");
     163                });
     164
     165            modelBuilder.Entity("iknow_api.Models.HighSchool", b =>
     166                {
     167                    b.HasOne("iknow_api.Models.User", "User")
     168                        .WithMany()
     169                        .HasForeignKey("UserId")
     170                        .OnDelete(DeleteBehavior.Cascade)
     171                        .IsRequired();
     172
     173                    b.Navigation("User");
     174                });
    61175#pragma warning restore 612, 618
    62176        }
  • iknow-api/Program.cs

    r5eb7847 r4f5d8fd  
    4343builder.Services.AddScoped<IAuthService, AuthService>();
    4444builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation
     45builder.Services.AddScoped<IUserService, UserService>();
     46
    4547builder.Services.AddAuthorization();
    4648var app = builder.Build();
  • iknow-api/Repository/Implementations/UserRepository.cs

    r5eb7847 r4f5d8fd  
    2424            return await _context.User.FirstOrDefaultAsync(u => u.Email == username);
    2525        }
     26       
     27        public async Task<User> GetUserByIdAsync(int id)
     28        {
     29            return await _context.User.FirstOrDefaultAsync(u => u.Id == id);
     30        }
     31
    2632
    2733        public async Task AddUserAsync(User user)
  • iknow-api/Repository/Interface/IUserRepository.cs

    r5eb7847 r4f5d8fd  
    88        Task AddUserAsync(User user);
    99        Task<int> GetUsersCountAsync();
     10        Task<User> GetUserByIdAsync(int id);
    1011    }
    1112}
Note: See TracChangeset for help on using the changeset viewer.