- Timestamp:
- 10/28/25 10:51:44 (11 months ago)
- Branches:
- master
- Children:
- f8af32b
- Parents:
- c2e73b6 (diff), ff202cf (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. - git-author:
- Boris Gjorgjievski <69085722+imbrsk@…> (10/28/25 10:51:44)
- git-committer:
- GitHub <noreply@…> (10/28/25 10:51:44)
- Location:
- iknow-api
- Files:
-
- 10 added
- 8 edited
-
Controllers/UserController.cs (added)
-
DTOs/UserDTO.cs (modified) (3 diffs)
-
Data/AppDbContext.cs (modified) (1 diff)
-
Migrations/20251027140655_InitialCreate.Designer.cs (added)
-
Migrations/20251027140655_InitialCreate.cs (added)
-
Migrations/20251027191028_dbRelations.Designer.cs (added)
-
Migrations/20251027191028_dbRelations.cs (added)
-
Migrations/AppDbContextModelSnapshot.cs (modified) (4 diffs)
-
Models/ContactInfo.cs (added)
-
Models/EnrollmentInfo.cs (added)
-
Models/HighSchool.cs (added)
-
Models/User.cs (modified) (1 diff)
-
Program.cs (modified) (3 diffs)
-
Repository/Implementations/UserRepository.cs (modified) (2 diffs)
-
Repository/Interface/IUserRepository.cs (modified) (1 diff)
-
Services/Implementations/AuthService.cs (modified) (1 diff)
-
Services/Implementations/UserService.cs (added)
-
Services/Interfaces/IUserService.cs (added)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/DTOs/UserDTO.cs
rc2e73b6 r4708118 7 7 public string Password { get; set; } = string.Empty; 8 8 public bool GenerateRefreshToken { get; set; } 9 } 10 public class GetUserDataDto 11 { 12 public string JWT { get; set; } 9 13 } 10 14 … … 19 23 public DateTime Bday { get; set; } 20 24 public UserRole Role { get; set; } 25 public float gpa { get; set; } 26 public type tip { get; set; } 27 public string city { get; set; } = string.Empty; 28 public string address { get; set; } = string.Empty; 29 public string municipality { get; set; } = string.Empty; 30 public string phoneNumber { get; set; } = string.Empty; 31 public string microsoftEmail { get; set; } = string.Empty; 32 public int enrollmentYear { get; set; } 33 public quota quotaType { get; set; } 34 public major majorType { get; set; } 35 21 36 } 22 37 … … 41 56 Student 42 57 } 58 public enum type 59 { 60 strucen, gimnazija 61 } 62 public enum quota 63 { 64 drzavna, privatna, stipendija 65 } 66 public enum major 67 { 68 SIIS, PIT, KN, KI, IMB, IE, SSP, SEIS 69 } 43 70 } -
iknow-api/Data/AppDbContext.cs
rc2e73b6 r4708118 10 10 11 11 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; } 12 15 public DbSet<RefreshToken> RefreshToken { get; set; } 13 16 } -
iknow-api/Migrations/AppDbContextModelSnapshot.cs
rc2e73b6 r4708118 23 23 NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); 24 24 25 modelBuilder.Entity("iknow_api.Models.ContactInfo", b => 25 26 modelBuilder.Entity("iknow_api.Models.RefreshToken", b => 26 27 { … … 31 32 NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); 32 33 34 b.Property<int>("UserId") 35 .HasColumnType("integer"); 36 37 b.Property<string>("address") 38 .HasColumnType("text"); 39 40 b.Property<string>("city") 41 .HasColumnType("text"); 42 43 b.Property<string>("microsoftEmail") 44 .HasColumnType("text"); 45 46 b.Property<string>("municipality") 47 .HasColumnType("text"); 48 49 b.Property<string>("phoneNumber") 50 .HasColumnType("text"); 51 52 b.HasKey("Id"); 53 54 b.HasIndex("UserId") 55 .IsUnique(); 56 57 b.ToTable("ContactInfo"); 58 }); 59 60 modelBuilder.Entity("iknow_api.Models.EnrollmentInfo", b => 61 { 62 b.Property<int>("Id") 63 .ValueGeneratedOnAdd() 64 .HasColumnType("integer"); 65 66 NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); 67 68 b.Property<int>("UserId") 69 .HasColumnType("integer"); 70 71 b.Property<int>("enrollmentYear") 72 .HasColumnType("integer"); 73 74 b.Property<int>("major") 75 .HasColumnType("integer"); 76 77 b.HasKey("Id"); 78 79 b.HasIndex("UserId") 80 .IsUnique(); 81 82 b.ToTable("EnrollmentInfo"); 83 }); 84 85 modelBuilder.Entity("iknow_api.Models.HighSchool", b => 86 { 87 b.Property<int>("Id") 88 .ValueGeneratedOnAdd() 89 .HasColumnType("integer"); 90 91 NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); 92 93 b.Property<float>("GPA") 94 .HasColumnType("real"); 95 96 b.Property<int>("UserId") 97 .HasColumnType("integer"); 98 99 b.Property<int>("tip") 100 .HasColumnType("integer"); 101 102 b.HasKey("Id"); 103 104 b.HasIndex("UserId") 105 .IsUnique(); 106 107 b.ToTable("HighSchool"); 33 108 b.Property<DateTime>("ExpiresAt") 34 109 .HasColumnType("timestamp with time zone"); … … 88 163 }); 89 164 165 modelBuilder.Entity("iknow_api.Models.ContactInfo", b => 166 { 167 b.HasOne("iknow_api.Models.User", "User") 168 .WithOne("ContactInfo") 169 .HasForeignKey("iknow_api.Models.ContactInfo", "UserId") 90 170 modelBuilder.Entity("iknow_api.Models.RefreshToken", b => 91 171 { … … 98 178 b.Navigation("User"); 99 179 }); 180 181 modelBuilder.Entity("iknow_api.Models.EnrollmentInfo", b => 182 { 183 b.HasOne("iknow_api.Models.User", "User") 184 .WithOne("EnrollmentInfo") 185 .HasForeignKey("iknow_api.Models.EnrollmentInfo", "UserId") 186 .OnDelete(DeleteBehavior.Cascade) 187 .IsRequired(); 188 189 b.Navigation("User"); 190 }); 191 192 modelBuilder.Entity("iknow_api.Models.HighSchool", b => 193 { 194 b.HasOne("iknow_api.Models.User", "User") 195 .WithOne("HighSchool") 196 .HasForeignKey("iknow_api.Models.HighSchool", "UserId") 197 .OnDelete(DeleteBehavior.Cascade) 198 .IsRequired(); 199 200 b.Navigation("User"); 201 }); 202 203 modelBuilder.Entity("iknow_api.Models.User", b => 204 { 205 b.Navigation("ContactInfo"); 206 207 b.Navigation("EnrollmentInfo"); 208 209 b.Navigation("HighSchool"); 210 }); 100 211 #pragma warning restore 612, 618 101 212 } -
iknow-api/Models/User.cs
rc2e73b6 r4708118 21 21 public DateTime CreatedAt { get; set; } 22 22 public UserRole Role { get; set; } 23 public HighSchool? HighSchool { get; set; } 24 public ContactInfo? ContactInfo { get; set; } 25 public EnrollmentInfo? EnrollmentInfo { get; set; } 23 26 24 27 } -
iknow-api/Program.cs
rc2e73b6 r4708118 1 1 using System.Text; 2 using System.Text.Json.Serialization; 2 3 using iknow_api.Data; 3 4 using iknow_api.Repositories; … … 33 34 }); 34 35 // Add services to the container. 35 builder.Services.AddControllers(); 36 builder.Services.AddControllers() 37 .AddJsonOptions(options => 38 { 39 options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; 40 }); 36 41 builder.Services.AddOpenApi(); 37 42 … … 42 47 // Register your services 43 48 builder.Services.AddScoped<IAuthService, AuthService>(); 49 builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation 50 builder.Services.AddScoped<IUserService, UserService>(); 51 44 52 builder.Services.AddScoped<IRefreshTokenService, RefreshTokenService>(); 45 53 builder.Services.AddScoped<IUserRepository, UserRepository>(); -
iknow-api/Repository/Implementations/UserRepository.cs
rc2e73b6 r4708118 24 24 return await _context.User.FirstOrDefaultAsync(u => u.Email == username); 25 25 } 26 27 public async Task<User?> GetUserByIdAsync(int id) 28 { 29 return await _context.User 30 .Include(u => u.ContactInfo) 31 .Include(u => u.EnrollmentInfo) 32 .Include(u => u.HighSchool) 33 .FirstOrDefaultAsync(u => u.Id == id); 34 } 35 36 26 37 public async Task<User?> GetOnlyUserByIdAsync(int id) 27 38 { … … 33 44 await _context.SaveChangesAsync(); 34 45 } 46 public async Task AddContactAsync(ContactInfo contactInfo) 47 { 48 _context.ContactInfo.Add(contactInfo); 49 await _context.SaveChangesAsync(); 50 } 51 public async Task AddEnrollmentAsync(EnrollmentInfo enrollment) 52 { 53 _context.EnrollmentInfo.Add(enrollment); 54 await _context.SaveChangesAsync(); 55 } 56 public async Task AddHighSchoolAsync(HighSchool highSchool) 57 { 58 _context.HighSchool.Add(highSchool); 59 await _context.SaveChangesAsync(); 60 } 35 61 36 62 public async Task<int> GetUsersCountAsync() -
iknow-api/Repository/Interface/IUserRepository.cs
rc2e73b6 r4708118 7 7 Task<User?> GetUserByUsernameAsync(string username); 8 8 Task AddUserAsync(User user); 9 Task AddContactAsync(ContactInfo contactInfo); 10 Task AddEnrollmentAsync(EnrollmentInfo enrollment); 11 Task AddHighSchoolAsync(HighSchool highSchool); 9 12 Task<int> GetUsersCountAsync(); 13 Task<User> GetUserByIdAsync(int id); 10 14 Task<User?> GetOnlyUserByIdAsync(int id); 11 15 -
iknow-api/Services/Implementations/AuthService.cs
rc2e73b6 r4708118 45 45 46 46 await _userRepository.AddUserAsync(user); 47 int userId = user.Id; 48 var contactInfo = new ContactInfo 49 { 50 UserId = userId, 51 city = registerDto.city, 52 address = registerDto.address, 53 municipality = registerDto.municipality, 54 phoneNumber = registerDto.phoneNumber, 55 microsoftEmail = registerDto.microsoftEmail 56 }; 57 await _userRepository.AddContactAsync(contactInfo); 58 var enrollmentInfo = new EnrollmentInfo 59 { 60 UserId = userId, 61 enrollmentYear = registerDto.enrollmentYear, 62 quota = (Models.quota)registerDto.quotaType, 63 major = (Models.major)registerDto.majorType 64 }; 65 await _userRepository.AddEnrollmentAsync(enrollmentInfo); 66 await _userRepository.AddHighSchoolAsync(new HighSchool 67 { 68 UserId = userId, 69 GPA = registerDto.gpa, 70 tip = (Models.type)registerDto.tip 71 }); 47 72 return true; 48 73 }
Note:
See TracChangeset
for help on using the changeset viewer.
