Changeset 4708118 for iknow-api


Ignore:
Timestamp:
10/28/25 10:51:44 (11 months ago)
Author:
GitHub <noreply@…>
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)
Message:

Merge pull request #6 from stefansaveski/feature/getUser

Feature/get user

Location:
iknow-api
Files:
10 added
8 edited

Legend:

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

    rc2e73b6 r4708118  
    77        public string Password { get; set; } = string.Empty;
    88        public bool GenerateRefreshToken { get; set; }
     9    }
     10    public class GetUserDataDto
     11    {
     12        public string JWT { get; set; }
    913    }
    1014
     
    1923        public DateTime Bday { get; set; }
    2024        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
    2136    }
    2237
     
    4156        Student
    4257    }
     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    }
    4370}
  • iknow-api/Data/AppDbContext.cs

    rc2e73b6 r4708118  
    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        public DbSet<RefreshToken> RefreshToken { get; set; }
    1316    }
  • iknow-api/Migrations/AppDbContextModelSnapshot.cs

    rc2e73b6 r4708118  
    2323            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
    2424
     25            modelBuilder.Entity("iknow_api.Models.ContactInfo", b =>
    2526            modelBuilder.Entity("iknow_api.Models.RefreshToken", b =>
    2627                {
     
    3132                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
    3233
     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");
    33108                    b.Property<DateTime>("ExpiresAt")
    34109                        .HasColumnType("timestamp with time zone");
     
    88163                });
    89164
     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")
    90170            modelBuilder.Entity("iknow_api.Models.RefreshToken", b =>
    91171                {
     
    98178                    b.Navigation("User");
    99179                });
     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                });
    100211#pragma warning restore 612, 618
    101212        }
  • iknow-api/Models/User.cs

    rc2e73b6 r4708118  
    2121        public DateTime CreatedAt { get; set; }
    2222        public UserRole Role { get; set; }
     23        public HighSchool? HighSchool { get; set; }
     24        public ContactInfo? ContactInfo { get; set; }
     25        public EnrollmentInfo? EnrollmentInfo { get; set; }
    2326
    2427    }
  • iknow-api/Program.cs

    rc2e73b6 r4708118  
    11using System.Text;
     2using System.Text.Json.Serialization;
    23using iknow_api.Data;
    34using iknow_api.Repositories;
     
    3334});
    3435// Add services to the container.
    35 builder.Services.AddControllers();
     36builder.Services.AddControllers()
     37    .AddJsonOptions(options =>
     38    {
     39        options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
     40    });
    3641builder.Services.AddOpenApi();
    3742
     
    4247// Register your services
    4348builder.Services.AddScoped<IAuthService, AuthService>();
     49builder.Services.AddScoped<IUserRepository, UserRepository>(); // You'll need to add the UserRepository implementation
     50builder.Services.AddScoped<IUserService, UserService>();
     51
    4452builder.Services.AddScoped<IRefreshTokenService, RefreshTokenService>();
    4553builder.Services.AddScoped<IUserRepository, UserRepository>();
  • iknow-api/Repository/Implementations/UserRepository.cs

    rc2e73b6 r4708118  
    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
     30                .Include(u => u.ContactInfo)
     31                .Include(u => u.EnrollmentInfo)
     32                .Include(u => u.HighSchool)
     33                .FirstOrDefaultAsync(u => u.Id == id);
     34        }
     35
     36
    2637        public async Task<User?> GetOnlyUserByIdAsync(int id)
    2738        {
     
    3344            await _context.SaveChangesAsync();
    3445        }
     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        }       
    3561
    3662        public async Task<int> GetUsersCountAsync()
  • iknow-api/Repository/Interface/IUserRepository.cs

    rc2e73b6 r4708118  
    77        Task<User?> GetUserByUsernameAsync(string username);
    88        Task AddUserAsync(User user);
     9        Task AddContactAsync(ContactInfo contactInfo);
     10        Task AddEnrollmentAsync(EnrollmentInfo enrollment);
     11        Task AddHighSchoolAsync(HighSchool highSchool);
    912        Task<int> GetUsersCountAsync();
     13        Task<User> GetUserByIdAsync(int id);
    1014        Task<User?> GetOnlyUserByIdAsync(int id);
    1115
  • iknow-api/Services/Implementations/AuthService.cs

    rc2e73b6 r4708118  
    4545
    4646            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            });
    4772            return true;
    4873        }
Note: See TracChangeset for help on using the changeset viewer.