Changeset c0256f3
- Timestamp:
- 10/27/25 21:50:02 (11 months ago)
- Branches:
- master
- Children:
- e423ff3
- Parents:
- 4f5d8fd
- Location:
- iknow-api
- Files:
-
- 2 added
- 8 edited
-
Controllers/UserController.cs (modified) (1 diff)
-
DTOs/UserDTO.cs (modified) (2 diffs)
-
Migrations/20251027191028_dbRelations.Designer.cs (added)
-
Migrations/20251027191028_dbRelations.cs (added)
-
Migrations/AppDbContextModelSnapshot.cs (modified) (7 diffs)
-
Models/User.cs (modified) (1 diff)
-
Program.cs (modified) (2 diffs)
-
Repository/Implementations/UserRepository.cs (modified) (2 diffs)
-
Repository/Interface/IUserRepository.cs (modified) (1 diff)
-
Services/Implementations/AuthService.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Controllers/UserController.cs
r4f5d8fd rc0256f3 26 26 var userData = await _userService.GetUserData(token); 27 27 if (userData == null) return Ok(new { info = "can't get info" }); 28 return Ok(new { Token= userData });28 return Ok(new { User = userData }); 29 29 } 30 30 return null; -
iknow-api/DTOs/UserDTO.cs
r4f5d8fd rc0256f3 22 22 public DateTime Bday { get; set; } 23 23 public UserRole Role { get; set; } 24 public float gpa { get; set; } 25 public type tip { get; set; } 26 public string city { get; set; } = string.Empty; 27 public string address { get; set; } = string.Empty; 28 public string municipality { get; set; } = string.Empty; 29 public string phoneNumber { get; set; } = string.Empty; 30 public string microsoftEmail { get; set; } = string.Empty; 31 public int enrollmentYear { get; set; } 32 public quota quotaType { get; set; } 33 public major majorType { get; set; } 34 24 35 } 25 36 … … 44 55 Student 45 56 } 57 public enum type 58 { 59 strucen, gimnazija 60 } 61 public enum quota 62 { 63 drzavna, privatna, stipendija 64 } 65 public enum major 66 { 67 SIIS, PIT, KN, KI, IMB, IE, SSP, SEIS 68 } 46 69 } -
iknow-api/Migrations/AppDbContextModelSnapshot.cs
r4f5d8fd rc0256f3 51 51 b.HasKey("Id"); 52 52 53 b.HasIndex("UserId"); 53 b.HasIndex("UserId") 54 .IsUnique(); 54 55 55 56 b.ToTable("ContactInfo"); … … 75 76 b.HasKey("Id"); 76 77 77 b.HasIndex("UserId"); 78 b.HasIndex("UserId") 79 .IsUnique(); 78 80 79 81 b.ToTable("EnrollmentInfo"); … … 99 101 b.HasKey("Id"); 100 102 101 b.HasIndex("UserId"); 103 b.HasIndex("UserId") 104 .IsUnique(); 102 105 103 106 b.ToTable("HighSchool"); … … 144 147 { 145 148 b.HasOne("iknow_api.Models.User", "User") 146 .With Many()147 .HasForeignKey(" UserId")149 .WithOne("ContactInfo") 150 .HasForeignKey("iknow_api.Models.ContactInfo", "UserId") 148 151 .OnDelete(DeleteBehavior.Cascade) 149 152 .IsRequired(); … … 155 158 { 156 159 b.HasOne("iknow_api.Models.User", "User") 157 .With Many()158 .HasForeignKey(" UserId")160 .WithOne("EnrollmentInfo") 161 .HasForeignKey("iknow_api.Models.EnrollmentInfo", "UserId") 159 162 .OnDelete(DeleteBehavior.Cascade) 160 163 .IsRequired(); … … 166 169 { 167 170 b.HasOne("iknow_api.Models.User", "User") 168 .With Many()169 .HasForeignKey(" UserId")171 .WithOne("HighSchool") 172 .HasForeignKey("iknow_api.Models.HighSchool", "UserId") 170 173 .OnDelete(DeleteBehavior.Cascade) 171 174 .IsRequired(); … … 173 176 b.Navigation("User"); 174 177 }); 178 179 modelBuilder.Entity("iknow_api.Models.User", b => 180 { 181 b.Navigation("ContactInfo"); 182 183 b.Navigation("EnrollmentInfo"); 184 185 b.Navigation("HighSchool"); 186 }); 175 187 #pragma warning restore 612, 618 176 188 } -
iknow-api/Models/User.cs
r4f5d8fd rc0256f3 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; } 26 23 27 } 24 28 } -
iknow-api/Program.cs
r4f5d8fd rc0256f3 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 -
iknow-api/Repository/Implementations/UserRepository.cs
r4f5d8fd rc0256f3 25 25 } 26 26 27 public async Task<User > GetUserByIdAsync(int id)27 public async Task<User?> GetUserByIdAsync(int id) 28 28 { 29 return await _context.User.FirstOrDefaultAsync(u => u.Id == id); 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); 30 34 } 31 35 … … 36 40 await _context.SaveChangesAsync(); 37 41 } 42 public async Task AddContactAsync(ContactInfo contactInfo) 43 { 44 _context.ContactInfo.Add(contactInfo); 45 await _context.SaveChangesAsync(); 46 } 47 public async Task AddEnrollmentAsync(EnrollmentInfo enrollment) 48 { 49 _context.EnrollmentInfo.Add(enrollment); 50 await _context.SaveChangesAsync(); 51 } 52 public async Task AddHighSchoolAsync(HighSchool highSchool) 53 { 54 _context.HighSchool.Add(highSchool); 55 await _context.SaveChangesAsync(); 56 } 38 57 39 58 public async Task<int> GetUsersCountAsync() -
iknow-api/Repository/Interface/IUserRepository.cs
r4f5d8fd rc0256f3 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(); 10 13 Task<User> GetUserByIdAsync(int id); -
iknow-api/Services/Implementations/AuthService.cs
r4f5d8fd rc0256f3 40 40 41 41 await _userRepository.AddUserAsync(user); 42 int userId = user.Id; 43 var contactInfo = new ContactInfo 44 { 45 UserId = userId, 46 city = registerDto.city, 47 address = registerDto.address, 48 municipality = registerDto.municipality, 49 phoneNumber = registerDto.phoneNumber, 50 microsoftEmail = registerDto.microsoftEmail 51 }; 52 await _userRepository.AddContactAsync(contactInfo); 53 var enrollmentInfo = new EnrollmentInfo 54 { 55 UserId = userId, 56 enrollmentYear = registerDto.enrollmentYear, 57 quota = (Models.quota)registerDto.quotaType, 58 major = (Models.major)registerDto.majorType 59 }; 60 await _userRepository.AddEnrollmentAsync(enrollmentInfo); 61 await _userRepository.AddHighSchoolAsync(new HighSchool 62 { 63 UserId = userId, 64 GPA = registerDto.gpa, 65 tip = (Models.type)registerDto.tip 66 }); 42 67 return true; 43 68 }
Note:
See TracChangeset
for help on using the changeset viewer.
