From 9dbb2abf901af71ed7981fa663f1d91bc57c0376 Mon Sep 17 00:00:00 2001 From: VoOneChek Date: Sun, 25 May 2025 20:59:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=91=D0=94=20+=20=D0=BA=D1=80=D1=83=D0=B4=20=D1=81=D1=82?= =?UTF-8?q?=D1=83=D0=B4=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTOs/Student/GradeInStudentDto.cs | 21 + .../DTOs/Student/StudentCreateDto.cs | 16 + .../DTOs/Student/StudentReadDto.cs | 21 + .../DTOs/Student/StudentTableDto.cs | 15 + .../GradeBookServer.Application.csproj | 13 + .../Interfaces/IBaseRepository.cs | 21 + .../Services/StudentService.cs | 96 +++++ GradeBookServer.Domain/Entities/Direction.cs | 21 + GradeBookServer.Domain/Entities/Discipline.cs | 19 + GradeBookServer.Domain/Entities/Faculty.cs | 16 + GradeBookServer.Domain/Entities/Grade.cs | 22 + GradeBookServer.Domain/Entities/Group.cs | 20 + GradeBookServer.Domain/Entities/Student.cs | 21 + GradeBookServer.Domain/Entities/User.cs | 22 + GradeBookServer.Domain/Entities/Vedomost.cs | 30 ++ GradeBookServer.Domain/Enums/ExamType.cs | 15 + GradeBookServer.Domain/Enums/GradeValue.cs | 18 + .../Enums/StatusVedоmost.cs | 15 + GradeBookServer.Domain/Enums/UserRole.cs | 14 + .../GradeBookServer.Domain.csproj | 9 + .../Data/ApplicationDbContext.cs | 27 ++ .../GradeBookServer.Infrastructure.csproj | 21 + .../20250525163835_AllBD.Designer.cs | 380 ++++++++++++++++++ .../Migrations/20250525163835_AllBD.cs | 285 +++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 377 +++++++++++++++++ .../Repositories/BaseRepository.cs | 64 +++ .../Controllers/StudentController.cs | 61 +++ .../GradeBookServer.WebAPI.csproj | 30 ++ .../GradeBookServer.WebAPI.http | 6 + .../GradeBookServer.WebAPI.sln | 43 ++ GradeBookServer.WebAPI/Program.cs | 55 +++ .../Properties/launchSettings.json | 41 ++ .../appsettings.Development.json | 8 + GradeBookServer.WebAPI/appsettings.json | 12 + 34 files changed, 1855 insertions(+) create mode 100644 GradeBookServer.Application/DTOs/Student/GradeInStudentDto.cs create mode 100644 GradeBookServer.Application/DTOs/Student/StudentCreateDto.cs create mode 100644 GradeBookServer.Application/DTOs/Student/StudentReadDto.cs create mode 100644 GradeBookServer.Application/DTOs/Student/StudentTableDto.cs create mode 100644 GradeBookServer.Application/GradeBookServer.Application.csproj create mode 100644 GradeBookServer.Application/Interfaces/IBaseRepository.cs create mode 100644 GradeBookServer.Application/Services/StudentService.cs create mode 100644 GradeBookServer.Domain/Entities/Direction.cs create mode 100644 GradeBookServer.Domain/Entities/Discipline.cs create mode 100644 GradeBookServer.Domain/Entities/Faculty.cs create mode 100644 GradeBookServer.Domain/Entities/Grade.cs create mode 100644 GradeBookServer.Domain/Entities/Group.cs create mode 100644 GradeBookServer.Domain/Entities/Student.cs create mode 100644 GradeBookServer.Domain/Entities/User.cs create mode 100644 GradeBookServer.Domain/Entities/Vedomost.cs create mode 100644 GradeBookServer.Domain/Enums/ExamType.cs create mode 100644 GradeBookServer.Domain/Enums/GradeValue.cs create mode 100644 GradeBookServer.Domain/Enums/StatusVedоmost.cs create mode 100644 GradeBookServer.Domain/Enums/UserRole.cs create mode 100644 GradeBookServer.Domain/GradeBookServer.Domain.csproj create mode 100644 GradeBookServer.Infrastructure/Data/ApplicationDbContext.cs create mode 100644 GradeBookServer.Infrastructure/GradeBookServer.Infrastructure.csproj create mode 100644 GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.Designer.cs create mode 100644 GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.cs create mode 100644 GradeBookServer.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 GradeBookServer.Infrastructure/Repositories/BaseRepository.cs create mode 100644 GradeBookServer.WebAPI/Controllers/StudentController.cs create mode 100644 GradeBookServer.WebAPI/GradeBookServer.WebAPI.csproj create mode 100644 GradeBookServer.WebAPI/GradeBookServer.WebAPI.http create mode 100644 GradeBookServer.WebAPI/GradeBookServer.WebAPI.sln create mode 100644 GradeBookServer.WebAPI/Program.cs create mode 100644 GradeBookServer.WebAPI/Properties/launchSettings.json create mode 100644 GradeBookServer.WebAPI/appsettings.Development.json create mode 100644 GradeBookServer.WebAPI/appsettings.json diff --git a/GradeBookServer.Application/DTOs/Student/GradeInStudentDto.cs b/GradeBookServer.Application/DTOs/Student/GradeInStudentDto.cs new file mode 100644 index 0000000..5ed64b8 --- /dev/null +++ b/GradeBookServer.Application/DTOs/Student/GradeInStudentDto.cs @@ -0,0 +1,21 @@ +using GradeBookServer.Domain.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.DTOs.Student +{ + public class GradeInStudentDto + { + public int ID { get; set; } + public GradeValue GradeValue { get; set; } + + public int VedomostID { get; set; } + public string DisciplineName { get; set; } = string.Empty; + public int Semester { get; set; } + public DateOnly AcademicYear { get; set; } + } + +} diff --git a/GradeBookServer.Application/DTOs/Student/StudentCreateDto.cs b/GradeBookServer.Application/DTOs/Student/StudentCreateDto.cs new file mode 100644 index 0000000..f2e298f --- /dev/null +++ b/GradeBookServer.Application/DTOs/Student/StudentCreateDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.DTOs.Student +{ + public class StudentCreateDto + { + public string FullName { get; set; } = string.Empty; + public int Age { get; set; } + public int GroupID { get; set; } + } + +} diff --git a/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs b/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs new file mode 100644 index 0000000..843cda5 --- /dev/null +++ b/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.DTOs.Student +{ + public class StudentReadDto + { + public int ID { get; set; } + public required string FullName { get; set; } + public int Age { get; set; } + + public int GroupID { get; set; } + public string? GroupName { get; set; } + + public List Grades { get; set; } = new(); + } + +} diff --git a/GradeBookServer.Application/DTOs/Student/StudentTableDto.cs b/GradeBookServer.Application/DTOs/Student/StudentTableDto.cs new file mode 100644 index 0000000..537a2fd --- /dev/null +++ b/GradeBookServer.Application/DTOs/Student/StudentTableDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.DTOs.Student +{ + public class StudentTableDto + { + public int ID { get; set; } + public required string FullName { get; set; } + public int Age { get; set; } + } +} diff --git a/GradeBookServer.Application/GradeBookServer.Application.csproj b/GradeBookServer.Application/GradeBookServer.Application.csproj new file mode 100644 index 0000000..7d0f4b3 --- /dev/null +++ b/GradeBookServer.Application/GradeBookServer.Application.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/GradeBookServer.Application/Interfaces/IBaseRepository.cs b/GradeBookServer.Application/Interfaces/IBaseRepository.cs new file mode 100644 index 0000000..1226060 --- /dev/null +++ b/GradeBookServer.Application/Interfaces/IBaseRepository.cs @@ -0,0 +1,21 @@ +using GradeBookServer.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.Interfaces +{ + public interface IBaseRepository where TEntity : class + { + Task GetByIdAsync(int id); + Task?> GetAllAsync(); + Task AddAsync(TEntity entity); + Task UpdateAsync(TEntity entity); + Task DeleteAsync(int id); + Task GetByIdWithIncludeAsync( + int id, Expression> idSelector, params Expression>[] includes); + } +} diff --git a/GradeBookServer.Application/Services/StudentService.cs b/GradeBookServer.Application/Services/StudentService.cs new file mode 100644 index 0000000..313ff39 --- /dev/null +++ b/GradeBookServer.Application/Services/StudentService.cs @@ -0,0 +1,96 @@ +using GradeBookServer.Application.DTOs.Student; +using GradeBookServer.Application.Interfaces; +using GradeBookServer.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Application.Services +{ + public class StudentService + { + private readonly IBaseRepository _baseRepository; + + public StudentService(IBaseRepository baseRepository) + { + _baseRepository = baseRepository; + } + + public async Task GetStudentByIdAsync(int id) + { + var student = await _baseRepository.GetByIdWithIncludeAsync( + id, + s => s.ID == id, + s => s.Group!, + s => s.Grades, + s => s.Grades.Select(g => g.Vedomost), + s => s.Grades.Select(g => g.Vedomost!.Discipline) + ); + + if (student == null) + return null; + + return new StudentReadDto + { + ID = student.ID, + FullName = student.FullName, + Age = student.Age, + GroupName = student.Group?.Name ?? "—", + Grades = student.Grades.Select(g => new GradeInStudentDto + { + ID = g.ID, + GradeValue = g.GradeValue, + DisciplineName = g.Vedomost?.Discipline?.Name ?? "Не указано", + Semester = g.Vedomost?.Semester ?? 0, + AcademicYear = g.Vedomost?.AcademicYear ?? default + }).ToList() + }; + } + + public async Task?> GetAllStudentsAsync() + { + var students = await _baseRepository.GetAllAsync(); + + if (students == null) + return null; + + return students.Select(s => new StudentTableDto + { + ID = s.ID, + FullName = s.FullName, + Age = s.Age + }); + } + + public async Task AddStudentAsync(StudentCreateDto studentDto) + { + var student = new Student + { + FullName = studentDto.FullName, + Age = studentDto.Age, + GroupID = studentDto.GroupID + }; + + await _baseRepository.AddAsync(student); + } + + public async Task UpdateStudentAsync(int id, StudentCreateDto dto) + { + var student = await _baseRepository.GetByIdAsync(id); + if (student == null) return; + + student.FullName = dto.FullName; + student.Age = dto.Age; + student.GroupID = dto.GroupID; + + await _baseRepository.UpdateAsync(student); + } + + public async Task DeleteStudentAsync(int id) + { + await _baseRepository.DeleteAsync(id); + } + } +} diff --git a/GradeBookServer.Domain/Entities/Direction.cs b/GradeBookServer.Domain/Entities/Direction.cs new file mode 100644 index 0000000..850cd91 --- /dev/null +++ b/GradeBookServer.Domain/Entities/Direction.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Direction + { + public int ID { get; set; } + public required string Name { get; set; } + + public int FacultyID { get; set; } + public Faculty? Faculty { get; set; } + + public ICollection Disciplines { get; set; } = new List(); + public ICollection Groups { get; set; } = new List(); + } +} diff --git a/GradeBookServer.Domain/Entities/Discipline.cs b/GradeBookServer.Domain/Entities/Discipline.cs new file mode 100644 index 0000000..bc4d7e3 --- /dev/null +++ b/GradeBookServer.Domain/Entities/Discipline.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Discipline + { + public int ID { get; set; } + public required string Name { get; set; } + public int TotalHours { get; set; } + + public ICollection Directions { get; set; } = new List(); + public ICollection Vedomosti { get; set; } = new List(); + } + +} diff --git a/GradeBookServer.Domain/Entities/Faculty.cs b/GradeBookServer.Domain/Entities/Faculty.cs new file mode 100644 index 0000000..3e4e2b4 --- /dev/null +++ b/GradeBookServer.Domain/Entities/Faculty.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Faculty + { + public int ID { get; set; } + public required string Name { get; set; } + + public ICollection Directions { get; set; } = new List(); + } +} diff --git a/GradeBookServer.Domain/Entities/Grade.cs b/GradeBookServer.Domain/Entities/Grade.cs new file mode 100644 index 0000000..f8c5af7 --- /dev/null +++ b/GradeBookServer.Domain/Entities/Grade.cs @@ -0,0 +1,22 @@ +using GradeBookServer.Domain.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Grade + { + public int ID { get; set; } + + public int StudentID { get; set; } + public Student? Student { get; set; } + + public int VedomostID { get; set; } + public Vedomost? Vedomost { get; set; } + + public GradeValue GradeValue { get; set; } + } +} diff --git a/GradeBookServer.Domain/Entities/Group.cs b/GradeBookServer.Domain/Entities/Group.cs new file mode 100644 index 0000000..7602b92 --- /dev/null +++ b/GradeBookServer.Domain/Entities/Group.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Group + { + public int ID { get; set; } + public required string Name { get; set; } + + public int DirectionID { get; set; } + public Direction? Direction { get; set; } + + public ICollection Students { get; set; } = new List(); + public ICollection Vedomosti { get; set; } = new List(); + } +} diff --git a/GradeBookServer.Domain/Entities/Student.cs b/GradeBookServer.Domain/Entities/Student.cs new file mode 100644 index 0000000..569c69d --- /dev/null +++ b/GradeBookServer.Domain/Entities/Student.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Student + { + public int ID { get; set; } + public required string FullName { get; set; } + public int Age { get; set; } + + public int GroupID { get; set; } + public Group? Group { get; set; } + + public ICollection Grades { get; set; } = new List(); + } + +} diff --git a/GradeBookServer.Domain/Entities/User.cs b/GradeBookServer.Domain/Entities/User.cs new file mode 100644 index 0000000..337a49f --- /dev/null +++ b/GradeBookServer.Domain/Entities/User.cs @@ -0,0 +1,22 @@ +using GradeBookServer.Domain.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class User + { + public int Id { get; set; } + public required string Name { get; set; } + public required string Email { get; set; } + public string? PhoneNumber { get; set; } + public required string Password { get; set; } + public UserRole Role { get; set; } + + public ICollection Vedomosti { get; set; } = new List(); + + } +} diff --git a/GradeBookServer.Domain/Entities/Vedomost.cs b/GradeBookServer.Domain/Entities/Vedomost.cs new file mode 100644 index 0000000..e80cdda --- /dev/null +++ b/GradeBookServer.Domain/Entities/Vedomost.cs @@ -0,0 +1,30 @@ +using GradeBookServer.Domain.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Entities +{ + public class Vedomost + { + public int ID { get; set; } + public ExamType ExamType { get; set; } + public StatusVedomost Status { get; set; } + public DateOnly AcademicYear { get; set; } + public int Semester { get; set; } + public int Hours { get; set; } + + public int GroupID { get; set; } + public Group? Group { get; set; } + + public int DisciplineID { get; set; } + public Discipline? Discipline { get; set; } + + public int? ProfessorID { get; set; } + public User? Professor { get; set; } + + public ICollection Grades { get; set; } = new List(); + } +} diff --git a/GradeBookServer.Domain/Enums/ExamType.cs b/GradeBookServer.Domain/Enums/ExamType.cs new file mode 100644 index 0000000..bc8841a --- /dev/null +++ b/GradeBookServer.Domain/Enums/ExamType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Enums +{ + public enum ExamType + { + Pass, + Exam, + GradedPass, + } +} diff --git a/GradeBookServer.Domain/Enums/GradeValue.cs b/GradeBookServer.Domain/Enums/GradeValue.cs new file mode 100644 index 0000000..268bf59 --- /dev/null +++ b/GradeBookServer.Domain/Enums/GradeValue.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Enums +{ + public enum GradeValue + { + Excellent, + Good, + Satisfactory, + Fail, + Absence, + Pass, + } +} diff --git a/GradeBookServer.Domain/Enums/StatusVedоmost.cs b/GradeBookServer.Domain/Enums/StatusVedоmost.cs new file mode 100644 index 0000000..2673670 --- /dev/null +++ b/GradeBookServer.Domain/Enums/StatusVedоmost.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Enums +{ + public enum StatusVedomost + { + Draft, + Completed, + Approved, + } +} diff --git a/GradeBookServer.Domain/Enums/UserRole.cs b/GradeBookServer.Domain/Enums/UserRole.cs new file mode 100644 index 0000000..b8fad0f --- /dev/null +++ b/GradeBookServer.Domain/Enums/UserRole.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Domain.Enums +{ + public enum UserRole + { + Employee, + Professor, + } +} diff --git a/GradeBookServer.Domain/GradeBookServer.Domain.csproj b/GradeBookServer.Domain/GradeBookServer.Domain.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/GradeBookServer.Domain/GradeBookServer.Domain.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/GradeBookServer.Infrastructure/Data/ApplicationDbContext.cs b/GradeBookServer.Infrastructure/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..58567f7 --- /dev/null +++ b/GradeBookServer.Infrastructure/Data/ApplicationDbContext.cs @@ -0,0 +1,27 @@ +using GradeBookServer.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Infrastructure.Data +{ + public class ApplicationDbContext : DbContext + { + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Groups { get; set; } + public DbSet Students { get; set; } + public DbSet Directions { get; set; } + public DbSet Disciplines { get; set; } + public DbSet Faculties { get; set; } + public DbSet Vedomosti { get; set; } + public DbSet Grades { get; set; } + public DbSet Users { get; set; } + } +} diff --git a/GradeBookServer.Infrastructure/GradeBookServer.Infrastructure.csproj b/GradeBookServer.Infrastructure/GradeBookServer.Infrastructure.csproj new file mode 100644 index 0000000..2d1e9ff --- /dev/null +++ b/GradeBookServer.Infrastructure/GradeBookServer.Infrastructure.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.Designer.cs b/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.Designer.cs new file mode 100644 index 0000000..d02431a --- /dev/null +++ b/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.Designer.cs @@ -0,0 +1,380 @@ +// +using System; +using GradeBookServer.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GradeBookServer.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20250525163835_AllBD")] + partial class AllBD + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DirectionDiscipline", b => + { + b.Property("DirectionsID") + .HasColumnType("integer"); + + b.Property("DisciplinesID") + .HasColumnType("integer"); + + b.HasKey("DirectionsID", "DisciplinesID"); + + b.HasIndex("DisciplinesID"); + + b.ToTable("DirectionDiscipline"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("FacultyID") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.HasIndex("FacultyID"); + + b.ToTable("Directions"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TotalHours") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.ToTable("Faculties"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("GradeValue") + .HasColumnType("integer"); + + b.Property("StudentID") + .HasColumnType("integer"); + + b.Property("VedomostID") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("StudentID"); + + b.HasIndex("VedomostID"); + + b.ToTable("Grades"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("DirectionID") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.HasIndex("DirectionID"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupID") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("GroupID"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("AcademicYear") + .HasColumnType("date"); + + b.Property("DisciplineID") + .HasColumnType("integer"); + + b.Property("ExamType") + .HasColumnType("integer"); + + b.Property("GroupID") + .HasColumnType("integer"); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("ProfessorID") + .HasColumnType("integer"); + + b.Property("Semester") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("DisciplineID"); + + b.HasIndex("GroupID"); + + b.HasIndex("ProfessorID"); + + b.ToTable("Vedomosti"); + }); + + modelBuilder.Entity("DirectionDiscipline", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Direction", null) + .WithMany() + .HasForeignKey("DirectionsID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Discipline", null) + .WithMany() + .HasForeignKey("DisciplinesID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Faculty", "Faculty") + .WithMany("Directions") + .HasForeignKey("FacultyID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Faculty"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Student", "Student") + .WithMany("Grades") + .HasForeignKey("StudentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Vedomost", "Vedomost") + .WithMany("Grades") + .HasForeignKey("VedomostID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("Vedomost"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Direction", "Direction") + .WithMany("Groups") + .HasForeignKey("DirectionID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Direction"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Group", "Group") + .WithMany("Students") + .HasForeignKey("GroupID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Discipline", "Discipline") + .WithMany("Vedomosti") + .HasForeignKey("DisciplineID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Group", "Group") + .WithMany("Vedomosti") + .HasForeignKey("GroupID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.User", "Professor") + .WithMany("Vedomosti") + .HasForeignKey("ProfessorID"); + + b.Navigation("Discipline"); + + b.Navigation("Group"); + + b.Navigation("Professor"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.Navigation("Groups"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b => + { + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b => + { + b.Navigation("Directions"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.Navigation("Students"); + + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.Navigation("Grades"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b => + { + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.Navigation("Grades"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.cs b/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.cs new file mode 100644 index 0000000..cbe588b --- /dev/null +++ b/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.cs @@ -0,0 +1,285 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GradeBookServer.Infrastructure.Migrations +{ + /// + public partial class AllBD : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Disciplines", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + TotalHours = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Disciplines", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "Faculties", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Faculties", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: true), + Password = table.Column(type: "text", nullable: false), + Role = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Directions", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + FacultyID = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Directions", x => x.ID); + table.ForeignKey( + name: "FK_Directions_Faculties_FacultyID", + column: x => x.FacultyID, + principalTable: "Faculties", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "DirectionDiscipline", + columns: table => new + { + DirectionsID = table.Column(type: "integer", nullable: false), + DisciplinesID = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DirectionDiscipline", x => new { x.DirectionsID, x.DisciplinesID }); + table.ForeignKey( + name: "FK_DirectionDiscipline_Directions_DirectionsID", + column: x => x.DirectionsID, + principalTable: "Directions", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_DirectionDiscipline_Disciplines_DisciplinesID", + column: x => x.DisciplinesID, + principalTable: "Disciplines", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + DirectionID = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.ID); + table.ForeignKey( + name: "FK_Groups_Directions_DirectionID", + column: x => x.DirectionID, + principalTable: "Directions", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FullName = table.Column(type: "text", nullable: false), + Age = table.Column(type: "integer", nullable: false), + GroupID = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.ID); + table.ForeignKey( + name: "FK_Students_Groups_GroupID", + column: x => x.GroupID, + principalTable: "Groups", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Vedomosti", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ExamType = table.Column(type: "integer", nullable: false), + Status = table.Column(type: "integer", nullable: false), + AcademicYear = table.Column(type: "date", nullable: false), + Semester = table.Column(type: "integer", nullable: false), + Hours = table.Column(type: "integer", nullable: false), + GroupID = table.Column(type: "integer", nullable: false), + DisciplineID = table.Column(type: "integer", nullable: false), + ProfessorID = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Vedomosti", x => x.ID); + table.ForeignKey( + name: "FK_Vedomosti_Disciplines_DisciplineID", + column: x => x.DisciplineID, + principalTable: "Disciplines", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Vedomosti_Groups_GroupID", + column: x => x.GroupID, + principalTable: "Groups", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Vedomosti_Users_ProfessorID", + column: x => x.ProfessorID, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Grades", + columns: table => new + { + ID = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StudentID = table.Column(type: "integer", nullable: false), + VedomostID = table.Column(type: "integer", nullable: false), + GradeValue = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Grades", x => x.ID); + table.ForeignKey( + name: "FK_Grades_Students_StudentID", + column: x => x.StudentID, + principalTable: "Students", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Grades_Vedomosti_VedomostID", + column: x => x.VedomostID, + principalTable: "Vedomosti", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_DirectionDiscipline_DisciplinesID", + table: "DirectionDiscipline", + column: "DisciplinesID"); + + migrationBuilder.CreateIndex( + name: "IX_Directions_FacultyID", + table: "Directions", + column: "FacultyID"); + + migrationBuilder.CreateIndex( + name: "IX_Grades_StudentID", + table: "Grades", + column: "StudentID"); + + migrationBuilder.CreateIndex( + name: "IX_Grades_VedomostID", + table: "Grades", + column: "VedomostID"); + + migrationBuilder.CreateIndex( + name: "IX_Groups_DirectionID", + table: "Groups", + column: "DirectionID"); + + migrationBuilder.CreateIndex( + name: "IX_Students_GroupID", + table: "Students", + column: "GroupID"); + + migrationBuilder.CreateIndex( + name: "IX_Vedomosti_DisciplineID", + table: "Vedomosti", + column: "DisciplineID"); + + migrationBuilder.CreateIndex( + name: "IX_Vedomosti_GroupID", + table: "Vedomosti", + column: "GroupID"); + + migrationBuilder.CreateIndex( + name: "IX_Vedomosti_ProfessorID", + table: "Vedomosti", + column: "ProfessorID"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DirectionDiscipline"); + + migrationBuilder.DropTable( + name: "Grades"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "Vedomosti"); + + migrationBuilder.DropTable( + name: "Disciplines"); + + migrationBuilder.DropTable( + name: "Groups"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Directions"); + + migrationBuilder.DropTable( + name: "Faculties"); + } + } +} diff --git a/GradeBookServer.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/GradeBookServer.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..274dec1 --- /dev/null +++ b/GradeBookServer.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,377 @@ +// +using System; +using GradeBookServer.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GradeBookServer.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DirectionDiscipline", b => + { + b.Property("DirectionsID") + .HasColumnType("integer"); + + b.Property("DisciplinesID") + .HasColumnType("integer"); + + b.HasKey("DirectionsID", "DisciplinesID"); + + b.HasIndex("DisciplinesID"); + + b.ToTable("DirectionDiscipline"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("FacultyID") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.HasIndex("FacultyID"); + + b.ToTable("Directions"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TotalHours") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.ToTable("Faculties"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("GradeValue") + .HasColumnType("integer"); + + b.Property("StudentID") + .HasColumnType("integer"); + + b.Property("VedomostID") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("StudentID"); + + b.HasIndex("VedomostID"); + + b.ToTable("Grades"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("DirectionID") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ID"); + + b.HasIndex("DirectionID"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupID") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("GroupID"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ID")); + + b.Property("AcademicYear") + .HasColumnType("date"); + + b.Property("DisciplineID") + .HasColumnType("integer"); + + b.Property("ExamType") + .HasColumnType("integer"); + + b.Property("GroupID") + .HasColumnType("integer"); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("ProfessorID") + .HasColumnType("integer"); + + b.Property("Semester") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.HasKey("ID"); + + b.HasIndex("DisciplineID"); + + b.HasIndex("GroupID"); + + b.HasIndex("ProfessorID"); + + b.ToTable("Vedomosti"); + }); + + modelBuilder.Entity("DirectionDiscipline", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Direction", null) + .WithMany() + .HasForeignKey("DirectionsID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Discipline", null) + .WithMany() + .HasForeignKey("DisciplinesID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Faculty", "Faculty") + .WithMany("Directions") + .HasForeignKey("FacultyID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Faculty"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Student", "Student") + .WithMany("Grades") + .HasForeignKey("StudentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Vedomost", "Vedomost") + .WithMany("Grades") + .HasForeignKey("VedomostID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("Vedomost"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Direction", "Direction") + .WithMany("Groups") + .HasForeignKey("DirectionID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Direction"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Group", "Group") + .WithMany("Students") + .HasForeignKey("GroupID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.HasOne("GradeBookServer.Domain.Entities.Discipline", "Discipline") + .WithMany("Vedomosti") + .HasForeignKey("DisciplineID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.Group", "Group") + .WithMany("Vedomosti") + .HasForeignKey("GroupID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GradeBookServer.Domain.Entities.User", "Professor") + .WithMany("Vedomosti") + .HasForeignKey("ProfessorID"); + + b.Navigation("Discipline"); + + b.Navigation("Group"); + + b.Navigation("Professor"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b => + { + b.Navigation("Groups"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b => + { + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b => + { + b.Navigation("Directions"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b => + { + b.Navigation("Students"); + + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b => + { + b.Navigation("Grades"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b => + { + b.Navigation("Vedomosti"); + }); + + modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b => + { + b.Navigation("Grades"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs b/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs new file mode 100644 index 0000000..06ec6d9 --- /dev/null +++ b/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs @@ -0,0 +1,64 @@ +using GradeBookServer.Application.Interfaces; +using GradeBookServer.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace GradeBookServer.Infrastructure.Repositories +{ + public class BaseRepository : IBaseRepository where TEntity : class + { + protected readonly DbContext _context; + protected readonly DbSet _dbSet; + + public BaseRepository(DbContext context) + { + _context = context; + _dbSet = context.Set(); + } + + public virtual async Task GetByIdAsync(int id) + => await _dbSet.FindAsync(id); + + public virtual async Task AddAsync(TEntity entity) + { + await _dbSet.AddAsync(entity); + await _context.SaveChangesAsync(); + } + + public virtual async Task?> GetAllAsync() + => await _dbSet.ToListAsync(); + + public virtual async Task UpdateAsync(TEntity entity) + { + _dbSet.Update(entity); + await _context.SaveChangesAsync(); + } + + public virtual async Task DeleteAsync(int id) + { + var entity = await _dbSet.FindAsync(id); + + if (entity != null) + { + _dbSet.Remove(entity); + await _context.SaveChangesAsync(); + } + } + + public async Task GetByIdWithIncludeAsync + (int id, Expression> idSelector, params Expression>[] includes) + { + IQueryable query = _dbSet; + + foreach (var include in includes) + query = query.Include(include); + + return await query.FirstOrDefaultAsync(idSelector); + } + } +} diff --git a/GradeBookServer.WebAPI/Controllers/StudentController.cs b/GradeBookServer.WebAPI/Controllers/StudentController.cs new file mode 100644 index 0000000..bfa6c82 --- /dev/null +++ b/GradeBookServer.WebAPI/Controllers/StudentController.cs @@ -0,0 +1,61 @@ +// WebAPI/Controllers/StudentController.cs + +using GradeBookServer.Application.DTOs.Student; +using GradeBookServer.Application.Services; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace WebAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class StudentController : ControllerBase + { + private readonly StudentService _studentService; + + public StudentController(StudentService studentService) + { + _studentService = studentService; + } + + [HttpGet] + public async Task>> GetAllStudents() + { + var students = await _studentService.GetAllStudentsAsync(); + return Ok(students); + } + + [HttpGet("{id}")] + public async Task> GetStudentById(int id) + { + var student = await _studentService.GetStudentByIdAsync(id); + if (student == null) + { + return NotFound(); + } + return Ok(student); + } + + [HttpPost] + public async Task AddStudent([FromBody] StudentCreateDto studentDto) + { + await _studentService.AddStudentAsync(studentDto); + return CreatedAtAction(nameof(GetStudentById), studentDto); + } + + [HttpPut("{id}")] + public async Task UpdateStudent(int id, [FromBody] StudentCreateDto studentDto) + { + await _studentService.UpdateStudentAsync(id, studentDto); + return NoContent(); + } + + [HttpDelete("{id}")] + public async Task DeleteStudent(int id) + { + await _studentService.DeleteStudentAsync(id); + return NoContent(); + } + } +} diff --git a/GradeBookServer.WebAPI/GradeBookServer.WebAPI.csproj b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.csproj new file mode 100644 index 0000000..f63f67b --- /dev/null +++ b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + diff --git a/GradeBookServer.WebAPI/GradeBookServer.WebAPI.http b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.http new file mode 100644 index 0000000..aca1c75 --- /dev/null +++ b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.http @@ -0,0 +1,6 @@ +@GradeBookServer.WebAPI_HostAddress = http://localhost:5142 + +GET {{GradeBookServer.WebAPI_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/GradeBookServer.WebAPI/GradeBookServer.WebAPI.sln b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.sln new file mode 100644 index 0000000..baee676 --- /dev/null +++ b/GradeBookServer.WebAPI/GradeBookServer.WebAPI.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.WebAPI", "GradeBookServer.WebAPI.csproj", "{8AEE9485-A46E-4145-A1FE-1B280E8C4561}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Domain", "..\GradeBookServer.Domain\GradeBookServer.Domain.csproj", "{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Application", "..\GradeBookServer.Application\GradeBookServer.Application.csproj", "{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Infrastructure", "..\GradeBookServer.Infrastructure\GradeBookServer.Infrastructure.csproj", "{4477C8C0-F545-455E-81A1-576551006D03}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Release|Any CPU.Build.0 = Release|Any CPU + {2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Release|Any CPU.Build.0 = Release|Any CPU + {3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Release|Any CPU.Build.0 = Release|Any CPU + {4477C8C0-F545-455E-81A1-576551006D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4477C8C0-F545-455E-81A1-576551006D03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4477C8C0-F545-455E-81A1-576551006D03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4477C8C0-F545-455E-81A1-576551006D03}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C5267331-1AD7-4C07-B032-18F3D9B9B467} + EndGlobalSection +EndGlobal diff --git a/GradeBookServer.WebAPI/Program.cs b/GradeBookServer.WebAPI/Program.cs new file mode 100644 index 0000000..d757520 --- /dev/null +++ b/GradeBookServer.WebAPI/Program.cs @@ -0,0 +1,55 @@ +using GradeBookServer.Application.Interfaces; +using GradeBookServer.Application.Services; +using GradeBookServer.Infrastructure.Data; +using GradeBookServer.Infrastructure.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +// +builder.Services.AddDbContext(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(options => +{ + options.SwaggerDoc("v1", new OpenApiInfo + { + Version = "1.0.0", + Title = "YumAsia API", + Description = "API ", + }); +}); + +// +builder.Services.AddScoped(); + +builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>)); +builder.Services.AddScoped(); + +builder.Services.AddControllers(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "YumAsia API V1"); + }); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/GradeBookServer.WebAPI/Properties/launchSettings.json b/GradeBookServer.WebAPI/Properties/launchSettings.json new file mode 100644 index 0000000..c484e9c --- /dev/null +++ b/GradeBookServer.WebAPI/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:8634", + "sslPort": 44300 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5142", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7270;http://localhost:5142", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/GradeBookServer.WebAPI/appsettings.Development.json b/GradeBookServer.WebAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/GradeBookServer.WebAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/GradeBookServer.WebAPI/appsettings.json b/GradeBookServer.WebAPI/appsettings.json new file mode 100644 index 0000000..9bdc9cd --- /dev/null +++ b/GradeBookServer.WebAPI/appsettings.json @@ -0,0 +1,12 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Host=localhost;Port=5432;Database=YumAsiaDb;Username=postgres;Password=postgres" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file