From 927ce4826b2d751d27c4c6682512932912b757ef Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 03:44:29 +0100 Subject: [PATCH 01/17] add controller for genre --- .../Genre/Controller/GenresController.cs | 38 ++++++ .../Genre/Repository/GenreRepository.cs | 33 +++++ .../Genre/Repository/IGenreRepository.cs | 7 + .../Genre/Request/CreateGenreRequest.cs | 7 + web-library/Genre/Service/GenreService.cs | 27 ++++ web-library/Genre/Service/IGenreService.cs | 9 ++ .../Migrations/20231201221253_UserWithInfo.cs | 124 ------------------ ...46_userAndUserBasicInfoEntity.Designer.cs} | 55 +++++++- ...231202024346_userAndUserBasicInfoEntity.cs | 74 +++++++++++ web-library/Program.cs | 6 +- web-library/User/Entity/UserBasicInfo.cs | 2 +- web-library/appsettings.Development.json | 3 + 12 files changed, 254 insertions(+), 131 deletions(-) create mode 100644 web-library/Genre/Controller/GenresController.cs create mode 100644 web-library/Genre/Repository/GenreRepository.cs create mode 100644 web-library/Genre/Repository/IGenreRepository.cs create mode 100644 web-library/Genre/Request/CreateGenreRequest.cs create mode 100644 web-library/Genre/Service/GenreService.cs create mode 100644 web-library/Genre/Service/IGenreService.cs delete mode 100644 web-library/Migrations/20231201221253_UserWithInfo.cs rename web-library/Migrations/{20231201221253_UserWithInfo.Designer.cs => 20231202024346_userAndUserBasicInfoEntity.Designer.cs} (78%) create mode 100644 web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs diff --git a/web-library/Genre/Controller/GenresController.cs b/web-library/Genre/Controller/GenresController.cs new file mode 100644 index 0000000..112151e --- /dev/null +++ b/web-library/Genre/Controller/GenresController.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Mvc; + +namespace web_library.Genre.Controller +{ + using Microsoft.AspNetCore.Authorization; + using web_library.Genre.Request; + using web_library.Genre.Service; + + [Route("api/[controller]")] + [ApiController] + public class GenresController : ControllerBase + { + private readonly IGenreService _genreService; + + public GenresController(IGenreService genreService) + { + _genreService = genreService; + } + + // POST: api/Genres + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPost] + [AllowAnonymous] + public ActionResult Post([FromBody] CreateGenreRequest request) + { + try + { + _genreService.createGenre(request); + } + catch + (Exception) + { + return NotFound(); + } + return Ok(); + } + } +} diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs new file mode 100644 index 0000000..a142acd --- /dev/null +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -0,0 +1,33 @@ +namespace web_library.Genre.Repository +{ + using Entity; + public class GenreRepository : IGenreRepository + { + private readonly DataContext _context; + public GenreRepository(DataContext context) + { + _context = context; + } + + public void Add(Genre entity) + { + _context.Add(entity); + _context.SaveChanges(); + } + + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + + public Genre GetByIdOrThrow(int id) + { + throw new NotImplementedException(); + } + + public void Remove(Genre entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/web-library/Genre/Repository/IGenreRepository.cs b/web-library/Genre/Repository/IGenreRepository.cs new file mode 100644 index 0000000..c862514 --- /dev/null +++ b/web-library/Genre/Repository/IGenreRepository.cs @@ -0,0 +1,7 @@ +namespace web_library.Genre.Repository +{ + using Entity; + public interface IGenreRepository : IGenericRepository + { + } +} \ No newline at end of file diff --git a/web-library/Genre/Request/CreateGenreRequest.cs b/web-library/Genre/Request/CreateGenreRequest.cs new file mode 100644 index 0000000..c6cbad7 --- /dev/null +++ b/web-library/Genre/Request/CreateGenreRequest.cs @@ -0,0 +1,7 @@ +namespace web_library.Genre.Request +{ + public class CreateGenreRequest + { + public string Name { get; set; } + } +} diff --git a/web-library/Genre/Service/GenreService.cs b/web-library/Genre/Service/GenreService.cs new file mode 100644 index 0000000..cd8b161 --- /dev/null +++ b/web-library/Genre/Service/GenreService.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using web_library.Genre.Repository; +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + using Entity; + public class GenreService : IGenreService + { + private readonly IGenreRepository _genreRepository; + + public GenreService(IGenreRepository genreRepository) + { + _genreRepository = genreRepository; + } + + public void createGenre(CreateGenreRequest request) + { + var jsonString = JsonConvert.SerializeObject(request); + + Genre? entity = JsonConvert.DeserializeObject(jsonString) ?? throw new NotImplementedException(); + + _genreRepository.Add(entity); + return; + } + } +} diff --git a/web-library/Genre/Service/IGenreService.cs b/web-library/Genre/Service/IGenreService.cs new file mode 100644 index 0000000..8960d6d --- /dev/null +++ b/web-library/Genre/Service/IGenreService.cs @@ -0,0 +1,9 @@ +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + public interface IGenreService + { + void createGenre(CreateGenreRequest request); + } +} \ No newline at end of file diff --git a/web-library/Migrations/20231201221253_UserWithInfo.cs b/web-library/Migrations/20231201221253_UserWithInfo.cs deleted file mode 100644 index 47b528d..0000000 --- a/web-library/Migrations/20231201221253_UserWithInfo.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class UserWithInfo : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "books", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - isbn = table.Column(type: "text", nullable: false), - title = table.Column(type: "text", nullable: false), - author = table.Column(type: "text", nullable: false), - publisher = table.Column(type: "text", nullable: false), - publication_date = table.Column(type: "date", nullable: false), - location = table.Column(type: "text", nullable: false), - description = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_books", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "users", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - email = table.Column(type: "text", nullable: false), - password = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_users", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "book_copies", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - book_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_book_copies", x => x.id); - table.ForeignKey( - name: "FK_book_copies_books_book_id", - column: x => x.book_id, - principalTable: "books", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "user_basic_info", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - userId = table.Column(type: "integer", nullable: false), - first_name = table.Column(type: "text", nullable: false), - last_name = table.Column(type: "text", nullable: false), - phone_number = table.Column(type: "text", nullable: false), - address = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_user_basic_info", x => x.id); - table.ForeignKey( - name: "FK_user_basic_info_users_userId", - column: x => x.userId, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_book_copies_book_id", - table: "book_copies", - column: "book_id"); - - migrationBuilder.CreateIndex( - name: "IX_user_basic_info_userId", - table: "user_basic_info", - column: "userId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_users_email", - table: "users", - column: "email", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "book_copies"); - - migrationBuilder.DropTable( - name: "user_basic_info"); - - migrationBuilder.DropTable( - name: "books"); - - migrationBuilder.DropTable( - name: "users"); - } - } -} diff --git a/web-library/Migrations/20231201221253_UserWithInfo.Designer.cs b/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.Designer.cs similarity index 78% rename from web-library/Migrations/20231201221253_UserWithInfo.Designer.cs rename to web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.Designer.cs index f41dd26..125faa7 100644 --- a/web-library/Migrations/20231201221253_UserWithInfo.Designer.cs +++ b/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.Designer.cs @@ -12,8 +12,8 @@ namespace web_library.Migrations { [DbContext(typeof(DataContext))] - [Migration("20231201221253_UserWithInfo")] - partial class UserWithInfo + [Migration("20231202024346_userAndUserBasicInfoEntity")] + partial class userAndUserBasicInfoEntity { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -25,6 +25,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("book_genres", b => + { + b.Property("book_id") + .HasColumnType("integer"); + + b.Property("genre_id") + .HasColumnType("integer"); + + b.HasKey("book_id", "genre_id"); + + b.HasIndex("genre_id"); + + b.ToTable("book_genres"); + }); + modelBuilder.Entity("web_library.Book.Entity.Book", b => { b.Property("Id") @@ -93,6 +108,25 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("book_copies"); }); + modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + modelBuilder.Entity("web_library.User.Entity.User", b => { b.Property("Id") @@ -151,7 +185,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("UserId") .HasColumnType("integer") - .HasColumnName("userId"); + .HasColumnName("user_id"); b.HasKey("Id"); @@ -161,6 +195,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("user_basic_info", (string)null); }); + modelBuilder.Entity("book_genres", b => + { + b.HasOne("web_library.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("book_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("genre_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => { b.HasOne("web_library.Book.Entity.Book", "Book") diff --git a/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs b/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs new file mode 100644 index 0000000..5e8fc5c --- /dev/null +++ b/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs @@ -0,0 +1,74 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class userAndUserBasicInfoEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "users", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + email = table.Column(type: "text", nullable: false), + password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_users", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "user_basic_info", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + user_id = table.Column(type: "integer", nullable: false), + first_name = table.Column(type: "text", nullable: false), + last_name = table.Column(type: "text", nullable: false), + phone_number = table.Column(type: "text", nullable: false), + address = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_basic_info", x => x.id); + table.ForeignKey( + name: "FK_user_basic_info_users_user_id", + column: x => x.user_id, + principalTable: "users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_user_basic_info_user_id", + table: "user_basic_info", + column: "user_id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_users_email", + table: "users", + column: "email", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "user_basic_info"); + + migrationBuilder.DropTable( + name: "users"); + } + } +} diff --git a/web-library/Program.cs b/web-library/Program.cs index bcda9f1..8045ec8 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -45,6 +45,9 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // Add services to the container. @@ -61,9 +64,6 @@ options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; }); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/web-library/User/Entity/UserBasicInfo.cs b/web-library/User/Entity/UserBasicInfo.cs index 0fe403f..83c32a6 100644 --- a/web-library/User/Entity/UserBasicInfo.cs +++ b/web-library/User/Entity/UserBasicInfo.cs @@ -9,7 +9,7 @@ public class UserBasicInfo [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } - [Column(name: "userId")] public int UserId { get; set; } + [Column(name: "user_id")] public int UserId { get; set; } [Column(name: "first_name")] public string FirstName { get; set; } diff --git a/web-library/appsettings.Development.json b/web-library/appsettings.Development.json index 0c208ae..43aa661 100644 --- a/web-library/appsettings.Development.json +++ b/web-library/appsettings.Development.json @@ -1,4 +1,7 @@ { + "ConnectionStrings": { + "WebApiDatabase": "Host=localhost; Database=TinyLib; Username=postgres; Password=kuba" + }, "Logging": { "LogLevel": { "Default": "Information", From 5b5e7c4c9470b7aa27a4f56e3c0f505b254f5bad Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 06:17:40 +0100 Subject: [PATCH 02/17] add endpoint for gatunkes --- web-library/Book/Controller/BookController.cs | 19 +++++++--- web-library/Book/Repository/BookRepository.cs | 6 ++- .../Book/Request/AssigneGenreToBookRequest.cs | 12 ++++++ web-library/Book/Service/BookService.cs | 17 ++++++++- web-library/Book/Service/IBookService.cs | 1 + .../Genre/Contoller/GenreController.cs | 31 ++++++++++++++++ .../Genre/Repository/GenreRepository.cs | 37 +++++++++++++++++++ .../Genre/Repository/IGenreRepository.cs | 16 ++++++++ .../Genre/Request/CreateGenreRequest.cs | 7 ++++ web-library/Genre/Service/GenreService.cs | 26 +++++++++++++ web-library/Genre/Service/IGenreService.cs | 9 +++++ web-library/Program.cs | 4 ++ web-library/Shared/NotFoundException.cs | 9 +++++ 13 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 web-library/Book/Request/AssigneGenreToBookRequest.cs create mode 100644 web-library/Genre/Contoller/GenreController.cs create mode 100644 web-library/Genre/Repository/GenreRepository.cs create mode 100644 web-library/Genre/Repository/IGenreRepository.cs create mode 100644 web-library/Genre/Request/CreateGenreRequest.cs create mode 100644 web-library/Genre/Service/GenreService.cs create mode 100644 web-library/Genre/Service/IGenreService.cs create mode 100644 web-library/Shared/NotFoundException.cs diff --git a/web-library/Book/Controller/BookController.cs b/web-library/Book/Controller/BookController.cs index 4d7bacf..aec3eaf 100644 --- a/web-library/Book/Controller/BookController.cs +++ b/web-library/Book/Controller/BookController.cs @@ -28,9 +28,10 @@ public ActionResult> Get() // GET api//5 [HttpGet("{id}")] - public string Get(int id) + public ActionResult Get(int id) { - return "value"; + + return Ok(); } // POST api/ @@ -41,8 +42,7 @@ public ActionResult Post([FromBody] CreateBookRequest request) { _bookService.createBook(request); } - catch - (Exception) + catch (Exception) { return NotFound(); } @@ -51,8 +51,17 @@ public ActionResult Post([FromBody] CreateBookRequest request) // PUT api//5 [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) + public ActionResult Put(int id, [FromBody] AssigneGenreToBookRequest request) { + try + { + request.book_id = id; + _bookService.assigneGenre(request); + } catch (Exception) + { + return NotFound(); + } + return Ok(); } // DELETE api//5 diff --git a/web-library/Book/Repository/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs index d2bec19..f4f0510 100644 --- a/web-library/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -1,4 +1,5 @@ -namespace web_library.Book.DataProvider +using web_library.Shared; +namespace web_library.Book.DataProvider { using Entity; public class BookRepository : IBookRepository @@ -22,7 +23,8 @@ public IEnumerable GetAll() public Book GetByIdOrThrow(int id) { - throw new NotImplementedException(); + Book? book = _context.Books.Find(id) ?? throw new NotFoundException("Book not found"); + return book; } public void Remove(Book entity) diff --git a/web-library/Book/Request/AssigneGenreToBookRequest.cs b/web-library/Book/Request/AssigneGenreToBookRequest.cs new file mode 100644 index 0000000..36ad43f --- /dev/null +++ b/web-library/Book/Request/AssigneGenreToBookRequest.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace web_library.Book.Request +{ + public class AssigneGenreToBookRequest + { + + public ICollection genres_ids { get; set; } + [JsonIgnore] + public int book_id { get; set; } + } +} diff --git a/web-library/Book/Service/BookService.cs b/web-library/Book/Service/BookService.cs index c9bce22..af80171 100644 --- a/web-library/Book/Service/BookService.cs +++ b/web-library/Book/Service/BookService.cs @@ -3,17 +3,22 @@ namespace web_library.Book.Service { using Entity; + using Genre.Entity; using Newtonsoft.Json; using web_library.Book.Repository; + using web_library.Genre.Repository; public class BookService : IBookService { private readonly IBookRepository _bookRepository; private readonly IBookCopyRepository _bookCopyRepository; - public BookService(IBookRepository bookRepository, IBookCopyRepository bookCopyRepository) + private readonly IGenreRepository _genreRepository; + + public BookService(IBookRepository bookRepository, IBookCopyRepository bookCopyRepository, IGenreRepository genreRepository) { _bookRepository = bookRepository; _bookCopyRepository = bookCopyRepository; + _genreRepository = genreRepository; } public void createBook(CreateBookRequest request) @@ -34,5 +39,15 @@ public void createBook(CreateBookRequest request) return; } + public void assigneGenre(AssigneGenreToBookRequest request) + { + Book? book = _bookRepository.GetByIdOrThrow(request.book_id); + foreach (var id in request.genres_ids) + { + Genre? genre = _genreRepository.GetByIdOrThrow(id); + book.AddGenre(genre); + } + _bookRepository.Update(book); + } } } diff --git a/web-library/Book/Service/IBookService.cs b/web-library/Book/Service/IBookService.cs index 9ba92e7..41ddd37 100644 --- a/web-library/Book/Service/IBookService.cs +++ b/web-library/Book/Service/IBookService.cs @@ -5,5 +5,6 @@ namespace web_library.Book.Service public interface IBookService { void createBook(CreateBookRequest request); + void assigneGenre(AssigneGenreToBookRequest request); } } \ No newline at end of file diff --git a/web-library/Genre/Contoller/GenreController.cs b/web-library/Genre/Contoller/GenreController.cs new file mode 100644 index 0000000..b1165e3 --- /dev/null +++ b/web-library/Genre/Contoller/GenreController.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc; +namespace web_library.Genre.Contoller +{ + using Service; + using web_library.Genre.Request; + + [Route("api/[controller]")] + [ApiController] + public class GenreController : ControllerBase + { + private readonly IGenreService _genreService; + + public GenreController(IGenreService genreService) + { + _genreService = genreService; + } + + [HttpPost] + public ActionResult Post([FromBody] CreateGenreRequest request) + { + try + { + _genreService.createGenre(request); + + } catch (Exception) { + return NotFound(); + } + return Ok(); + } + } +} diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs new file mode 100644 index 0000000..814aef9 --- /dev/null +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -0,0 +1,37 @@ +using web_library.Shared; +namespace web_library.Genre.Repository +{ + using Entity; + using System.Collections.Generic; + + public class GenreRepository : IGenreRepository + { + private readonly DataContext _context; + public GenreRepository(DataContext context) + { + _context = context; + } + + public void Add(Genre entity) + { + _context.Genres.Add(entity); + _context.SaveChanges(); + } + + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + + public Genre GetByIdOrThrow(int id) + { + Genre? genre = _context.Genres.Find(id) ?? throw new NotFoundException("Genre not found"); + return genre; + } + + public void Remove(Genre entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/web-library/Genre/Repository/IGenreRepository.cs b/web-library/Genre/Repository/IGenreRepository.cs new file mode 100644 index 0000000..5d319d2 --- /dev/null +++ b/web-library/Genre/Repository/IGenreRepository.cs @@ -0,0 +1,16 @@ + + + + + +namespace web_library.Genre.Repository +{ + using Entity; + public interface IGenreRepository : IGenericRepository + { + void Add(Entity.Genre entity); + IEnumerable GetAll(); + Entity.Genre GetByIdOrThrow(int id); + void Remove(Entity.Genre entity); + } +} \ No newline at end of file diff --git a/web-library/Genre/Request/CreateGenreRequest.cs b/web-library/Genre/Request/CreateGenreRequest.cs new file mode 100644 index 0000000..93a9d16 --- /dev/null +++ b/web-library/Genre/Request/CreateGenreRequest.cs @@ -0,0 +1,7 @@ +namespace web_library.Genre.Request +{ + public class CreateGenreRequest + { + public string Name { get; set; } + } +} diff --git a/web-library/Genre/Service/GenreService.cs b/web-library/Genre/Service/GenreService.cs new file mode 100644 index 0000000..7263d85 --- /dev/null +++ b/web-library/Genre/Service/GenreService.cs @@ -0,0 +1,26 @@ +using web_library.Genre.Repository; +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + using Entity; + using Newtonsoft.Json; + + public class GenreService : IGenreService + { + private readonly IGenreRepository _genreRepository; + public GenreService(IGenreRepository genreRepository) + { + _genreRepository = genreRepository; + } + + public void createGenre(CreateGenreRequest request) + { + var jsonString = JsonConvert.SerializeObject(request); + + Genre? genre = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); + + _genreRepository.Add(genre); + } + } +} diff --git a/web-library/Genre/Service/IGenreService.cs b/web-library/Genre/Service/IGenreService.cs new file mode 100644 index 0000000..8960d6d --- /dev/null +++ b/web-library/Genre/Service/IGenreService.cs @@ -0,0 +1,9 @@ +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + public interface IGenreService + { + void createGenre(CreateGenreRequest request); + } +} \ No newline at end of file diff --git a/web-library/Program.cs b/web-library/Program.cs index 898017c..29faffe 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -7,6 +7,8 @@ using web_library.Book.DataProvider; using web_library.Book.Repository; using web_library.Book.Service; +using web_library.Genre.Repository; +using web_library.Genre.Service; using web_library.User.Repository; using web_library.User.Service; @@ -44,6 +46,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); diff --git a/web-library/Shared/NotFoundException.cs b/web-library/Shared/NotFoundException.cs new file mode 100644 index 0000000..8b321dc --- /dev/null +++ b/web-library/Shared/NotFoundException.cs @@ -0,0 +1,9 @@ +namespace web_library.Shared; + +public class NotFoundException : Exception +{ + public NotFoundException(string message) + : base(message) + { + } +} \ No newline at end of file From 6a2fc2f036d58e03cdd2a6ba997aceeb86301d3d Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 06:27:51 +0100 Subject: [PATCH 03/17] v1 fix --- .../20231201221253_UserWithInfo.Designer.cs | 198 ------------------ ...231202024346_userAndUserBasicInfoEntity.cs | 74 ------- 2 files changed, 272 deletions(-) delete mode 100644 web-library/Migrations/20231201221253_UserWithInfo.Designer.cs delete mode 100644 web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs diff --git a/web-library/Migrations/20231201221253_UserWithInfo.Designer.cs b/web-library/Migrations/20231201221253_UserWithInfo.Designer.cs deleted file mode 100644 index f41dd26..0000000 --- a/web-library/Migrations/20231201221253_UserWithInfo.Designer.cs +++ /dev/null @@ -1,198 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231201221253_UserWithInfo")] - partial class UserWithInfo - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("userId"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs b/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs deleted file mode 100644 index 5e8fc5c..0000000 --- a/web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class userAndUserBasicInfoEntity : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "users", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - email = table.Column(type: "text", nullable: false), - password = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_users", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "user_basic_info", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - user_id = table.Column(type: "integer", nullable: false), - first_name = table.Column(type: "text", nullable: false), - last_name = table.Column(type: "text", nullable: false), - phone_number = table.Column(type: "text", nullable: false), - address = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_user_basic_info", x => x.id); - table.ForeignKey( - name: "FK_user_basic_info_users_user_id", - column: x => x.user_id, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_user_basic_info_user_id", - table: "user_basic_info", - column: "user_id", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_users_email", - table: "users", - column: "email", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "user_basic_info"); - - migrationBuilder.DropTable( - name: "users"); - } - } -} From 82e8e00d80215dc80410cccfd705b3a7d12842ee Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 06:46:29 +0100 Subject: [PATCH 04/17] git ign --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1057dde..b697fe7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ ################################################################################ /.vs /.idea -/web-library/appsettings.json /web-library/bin /web-library/obj /web-library/web-library.csproj.user From 8bf4887c5ad9481c74203ba1c63a0d2e130c55a8 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 07:19:22 +0100 Subject: [PATCH 05/17] reservation entity with moving to api directory --- .../Book/Controller/BookController.cs | 6 +- web-library/{ => Api}/Book/Entity/Book.cs | 6 +- web-library/{ => Api}/Book/Entity/BookCopy.cs | 4 +- .../Book/Repository/BookCopyRepository.cs | 4 +- .../Book/Repository/BookRepository.cs | 4 +- .../Book/Repository/IBookCopyRepository.cs | 4 +- .../Book/Repository/IBookRepository.cs | 4 +- .../Book/Request/CreateBookRequest.cs | 2 +- .../{ => Api}/Book/Service/BookService.cs | 8 +- .../{ => Api}/Book/Service/IBookService.cs | 4 +- .../Api/BookReservation/Entity/Reservation.cs | 31 ++ web-library/{ => Api}/Genre/Entity/Genre.cs | 4 +- .../User/Controller/AuthController.cs | 7 +- web-library/{ => Api}/User/Entity/User.cs | 2 +- .../{ => Api}/User/Entity/UserBasicInfo.cs | 2 +- .../Repository/IUserBasicInfoRepository.cs | 3 +- .../User/Repository/IUserRepository.cs | 3 +- .../Repository/UserBasicInfoRepository.cs | 3 +- .../User/Repository/UserRepository.cs | 3 +- .../User/Request/LoginUserRequest.cs | 2 +- .../User/Request/RegisterUserRequest.cs | 2 +- .../{ => Api}/User/Service/AuthService.cs | 7 +- .../{ => Api}/User/Service/IAuthService.cs | 4 +- web-library/Api/User/Service/IUserService.cs | 5 + .../{ => Api}/User/Service/UserService.cs | 4 +- web-library/DataContext.cs | 94 +++--- ...231202061543_reservationEntity.Designer.cs | 284 ++++++++++++++++++ .../20231202061543_reservationEntity.cs | 47 +++ .../Migrations/DataContextModelSnapshot.cs | 73 +++-- web-library/Program.cs | 9 +- web-library/User/Service/IUserService.cs | 5 - 31 files changed, 526 insertions(+), 114 deletions(-) rename web-library/{ => Api}/Book/Controller/BookController.cs (92%) rename web-library/{ => Api}/Book/Entity/Book.cs (92%) rename web-library/{ => Api}/Book/Entity/BookCopy.cs (71%) rename web-library/{ => Api}/Book/Repository/BookCopyRepository.cs (89%) rename web-library/{ => Api}/Book/Repository/BookRepository.cs (90%) rename web-library/{ => Api}/Book/Repository/IBookCopyRepository.cs (52%) rename web-library/{ => Api}/Book/Repository/IBookRepository.cs (61%) rename web-library/{ => Api}/Book/Request/CreateBookRequest.cs (90%) rename web-library/{ => Api}/Book/Service/BookService.cs (85%) rename web-library/{ => Api}/Book/Service/IBookService.cs (56%) create mode 100644 web-library/Api/BookReservation/Entity/Reservation.cs rename web-library/{ => Api}/Genre/Entity/Genre.cs (85%) rename web-library/{ => Api}/User/Controller/AuthController.cs (89%) rename web-library/{ => Api}/User/Entity/User.cs (92%) rename web-library/{ => Api}/User/Entity/UserBasicInfo.cs (96%) rename web-library/{ => Api}/User/Repository/IUserBasicInfoRepository.cs (64%) rename web-library/{ => Api}/User/Repository/IUserRepository.cs (61%) rename web-library/{ => Api}/User/Repository/UserBasicInfoRepository.cs (85%) rename web-library/{ => Api}/User/Repository/UserRepository.cs (92%) rename web-library/{ => Api}/User/Request/LoginUserRequest.cs (76%) rename web-library/{ => Api}/User/Request/RegisterUserRequest.cs (87%) rename web-library/{ => Api}/User/Service/AuthService.cs (95%) rename web-library/{ => Api}/User/Service/IAuthService.cs (73%) create mode 100644 web-library/Api/User/Service/IUserService.cs rename web-library/{ => Api}/User/Service/UserService.cs (72%) create mode 100644 web-library/Migrations/20231202061543_reservationEntity.Designer.cs create mode 100644 web-library/Migrations/20231202061543_reservationEntity.cs delete mode 100644 web-library/User/Service/IUserService.cs diff --git a/web-library/Book/Controller/BookController.cs b/web-library/Api/Book/Controller/BookController.cs similarity index 92% rename from web-library/Book/Controller/BookController.cs rename to web-library/Api/Book/Controller/BookController.cs index 4d7bacf..9055697 100644 --- a/web-library/Book/Controller/BookController.cs +++ b/web-library/Api/Book/Controller/BookController.cs @@ -2,11 +2,11 @@ // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -namespace web_library.Book.Controller +namespace web_library.Api.Book.Controller { using Entity; - using web_library.Book.Request; - using web_library.Book.Service; + using web_library.Api.Book.Request; + using web_library.Api.Book.Service; [Route("api/[controller]")] [ApiController] diff --git a/web-library/Book/Entity/Book.cs b/web-library/Api/Book/Entity/Book.cs similarity index 92% rename from web-library/Book/Entity/Book.cs rename to web-library/Api/Book/Entity/Book.cs index 1207615..1d83af6 100644 --- a/web-library/Book/Entity/Book.cs +++ b/web-library/Api/Book/Entity/Book.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Book.Entity; +namespace web_library.Api.Book.Entity; -using web_library.Genre.Entity; +using web_library.Api.Genre.Entity; [Table("books")] public class Book @@ -46,7 +46,7 @@ public Book(string iSBN, string title, string author, string publisher, DateOnly public void AddGenre(Genre genre) { - this.Genres.Add(genre); + Genres.Add(genre); } diff --git a/web-library/Book/Entity/BookCopy.cs b/web-library/Api/Book/Entity/BookCopy.cs similarity index 71% rename from web-library/Book/Entity/BookCopy.cs rename to web-library/Api/Book/Entity/BookCopy.cs index 5fba106..a7a6dc5 100644 --- a/web-library/Book/Entity/BookCopy.cs +++ b/web-library/Api/Book/Entity/BookCopy.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; +using web_library.Api.BookReservation.Entity; -namespace web_library.Book.Entity; +namespace web_library.Api.Book.Entity; [Table("book_copies")] public class BookCopy @@ -10,6 +11,7 @@ public class BookCopy [Column("book_id")] public int BookId { get; set; } public Book Book { get; set; } + public Reservation? reservation { get; set; } public BookCopy() { } public BookCopy(Book book) { diff --git a/web-library/Book/Repository/BookCopyRepository.cs b/web-library/Api/Book/Repository/BookCopyRepository.cs similarity index 89% rename from web-library/Book/Repository/BookCopyRepository.cs rename to web-library/Api/Book/Repository/BookCopyRepository.cs index 277c5f7..4c69d7f 100644 --- a/web-library/Book/Repository/BookCopyRepository.cs +++ b/web-library/Api/Book/Repository/BookCopyRepository.cs @@ -1,6 +1,6 @@ -using web_library.Book.Entity; +using web_library.Api.Book.Entity; -namespace web_library.Book.Repository +namespace web_library.Api.Book.Repository { public class BookCopyRepository : IBookCopyRepository { diff --git a/web-library/Book/Repository/BookRepository.cs b/web-library/Api/Book/Repository/BookRepository.cs similarity index 90% rename from web-library/Book/Repository/BookRepository.cs rename to web-library/Api/Book/Repository/BookRepository.cs index d2bec19..58745cf 100644 --- a/web-library/Book/Repository/BookRepository.cs +++ b/web-library/Api/Book/Repository/BookRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Book.DataProvider +namespace web_library.Api.Book.Repository { using Entity; + using web_library.Api.Book.Entity; + public class BookRepository : IBookRepository { private readonly DataContext _context; diff --git a/web-library/Book/Repository/IBookCopyRepository.cs b/web-library/Api/Book/Repository/IBookCopyRepository.cs similarity index 52% rename from web-library/Book/Repository/IBookCopyRepository.cs rename to web-library/Api/Book/Repository/IBookCopyRepository.cs index 03e6934..b74b183 100644 --- a/web-library/Book/Repository/IBookCopyRepository.cs +++ b/web-library/Api/Book/Repository/IBookCopyRepository.cs @@ -1,6 +1,6 @@ -using web_library.Book.Entity; +using web_library.Api.Book.Entity; -namespace web_library.Book.Repository +namespace web_library.Api.Book.Repository { public interface IBookCopyRepository : IGenericRepository { diff --git a/web-library/Book/Repository/IBookRepository.cs b/web-library/Api/Book/Repository/IBookRepository.cs similarity index 61% rename from web-library/Book/Repository/IBookRepository.cs rename to web-library/Api/Book/Repository/IBookRepository.cs index c0c8412..6d4c497 100644 --- a/web-library/Book/Repository/IBookRepository.cs +++ b/web-library/Api/Book/Repository/IBookRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Book.DataProvider +namespace web_library.Api.Book.Repository { using Entity; + using web_library.Api.Book.Entity; + public interface IBookRepository : IGenericRepository { public void Update(Book book); diff --git a/web-library/Book/Request/CreateBookRequest.cs b/web-library/Api/Book/Request/CreateBookRequest.cs similarity index 90% rename from web-library/Book/Request/CreateBookRequest.cs rename to web-library/Api/Book/Request/CreateBookRequest.cs index d303b46..b97e554 100644 --- a/web-library/Book/Request/CreateBookRequest.cs +++ b/web-library/Api/Book/Request/CreateBookRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Book.Request +namespace web_library.Api.Book.Request { public class CreateBookRequest { diff --git a/web-library/Book/Service/BookService.cs b/web-library/Api/Book/Service/BookService.cs similarity index 85% rename from web-library/Book/Service/BookService.cs rename to web-library/Api/Book/Service/BookService.cs index c9bce22..f165f92 100644 --- a/web-library/Book/Service/BookService.cs +++ b/web-library/Api/Book/Service/BookService.cs @@ -1,10 +1,10 @@ -using web_library.Book.DataProvider; -using web_library.Book.Request; -namespace web_library.Book.Service +namespace web_library.Api.Book.Service { using Entity; using Newtonsoft.Json; - using web_library.Book.Repository; + using web_library.Api.Book.Entity; + using web_library.Api.Book.Repository; + using web_library.Api.Book.Request; public class BookService : IBookService { diff --git a/web-library/Book/Service/IBookService.cs b/web-library/Api/Book/Service/IBookService.cs similarity index 56% rename from web-library/Book/Service/IBookService.cs rename to web-library/Api/Book/Service/IBookService.cs index 9ba92e7..c7b3466 100644 --- a/web-library/Book/Service/IBookService.cs +++ b/web-library/Api/Book/Service/IBookService.cs @@ -1,6 +1,6 @@ -using web_library.Book.Request; +using web_library.Api.Book.Request; -namespace web_library.Book.Service +namespace web_library.Api.Book.Service { public interface IBookService { diff --git a/web-library/Api/BookReservation/Entity/Reservation.cs b/web-library/Api/BookReservation/Entity/Reservation.cs new file mode 100644 index 0000000..7710d16 --- /dev/null +++ b/web-library/Api/BookReservation/Entity/Reservation.cs @@ -0,0 +1,31 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace web_library.Api.BookReservation.Entity +{ + using System.ComponentModel.DataAnnotations; + using web_library.Api.Book.Entity; + [Table("reservations")] + public class Reservation + { + [Column("id")] + [Key] + public int Id { get; set; } + [Column("reservation_start_date")] + public DateOnly reservationStartDate { get; } + [Column("reservation_end_date")] + public DateOnly reservationEndDate { get; } + [Column("book_copy_id")] + public int bookCopyId { get; set; } + public BookCopy bookCopy { get; set; } = null!; + + public Reservation() + { + reservationStartDate = new(); + reservationEndDate = reservationStartDate.AddMonths(+1); + } + public Reservation(BookCopy book) + { + bookCopy = book; + } + } +} diff --git a/web-library/Genre/Entity/Genre.cs b/web-library/Api/Genre/Entity/Genre.cs similarity index 85% rename from web-library/Genre/Entity/Genre.cs rename to web-library/Api/Genre/Entity/Genre.cs index e8c8ece..5c83e4f 100644 --- a/web-library/Genre/Entity/Genre.cs +++ b/web-library/Api/Genre/Entity/Genre.cs @@ -1,8 +1,8 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Genre.Entity +namespace web_library.Api.Genre.Entity { - using web_library.Book.Entity; + using web_library.Api.Book.Entity; [Table("genres")] public class Genre { diff --git a/web-library/User/Controller/AuthController.cs b/web-library/Api/User/Controller/AuthController.cs similarity index 89% rename from web-library/User/Controller/AuthController.cs rename to web-library/Api/User/Controller/AuthController.cs index 6785a1a..f2f4a8a 100644 --- a/web-library/User/Controller/AuthController.cs +++ b/web-library/Api/User/Controller/AuthController.cs @@ -1,10 +1,9 @@ using Microsoft.AspNetCore.Authorization; -using web_library.User.Request; -using web_library.User.Service; -namespace web_library.User.Controller; +namespace web_library.Api.User.Controller; using Microsoft.AspNetCore.Mvc; - +using web_library.Api.User.Request; +using web_library.Api.User.Service; [ApiController] [Route("api/auth")] diff --git a/web-library/User/Entity/User.cs b/web-library/Api/User/Entity/User.cs similarity index 92% rename from web-library/User/Entity/User.cs rename to web-library/Api/User/Entity/User.cs index 6c51c86..562d724 100644 --- a/web-library/User/Entity/User.cs +++ b/web-library/Api/User/Entity/User.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.User.Entity; +namespace web_library.Api.User.Entity; [Table("users")] public class User diff --git a/web-library/User/Entity/UserBasicInfo.cs b/web-library/Api/User/Entity/UserBasicInfo.cs similarity index 96% rename from web-library/User/Entity/UserBasicInfo.cs rename to web-library/Api/User/Entity/UserBasicInfo.cs index 83c32a6..9907f79 100644 --- a/web-library/User/Entity/UserBasicInfo.cs +++ b/web-library/Api/User/Entity/UserBasicInfo.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.User.Entity; +namespace web_library.Api.User.Entity; [Table("user_basic_info")] public class UserBasicInfo diff --git a/web-library/User/Repository/IUserBasicInfoRepository.cs b/web-library/Api/User/Repository/IUserBasicInfoRepository.cs similarity index 64% rename from web-library/User/Repository/IUserBasicInfoRepository.cs rename to web-library/Api/User/Repository/IUserBasicInfoRepository.cs index 57ed8d6..9572188 100644 --- a/web-library/User/Repository/IUserBasicInfoRepository.cs +++ b/web-library/Api/User/Repository/IUserBasicInfoRepository.cs @@ -1,5 +1,6 @@ -namespace web_library.User.Repository; +namespace web_library.Api.User.Repository; using Entity; +using web_library.Api.User.Entity; public interface IUserBasicInfoRepository { diff --git a/web-library/User/Repository/IUserRepository.cs b/web-library/Api/User/Repository/IUserRepository.cs similarity index 61% rename from web-library/User/Repository/IUserRepository.cs rename to web-library/Api/User/Repository/IUserRepository.cs index 2ff4778..708e44f 100644 --- a/web-library/User/Repository/IUserRepository.cs +++ b/web-library/Api/User/Repository/IUserRepository.cs @@ -1,5 +1,6 @@ -namespace web_library.User.Repository; +namespace web_library.Api.User.Repository; using Entity; +using web_library.Api.User.Entity; public interface IUserRepository : IGenericRepository { diff --git a/web-library/User/Repository/UserBasicInfoRepository.cs b/web-library/Api/User/Repository/UserBasicInfoRepository.cs similarity index 85% rename from web-library/User/Repository/UserBasicInfoRepository.cs rename to web-library/Api/User/Repository/UserBasicInfoRepository.cs index 5991d01..2f34828 100644 --- a/web-library/User/Repository/UserBasicInfoRepository.cs +++ b/web-library/Api/User/Repository/UserBasicInfoRepository.cs @@ -1,5 +1,6 @@ -namespace web_library.User.Repository; +namespace web_library.Api.User.Repository; using Entity; +using web_library.Api.User.Entity; public class UserBasicInfoRepository : IUserBasicInfoRepository { diff --git a/web-library/User/Repository/UserRepository.cs b/web-library/Api/User/Repository/UserRepository.cs similarity index 92% rename from web-library/User/Repository/UserRepository.cs rename to web-library/Api/User/Repository/UserRepository.cs index 57454df..7ea0f15 100644 --- a/web-library/User/Repository/UserRepository.cs +++ b/web-library/Api/User/Repository/UserRepository.cs @@ -1,7 +1,8 @@ using web_library.Shared; -namespace web_library.User.Repository; +namespace web_library.Api.User.Repository; using Entity; +using web_library.Api.User.Entity; public class UserRepository : IUserRepository { diff --git a/web-library/User/Request/LoginUserRequest.cs b/web-library/Api/User/Request/LoginUserRequest.cs similarity index 76% rename from web-library/User/Request/LoginUserRequest.cs rename to web-library/Api/User/Request/LoginUserRequest.cs index 54ed1e4..8853c67 100644 --- a/web-library/User/Request/LoginUserRequest.cs +++ b/web-library/Api/User/Request/LoginUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.User.Request +namespace web_library.Api.User.Request { public class LoginUserRequest { diff --git a/web-library/User/Request/RegisterUserRequest.cs b/web-library/Api/User/Request/RegisterUserRequest.cs similarity index 87% rename from web-library/User/Request/RegisterUserRequest.cs rename to web-library/Api/User/Request/RegisterUserRequest.cs index ff7d4cf..7618213 100644 --- a/web-library/User/Request/RegisterUserRequest.cs +++ b/web-library/Api/User/Request/RegisterUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.User.Request; +namespace web_library.Api.User.Request; public class RegisterUserRequest { diff --git a/web-library/User/Service/AuthService.cs b/web-library/Api/User/Service/AuthService.cs similarity index 95% rename from web-library/User/Service/AuthService.cs rename to web-library/Api/User/Service/AuthService.cs index 4651b78..46bbbcb 100644 --- a/web-library/User/Service/AuthService.cs +++ b/web-library/Api/User/Service/AuthService.cs @@ -4,11 +4,12 @@ using System.Security.Claims; using System.Security.Cryptography; using System.Text; -using web_library.User.Repository; -using web_library.User.Request; -namespace web_library.User.Service; +namespace web_library.Api.User.Service; using Entity; +using web_library.Api.User.Entity; +using web_library.Api.User.Repository; +using web_library.Api.User.Request; public class AuthService : IAuthService { diff --git a/web-library/User/Service/IAuthService.cs b/web-library/Api/User/Service/IAuthService.cs similarity index 73% rename from web-library/User/Service/IAuthService.cs rename to web-library/Api/User/Service/IAuthService.cs index fbe4e80..d52185f 100644 --- a/web-library/User/Service/IAuthService.cs +++ b/web-library/Api/User/Service/IAuthService.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; -using web_library.User.Request; +using web_library.Api.User.Request; -namespace web_library.User.Service +namespace web_library.Api.User.Service { public interface IAuthService { diff --git a/web-library/Api/User/Service/IUserService.cs b/web-library/Api/User/Service/IUserService.cs new file mode 100644 index 0000000..c98354a --- /dev/null +++ b/web-library/Api/User/Service/IUserService.cs @@ -0,0 +1,5 @@ +namespace web_library.Api.User.Service; + +public interface IUserService +{ +} \ No newline at end of file diff --git a/web-library/User/Service/UserService.cs b/web-library/Api/User/Service/UserService.cs similarity index 72% rename from web-library/User/Service/UserService.cs rename to web-library/Api/User/Service/UserService.cs index ba1b9de..0d977ab 100644 --- a/web-library/User/Service/UserService.cs +++ b/web-library/Api/User/Service/UserService.cs @@ -1,6 +1,6 @@ -using web_library.User.Repository; +using web_library.Api.User.Repository; -namespace web_library.User.Service; +namespace web_library.Api.User.Service; public class UserService : IUserService { diff --git a/web-library/DataContext.cs b/web-library/DataContext.cs index 83bf13d..843c2ff 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -1,65 +1,69 @@ using Microsoft.EntityFrameworkCore; -using web_library.User.Entity; -namespace web_library; - -public class DataContext : DbContext +namespace web_library { - protected readonly IConfiguration Configuration; - - public DataContext(IConfiguration configuration) - { - Configuration = configuration; - } + using Api.Book.Entity; + using Api.Genre.Entity; + using Api.User.Entity; + using Api.BookReservation.Entity; - protected override void OnConfiguring(DbContextOptionsBuilder options) + public class DataContext : DbContext { - // connect to postgres with connection string from app settings - options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); - } + protected readonly IConfiguration Configuration; - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .HasMany(left => left.Genres) - .WithMany(right => right.Books) - .UsingEntity>( - "book_genres", - j => j.HasOne().WithMany().HasForeignKey("genre_id"), - j => j.HasOne().WithMany().HasForeignKey("book_id") - ); - - modelBuilder.Entity(entity => + public DataContext(IConfiguration configuration) { - entity.ToTable("users"); - entity.HasIndex(u => u.Email).IsUnique(); + Configuration = configuration; + } - entity.HasOne(u => u.UserBasicInfo) - .WithOne(ubi => ubi.User) - .HasForeignKey(ubi => ubi.UserId) - .OnDelete(DeleteBehavior.Cascade); - }); + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to postgres with connection string from app settings + options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); + } - modelBuilder.Entity(entity => + protected override void OnModelCreating(ModelBuilder modelBuilder) { - entity.ToTable("user_basic_info"); + modelBuilder.Entity() + .HasMany(left => left.Genres) + .WithMany(right => right.Books) + .UsingEntity>( + "book_genres", + j => j.HasOne().WithMany().HasForeignKey("genre_id"), + j => j.HasOne().WithMany().HasForeignKey("book_id") + ); - entity.Property(ubi => ubi.UserId).IsRequired(); + modelBuilder.Entity(entity => + { + entity.ToTable("users"); + entity.HasIndex(u => u.Email).IsUnique(); - entity.HasIndex(ubi => ubi.UserId).IsUnique(); + entity.HasOne(u => u.UserBasicInfo) + .WithOne(ubi => ubi.User) + .HasForeignKey(ubi => ubi.UserId) + .OnDelete(DeleteBehavior.Cascade); + }); - }); + modelBuilder.Entity(entity => + { + entity.ToTable("user_basic_info"); - base.OnModelCreating(modelBuilder); - } + entity.Property(ubi => ubi.UserId).IsRequired(); - public DbSet Users { get; set; } + entity.HasIndex(ubi => ubi.UserId).IsUnique(); + }); - public DbSet Books { get; set; } - public DbSet BooksCopy { get; set; } - public DbSet Genres { get; set; } + base.OnModelCreating(modelBuilder); + } + public DbSet Users { get; set; } - public DbSet UserBasicInfos { get; set; } + + public DbSet Books { get; set; } + public DbSet BooksCopy { get; set; } + public DbSet Genres { get; set; } + public DbSet Reservations { get; set; } + public DbSet UserBasicInfos { get; set; } + } } \ No newline at end of file diff --git a/web-library/Migrations/20231202061543_reservationEntity.Designer.cs b/web-library/Migrations/20231202061543_reservationEntity.Designer.cs new file mode 100644 index 0000000..d366f33 --- /dev/null +++ b/web-library/Migrations/20231202061543_reservationEntity.Designer.cs @@ -0,0 +1,284 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231202061543_reservationEntity")] + partial class reservationEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("book_genres", b => + { + b.Property("book_id") + .HasColumnType("integer"); + + b.Property("genre_id") + .HasColumnType("integer"); + + b.HasKey("book_id", "genre_id"); + + b.HasIndex("genre_id"); + + b.ToTable("book_genres"); + }); + + modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("bookCopyId") + .HasColumnType("integer") + .HasColumnName("book_copy_id"); + + b.HasKey("Id"); + + b.HasIndex("bookCopyId") + .IsUnique(); + + b.ToTable("reservations"); + }); + + modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text") + .HasColumnName("password"); + + b.HasKey("Id"); + + b.HasIndex("Email") + .IsUnique(); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text") + .HasColumnName("address"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text") + .HasColumnName("phone_number"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_basic_info", (string)null); + }); + + modelBuilder.Entity("book_genres", b => + { + b.HasOne("web_library.Api.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("book_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Api.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("genre_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Api.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + { + b.HasOne("web_library.Api.Book.Entity.BookCopy", "bookCopy") + .WithOne("reservation") + .HasForeignKey("web_library.Api.BookReservation.Entity.Reservation", "bookCopyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("bookCopy"); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => + { + b.HasOne("web_library.Api.User.Entity.User", "User") + .WithOne("UserBasicInfo") + .HasForeignKey("web_library.Api.User.Entity.UserBasicInfo", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); + + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => + { + b.Navigation("reservation"); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.User", b => + { + b.Navigation("UserBasicInfo"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231202061543_reservationEntity.cs b/web-library/Migrations/20231202061543_reservationEntity.cs new file mode 100644 index 0000000..2cc4bba --- /dev/null +++ b/web-library/Migrations/20231202061543_reservationEntity.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class reservationEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "reservations", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + book_copy_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_reservations", x => x.id); + table.ForeignKey( + name: "FK_reservations_book_copies_book_copy_id", + column: x => x.book_copy_id, + principalTable: "book_copies", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_reservations_book_copy_id", + table: "reservations", + column: "book_copy_id", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "reservations"); + } + } +} diff --git a/web-library/Migrations/DataContextModelSnapshot.cs b/web-library/Migrations/DataContextModelSnapshot.cs index f7d5db9..6043b64 100644 --- a/web-library/Migrations/DataContextModelSnapshot.cs +++ b/web-library/Migrations/DataContextModelSnapshot.cs @@ -34,10 +34,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("genre_id"); - b.ToTable("book_genres", (string)null); + b.ToTable("book_genres"); }); - modelBuilder.Entity("web_library.Book.Entity.Book", b => + modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -82,10 +82,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("books", (string)null); + b.ToTable("books"); }); - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -102,10 +102,31 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("BookId"); - b.ToTable("book_copies", (string)null); + b.ToTable("book_copies"); }); - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("bookCopyId") + .HasColumnType("integer") + .HasColumnName("book_copy_id"); + + b.HasKey("Id"); + + b.HasIndex("bookCopyId") + .IsUnique(); + + b.ToTable("reservations"); + }); + + modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -121,10 +142,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("genres", (string)null); + b.ToTable("genres"); }); - modelBuilder.Entity("web_library.User.Entity.User", b => + modelBuilder.Entity("web_library.Api.User.Entity.User", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -151,7 +172,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("users", (string)null); }); - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -194,22 +215,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("book_genres", b => { - b.HasOne("web_library.Book.Entity.Book", null) + b.HasOne("web_library.Api.Book.Entity.Book", null) .WithMany() .HasForeignKey("book_id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("web_library.Genre.Entity.Genre", null) + b.HasOne("web_library.Api.Genre.Entity.Genre", null) .WithMany() .HasForeignKey("genre_id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => { - b.HasOne("web_library.Book.Entity.Book", "Book") + b.HasOne("web_library.Api.Book.Entity.Book", "Book") .WithMany("Copies") .HasForeignKey("BookId") .OnDelete(DeleteBehavior.Cascade) @@ -218,23 +239,39 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Book"); }); - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + { + b.HasOne("web_library.Api.Book.Entity.BookCopy", "bookCopy") + .WithOne("reservation") + .HasForeignKey("web_library.Api.BookReservation.Entity.Reservation", "bookCopyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("bookCopy"); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => { - b.HasOne("web_library.User.Entity.User", "User") + b.HasOne("web_library.Api.User.Entity.User", "User") .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") + .HasForeignKey("web_library.Api.User.Entity.UserBasicInfo", "UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("User"); }); - modelBuilder.Entity("web_library.Book.Entity.Book", b => + modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => { b.Navigation("Copies"); }); - modelBuilder.Entity("web_library.User.Entity.User", b => + modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => + { + b.Navigation("reservation"); + }); + + modelBuilder.Entity("web_library.Api.User.Entity.User", b => { b.Navigation("UserBasicInfo"); }); diff --git a/web-library/Program.cs b/web-library/Program.cs index 898017c..95297ff 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -4,11 +4,10 @@ using Microsoft.OpenApi.Models; using System.Text; using web_library; -using web_library.Book.DataProvider; -using web_library.Book.Repository; -using web_library.Book.Service; -using web_library.User.Repository; -using web_library.User.Service; +using web_library.Api.Book.Repository; +using web_library.Api.Book.Service; +using web_library.Api.User.Repository; +using web_library.Api.User.Service; var builder = WebApplication.CreateBuilder(args); diff --git a/web-library/User/Service/IUserService.cs b/web-library/User/Service/IUserService.cs deleted file mode 100644 index d9facb2..0000000 --- a/web-library/User/Service/IUserService.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace web_library.User.Service; - -public interface IUserService -{ -} \ No newline at end of file From c40f25a4e52d45db0068312adb157f5caed84073 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 07:46:04 +0100 Subject: [PATCH 06/17] remove misspelled directory --- .../Genre/Contoller/GenreController.cs | 31 ------------------- .../Genre/Controller/GenresController.cs | 4 --- web-library/web-library.csproj | 2 +- 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 web-library/Genre/Contoller/GenreController.cs diff --git a/web-library/Genre/Contoller/GenreController.cs b/web-library/Genre/Contoller/GenreController.cs deleted file mode 100644 index b1165e3..0000000 --- a/web-library/Genre/Contoller/GenreController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -namespace web_library.Genre.Contoller -{ - using Service; - using web_library.Genre.Request; - - [Route("api/[controller]")] - [ApiController] - public class GenreController : ControllerBase - { - private readonly IGenreService _genreService; - - public GenreController(IGenreService genreService) - { - _genreService = genreService; - } - - [HttpPost] - public ActionResult Post([FromBody] CreateGenreRequest request) - { - try - { - _genreService.createGenre(request); - - } catch (Exception) { - return NotFound(); - } - return Ok(); - } - } -} diff --git a/web-library/Genre/Controller/GenresController.cs b/web-library/Genre/Controller/GenresController.cs index 112151e..dada424 100644 --- a/web-library/Genre/Controller/GenresController.cs +++ b/web-library/Genre/Controller/GenresController.cs @@ -2,7 +2,6 @@ namespace web_library.Genre.Controller { - using Microsoft.AspNetCore.Authorization; using web_library.Genre.Request; using web_library.Genre.Service; @@ -17,10 +16,7 @@ public GenresController(IGenreService genreService) _genreService = genreService; } - // POST: api/Genres - // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] - [AllowAnonymous] public ActionResult Post([FromBody] CreateGenreRequest request) { try diff --git a/web-library/web-library.csproj b/web-library/web-library.csproj index 6f912b3..8035a6d 100644 --- a/web-library/web-library.csproj +++ b/web-library/web-library.csproj @@ -1,4 +1,4 @@ - + net8.0 From 2cbf409bd530735025c2e4a6e3698882f8dc0aee Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Mon, 4 Dec 2023 02:09:46 +0100 Subject: [PATCH 07/17] new endpoint create reservation adding models and dataproviders --- .../Api/Book/Controller/BookController.cs | 93 +++++++++---------- .../Api/Book/DataProvider/BookDataProvider.cs | 41 ++++++++ .../Book/DataProvider/IBookDataProvider.cs | 9 ++ web-library/Api/Book/Entity/Book.cs | 2 +- web-library/Api/Book/Entity/BookCopy.cs | 2 +- web-library/Api/Book/Model/BookModel.cs | 27 ++++++ .../Api/Book/Repository/BookCopyRepository.cs | 51 +++++----- .../Api/Book/Repository/BookRepository.cs | 63 +++++++------ .../Book/Repository/IBookCopyRepository.cs | 7 +- .../Api/Book/Repository/IBookRepository.cs | 13 +-- .../Api/Book/Request/CreateBookRequest.cs | 23 +++++ web-library/Api/Book/Service/BookService.cs | 54 ++++++----- web-library/Api/Book/Service/IBookService.cs | 9 +- .../Api/BookReservation/Entity/Reservation.cs | 31 ------- web-library/Api/Genre/Entity/Genre.cs | 35 ++++--- .../Controller/ReservationController.cs | 37 ++++++++ .../DataProvider/IReservationDataProvider.cs | 9 ++ .../DataProvider/ReservationDataProvider.cs | 49 ++++++++++ .../Api/Reservation/Entity/Reservation.cs | 33 +++++++ .../Api/Reservation/Model/ReservationModel.cs | 33 +++++++ .../Repostiory/IReservationRepository.cs | 7 ++ .../Repostiory/ReservationRepository.cs | 41 ++++++++ .../Request/CreateReservationRequest.cs | 13 +++ .../Service/IReservationService.cs | 9 ++ .../Reservation/Service/ReservationService.cs | 24 +++++ .../Repository/IUserBasicInfoRepository.cs | 2 - .../Api/User/Repository/UserRepository.cs | 6 +- web-library/Api/User/Service/AuthService.cs | 5 +- web-library/DataContext.cs | 3 +- web-library/IGenericRepository.cs | 4 +- ...31204004614_reservationEntity.Designer.cs} | 42 +++++---- ...cs => 20231204004614_reservationEntity.cs} | 5 +- .../Migrations/DataContextModelSnapshot.cs | 40 ++++---- web-library/Program.cs | 70 +++++++------- web-library/Shared/NotFoundException.cs | 9 ++ 35 files changed, 618 insertions(+), 283 deletions(-) create mode 100644 web-library/Api/Book/DataProvider/BookDataProvider.cs create mode 100644 web-library/Api/Book/DataProvider/IBookDataProvider.cs create mode 100644 web-library/Api/Book/Model/BookModel.cs delete mode 100644 web-library/Api/BookReservation/Entity/Reservation.cs create mode 100644 web-library/Api/Reservation/Controller/ReservationController.cs create mode 100644 web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs create mode 100644 web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs create mode 100644 web-library/Api/Reservation/Entity/Reservation.cs create mode 100644 web-library/Api/Reservation/Model/ReservationModel.cs create mode 100644 web-library/Api/Reservation/Repostiory/IReservationRepository.cs create mode 100644 web-library/Api/Reservation/Repostiory/ReservationRepository.cs create mode 100644 web-library/Api/Reservation/Request/CreateReservationRequest.cs create mode 100644 web-library/Api/Reservation/Service/IReservationService.cs create mode 100644 web-library/Api/Reservation/Service/ReservationService.cs rename web-library/Migrations/{20231202061543_reservationEntity.Designer.cs => 20231204004614_reservationEntity.Designer.cs} (93%) rename web-library/Migrations/{20231202061543_reservationEntity.cs => 20231204004614_reservationEntity.cs} (86%) create mode 100644 web-library/Shared/NotFoundException.cs diff --git a/web-library/Api/Book/Controller/BookController.cs b/web-library/Api/Book/Controller/BookController.cs index 9055697..146c857 100644 --- a/web-library/Api/Book/Controller/BookController.cs +++ b/web-library/Api/Book/Controller/BookController.cs @@ -1,64 +1,63 @@ using Microsoft.AspNetCore.Mvc; -// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +namespace web_library.Api.Book.Controller; -namespace web_library.Api.Book.Controller +using DataProvider; +using Request; +using Service; +using Model; + +[Route("api/[controller]")] +[ApiController] +public class BookController : ControllerBase { - using Entity; - using web_library.Api.Book.Request; - using web_library.Api.Book.Service; + private readonly IBookService _bookService; + private readonly IBookDataProvider _bookDataProvider; - [Route("api/[controller]")] - [ApiController] - public class BookController : ControllerBase + public BookController(IBookService bookService, IBookDataProvider bookDataProvider) { - private readonly IBookService _bookService; + _bookService = bookService; + _bookDataProvider = bookDataProvider; + } - public BookController(IBookService bookService) - { - _bookService = bookService; - } + [HttpGet] + public ActionResult> Index() + { + return Ok(_bookDataProvider.getAll()); + } - // GET: api/ - [HttpGet] - public ActionResult> Get() - { - return Ok(); - } + [HttpGet("{id}")] + public ActionResult Index(int id) + { + + return Ok(_bookDataProvider.getById(id)); + } - // GET api//5 - [HttpGet("{id}")] - public string Get(int id) + // POST api/ + [HttpPost] + public ActionResult Create([FromBody] CreateBookRequest request) + { + try { - return "value"; + _bookService.createBook(request); } - - // POST api/ - [HttpPost] - public ActionResult Post([FromBody] CreateBookRequest request) + catch + (Exception) { - try - { - _bookService.createBook(request); - } - catch - (Exception) - { - return NotFound(); - } - return Ok(); + return NotFound(); } + return Ok(); + } - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { - } + // SEED + [HttpPost("seed")] + public ActionResult Seed(CreateBookRequest request) + { - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } + CreateBookRequest bookRequest = new CreateBookRequest("random"); + _bookService.createBook(bookRequest); + + return Ok(); } } + diff --git a/web-library/Api/Book/DataProvider/BookDataProvider.cs b/web-library/Api/Book/DataProvider/BookDataProvider.cs new file mode 100644 index 0000000..12a443a --- /dev/null +++ b/web-library/Api/Book/DataProvider/BookDataProvider.cs @@ -0,0 +1,41 @@ +using web_library.Api.Book.Model; +using web_library.Api.Book.Repository; + +namespace web_library.Api.Book.DataProvider; +using Entity; + +public class BookDataProvider : IBookDataProvider +{ + private readonly IBookRepository _bookRepository; + public BookDataProvider(IBookRepository bookRepository) + { + _bookRepository = bookRepository; + } + private BookModel getModel(Book entity) + { + return new BookModel( + entity.Id, + entity.ISBN, + entity.Title, + entity.Author, + entity.Publisher, + entity.Publication_date, + entity.Location, + entity.Description, + entity.Copies.Count() + ); + } + public ICollection getAll() + { + List result = new(); + foreach (var item in _bookRepository.FindAll()) + { + result.Add(getModel(item)); + }; + return result; + } + public BookModel getById(int id) + { + return getModel(_bookRepository.FindByIdOrThrow(id)); + } +} diff --git a/web-library/Api/Book/DataProvider/IBookDataProvider.cs b/web-library/Api/Book/DataProvider/IBookDataProvider.cs new file mode 100644 index 0000000..9939e06 --- /dev/null +++ b/web-library/Api/Book/DataProvider/IBookDataProvider.cs @@ -0,0 +1,9 @@ +using web_library.Api.Book.Model; + +namespace web_library.Api.Book.DataProvider; + +public interface IBookDataProvider +{ + ICollection getAll(); + BookModel getById(int id); +} \ No newline at end of file diff --git a/web-library/Api/Book/Entity/Book.cs b/web-library/Api/Book/Entity/Book.cs index 1d83af6..85c729c 100644 --- a/web-library/Api/Book/Entity/Book.cs +++ b/web-library/Api/Book/Entity/Book.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace web_library.Api.Book.Entity; -using web_library.Api.Genre.Entity; +using Genre.Entity; [Table("books")] public class Book diff --git a/web-library/Api/Book/Entity/BookCopy.cs b/web-library/Api/Book/Entity/BookCopy.cs index a7a6dc5..c02acbe 100644 --- a/web-library/Api/Book/Entity/BookCopy.cs +++ b/web-library/Api/Book/Entity/BookCopy.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; -using web_library.Api.BookReservation.Entity; namespace web_library.Api.Book.Entity; +using Reservation.Entity; [Table("book_copies")] public class BookCopy diff --git a/web-library/Api/Book/Model/BookModel.cs b/web-library/Api/Book/Model/BookModel.cs new file mode 100644 index 0000000..6fefc88 --- /dev/null +++ b/web-library/Api/Book/Model/BookModel.cs @@ -0,0 +1,27 @@ +namespace web_library.Api.Book.Model; + +public class BookModel +{ + public int BookId { get; set; } + public string ISBN { get; set; } + public string Title { get; set; } + public string Author { get; set; } + public string Publisher { get; set; } + public DateOnly Publication_date { get; set; } + public string Location { get; set; } + public string Description { get; set; } + public int NumberOfCopies { get; set; } + + public BookModel(int bookId, string iSBN, string title, string author, string publisher, DateOnly publication_date, string location, string description, int numberOfCopies) + { + BookId = bookId; + ISBN = iSBN; + Title = title; + Author = author; + Publisher = publisher; + Publication_date = publication_date; + Location = location; + Description = description; + NumberOfCopies = numberOfCopies; + } +} diff --git a/web-library/Api/Book/Repository/BookCopyRepository.cs b/web-library/Api/Book/Repository/BookCopyRepository.cs index 4c69d7f..9f7437b 100644 --- a/web-library/Api/Book/Repository/BookCopyRepository.cs +++ b/web-library/Api/Book/Repository/BookCopyRepository.cs @@ -1,34 +1,33 @@ -using web_library.Api.Book.Entity; - -namespace web_library.Api.Book.Repository +namespace web_library.Api.Book.Repository; +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +public class BookCopyRepository : IBookCopyRepository { - public class BookCopyRepository : IBookCopyRepository + private readonly DataContext _context; + public BookCopyRepository(DataContext context) { - private readonly DataContext _context; - public BookCopyRepository(DataContext context) - { - _context = context; - } + _context = context; + } - public void Add(BookCopy entity) - { - _context.BooksCopy.Add(entity); - _context.SaveChanges(); - } + public void Add(BookCopy entity) + { + _context.BooksCopy.Add(entity); + _context.SaveChanges(); + } - public IEnumerable GetAll() - { - throw new NotImplementedException(); - } + public IEnumerable FindAll() + { + throw new NotImplementedException(); + } - public BookCopy GetByIdOrThrow(int id) - { - throw new NotImplementedException(); - } + public BookCopy FindByIdOrThrow(int id) + { + return _context.BooksCopy.Find(id) ?? throw new NotFoundException("Book copy (" + id +") not found repository"); + } - public void Remove(BookCopy entity) - { - throw new NotImplementedException(); - } + public void Remove(BookCopy entity) + { + throw new NotImplementedException(); } } diff --git a/web-library/Api/Book/Repository/BookRepository.cs b/web-library/Api/Book/Repository/BookRepository.cs index 58745cf..de1cf3a 100644 --- a/web-library/Api/Book/Repository/BookRepository.cs +++ b/web-library/Api/Book/Repository/BookRepository.cs @@ -1,41 +1,40 @@ -namespace web_library.Api.Book.Repository -{ - using Entity; - using web_library.Api.Book.Entity; +namespace web_library.Api.Book.Repository; - public class BookRepository : IBookRepository +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +public class BookRepository : IBookRepository +{ + private readonly DataContext _context; + public BookRepository(DataContext context) { - private readonly DataContext _context; - public BookRepository(DataContext context) - { - _context = context; - } + _context = context; + } - public void Add(Book entity) - { - _context.Books.Add(entity); - _context.SaveChanges(); - } + public void Add(Book entity) + { + _context.Books.Add(entity); + _context.SaveChanges(); + } - public IEnumerable GetAll() - { - throw new NotImplementedException(); - } + public IEnumerable FindAll() + { + return _context.Books.Include(b=>b.Copies).ToList(); + } - public Book GetByIdOrThrow(int id) - { - throw new NotImplementedException(); - } + public Book FindByIdOrThrow(int id) + { + return _context.Books.Find(id) ?? throw new NotFoundException("Book not found"); + } - public void Remove(Book entity) - { - throw new NotImplementedException(); - } + public void Remove(Book entity) + { + throw new NotImplementedException(); + } - public void Update(Book entity) - { - _context.Books.Update(entity); - _context.SaveChanges(); - } + public void Update(Book entity) + { + _context.Books.Update(entity); + _context.SaveChanges(); } } diff --git a/web-library/Api/Book/Repository/IBookCopyRepository.cs b/web-library/Api/Book/Repository/IBookCopyRepository.cs index b74b183..d03a296 100644 --- a/web-library/Api/Book/Repository/IBookCopyRepository.cs +++ b/web-library/Api/Book/Repository/IBookCopyRepository.cs @@ -1,8 +1,7 @@ using web_library.Api.Book.Entity; -namespace web_library.Api.Book.Repository +namespace web_library.Api.Book.Repository; + +public interface IBookCopyRepository : IGenericRepository { - public interface IBookCopyRepository : IGenericRepository - { - } } \ No newline at end of file diff --git a/web-library/Api/Book/Repository/IBookRepository.cs b/web-library/Api/Book/Repository/IBookRepository.cs index 6d4c497..76534eb 100644 --- a/web-library/Api/Book/Repository/IBookRepository.cs +++ b/web-library/Api/Book/Repository/IBookRepository.cs @@ -1,10 +1,7 @@ -namespace web_library.Api.Book.Repository -{ - using Entity; - using web_library.Api.Book.Entity; +namespace web_library.Api.Book.Repository; - public interface IBookRepository : IGenericRepository - { - public void Update(Book book); - } +using Entity; +public interface IBookRepository : IGenericRepository +{ + public void Update(Book book); } \ No newline at end of file diff --git a/web-library/Api/Book/Request/CreateBookRequest.cs b/web-library/Api/Book/Request/CreateBookRequest.cs index b97e554..853d8d1 100644 --- a/web-library/Api/Book/Request/CreateBookRequest.cs +++ b/web-library/Api/Book/Request/CreateBookRequest.cs @@ -11,5 +11,28 @@ public class CreateBookRequest public string description { get; set; } public int numberOfCopies { get; set; } + public CreateBookRequest() { } + public CreateBookRequest(string type) + { + List isbnList = new() { 9780439023528, 9780747532743, 9780451524935, 9780618260300, 9780141439600 }; + List titleList = new() { "The Hunger Games", "Harry Potter and the Philosopher's Stone", "1984", "The Hobbit", "Pride and Prejudice" }; + List authorList = new() { "Suzanne Collins", "J.K. Rowling", "George Orwell", "J.R.R. Tolkien", "Jane Austen" }; + List publisherList = new() { "Scholastic Press", "Bloomsbury", "Harcourt Brace Jovanovich", "Houghton Mifflin", "Penguin Books" }; + List publication_dateList = new() { "September 14, 2008", "June 26, 1997", "June 8, 1949", "September 21, 1937", "January 28, 1813" }; + List locationList = new() { "United States", "United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom" }; + List descriptionList = new() { "A dystopian novel set in a post-apocalyptic society in the country of Panem.", "The first novel in the Harry Potter series and Rowling's debut novel.", "A dystopian social science fiction novel and a cautionary tale of a totalitarian regime.", "A children's fantasy novel and prelude to the Lord of the Rings series.", "A romantic novel of manners depicting the society of early 19th-century England." }; + List numberOfCopiesList = new() { 5, 10, 15, 20, 25 }; + + Random r = new Random(); + int bookNumber = r.Next(0, 5); + isbn = isbnList[bookNumber].ToString(); + title = titleList[bookNumber]; + author = authorList[bookNumber]; + publisher = publisherList[bookNumber]; + publication_date = DateOnly.Parse(publication_dateList[r.Next(0, 5)]); + location = locationList[bookNumber]; + description = descriptionList[bookNumber]; + numberOfCopies = numberOfCopiesList[bookNumber]; + } } } diff --git a/web-library/Api/Book/Service/BookService.cs b/web-library/Api/Book/Service/BookService.cs index f165f92..3c7a2dd 100644 --- a/web-library/Api/Book/Service/BookService.cs +++ b/web-library/Api/Book/Service/BookService.cs @@ -1,38 +1,36 @@ -namespace web_library.Api.Book.Service -{ - using Entity; - using Newtonsoft.Json; - using web_library.Api.Book.Entity; - using web_library.Api.Book.Repository; - using web_library.Api.Book.Request; +namespace web_library.Api.Book.Service; + +using Entity; +using Newtonsoft.Json; +using Repository; +using Request; - public class BookService : IBookService +public class BookService : IBookService +{ + private readonly IBookRepository _bookRepository; + private readonly IBookCopyRepository _bookCopyRepository; + public BookService(IBookRepository bookRepository, IBookCopyRepository bookCopyRepository) { - private readonly IBookRepository _bookRepository; - private readonly IBookCopyRepository _bookCopyRepository; - public BookService(IBookRepository bookRepository, IBookCopyRepository bookCopyRepository) - { - _bookRepository = bookRepository; - _bookCopyRepository = bookCopyRepository; - } + _bookRepository = bookRepository; + _bookCopyRepository = bookCopyRepository; + } - public void createBook(CreateBookRequest request) - { - var jsonString = JsonConvert.SerializeObject(request); + public void createBook(CreateBookRequest request) + { + var jsonString = JsonConvert.SerializeObject(request); - Book? entity = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); + Book entity = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); - _bookRepository.Add(entity); + _bookRepository.Add(entity); - for (int i = 0; i < request.numberOfCopies; i++) - { - BookCopy copy = new(entity); - _bookCopyRepository.Add(copy); - } + for (int i = 0; i < request.numberOfCopies; i++) + { + BookCopy copy = new(entity); + _bookCopyRepository.Add(copy); + } - _bookRepository.Update(entity); + _bookRepository.Update(entity); - return; - } + return; } } diff --git a/web-library/Api/Book/Service/IBookService.cs b/web-library/Api/Book/Service/IBookService.cs index c7b3466..8627ee9 100644 --- a/web-library/Api/Book/Service/IBookService.cs +++ b/web-library/Api/Book/Service/IBookService.cs @@ -1,9 +1,8 @@ using web_library.Api.Book.Request; -namespace web_library.Api.Book.Service +namespace web_library.Api.Book.Service; + +public interface IBookService { - public interface IBookService - { - void createBook(CreateBookRequest request); - } + void createBook(CreateBookRequest request); } \ No newline at end of file diff --git a/web-library/Api/BookReservation/Entity/Reservation.cs b/web-library/Api/BookReservation/Entity/Reservation.cs deleted file mode 100644 index 7710d16..0000000 --- a/web-library/Api/BookReservation/Entity/Reservation.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace web_library.Api.BookReservation.Entity -{ - using System.ComponentModel.DataAnnotations; - using web_library.Api.Book.Entity; - [Table("reservations")] - public class Reservation - { - [Column("id")] - [Key] - public int Id { get; set; } - [Column("reservation_start_date")] - public DateOnly reservationStartDate { get; } - [Column("reservation_end_date")] - public DateOnly reservationEndDate { get; } - [Column("book_copy_id")] - public int bookCopyId { get; set; } - public BookCopy bookCopy { get; set; } = null!; - - public Reservation() - { - reservationStartDate = new(); - reservationEndDate = reservationStartDate.AddMonths(+1); - } - public Reservation(BookCopy book) - { - bookCopy = book; - } - } -} diff --git a/web-library/Api/Genre/Entity/Genre.cs b/web-library/Api/Genre/Entity/Genre.cs index 5c83e4f..33767bf 100644 --- a/web-library/Api/Genre/Entity/Genre.cs +++ b/web-library/Api/Genre/Entity/Genre.cs @@ -1,25 +1,24 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Genre.Entity +namespace web_library.Api.Genre.Entity; + +using Book.Entity; +[Table("genres")] +public class Genre { - using web_library.Api.Book.Entity; - [Table("genres")] - public class Genre + [Column("id")] + public int Id { get; set; } + [Column("name")] + public string Name { get; set; } + public List Books { get; } + public Genre() { - [Column("id")] - public int Id { get; set; } - [Column("name")] - public string Name { get; set; } - public List Books { get; } - public Genre() - { - Books = new List(); - } - - public Genre(string name) - { - Name = name; - } + Books = new List(); + } + public Genre(string name) + { + Name = name; } + } diff --git a/web-library/Api/Reservation/Controller/ReservationController.cs b/web-library/Api/Reservation/Controller/ReservationController.cs new file mode 100644 index 0000000..12d6d63 --- /dev/null +++ b/web-library/Api/Reservation/Controller/ReservationController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; + +namespace web_library.Api.Reservation.Controller +{ + using DataProvider; + using Request; + using Service; + using Model; + + [Route("api/[controller]")] + [ApiController] + public class ReservationController : ControllerBase + { + private readonly IReservationService _reservationService; + private readonly IReservationDataProvider _reservationDataProvider; + + public ReservationController(IReservationService reservationService, IReservationDataProvider reservationDataProvider) + { + _reservationService = reservationService; + _reservationDataProvider = reservationDataProvider; + } + + // GET: HomeController + [HttpGet] + public ActionResult> Index() + { + return Ok(_reservationDataProvider.GetAll()); + } + // POST: HomeController/Create + [HttpPost] + public ActionResult Create([FromBody] CreateReservationRequest request) + { + _reservationService.createReservation(request); + return Ok(); + } + } +} diff --git a/web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs b/web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs new file mode 100644 index 0000000..f5a08e9 --- /dev/null +++ b/web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs @@ -0,0 +1,9 @@ +using web_library.Api.Reservation.Model; + +namespace web_library.Api.Reservation.DataProvider +{ + public interface IReservationDataProvider + { + IEnumerable GetAll(); + } +} \ No newline at end of file diff --git a/web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs b/web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs new file mode 100644 index 0000000..e4ec9ca --- /dev/null +++ b/web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs @@ -0,0 +1,49 @@ +using web_library.Api.Reservation.Model; +using web_library.Api.Reservation.Repostiory; + +namespace web_library.Api.Reservation.DataProvider; + +using Entity; +using System.Security.Policy; +using web_library.Api.Book.Entity; +using web_library.Api.Book.Repository; + +public class ReservationDataProvider : IReservationDataProvider +{ + private readonly IReservationRepository _reservationRepository; + //private readonly IBookRepository _bookRepository; + + public ReservationDataProvider(IReservationRepository reservationRepository, IBookRepository bookRepository) + { + _reservationRepository = reservationRepository; + //_bookRepository = bookRepository; + } + + private ReservationModel getModel(Reservation entity) + { + return new ReservationModel( + entity.Id, + entity.bookCopy.Book.Id, + entity.bookCopy.Book.ISBN, + entity.bookCopy.Book.Title, + entity.bookCopy.Book.Author, + entity.bookCopy.Book.Publisher, + entity.bookCopy.Book.Publication_date, + entity.bookCopyId, + entity.reservationStartDate, + entity.reservationEndDate + ); + } + public IEnumerable GetAll() + { + List list = new(); + foreach (var item in _reservationRepository.FindAll()) + { + list.Add(getModel(item)); + } + return list; + } + + + +} diff --git a/web-library/Api/Reservation/Entity/Reservation.cs b/web-library/Api/Reservation/Entity/Reservation.cs new file mode 100644 index 0000000..a324137 --- /dev/null +++ b/web-library/Api/Reservation/Entity/Reservation.cs @@ -0,0 +1,33 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace web_library.Api.Reservation.Entity; + +using System.ComponentModel.DataAnnotations; +using Book.Entity; +[Table("reservations")] +public class Reservation +{ + [Column("id")] + [Key] + public int Id { get; set; } + + [Column("reservation_start_date")] + public DateOnly reservationStartDate { get; set; } + + [Column("reservation_end_date")] + public DateOnly reservationEndDate { get; set; } + + [Column("book_copy_id")] + public int bookCopyId { get; set; } + + public BookCopy bookCopy { get; set; } = null!; + + public Reservation() {} + + public Reservation(DateOnly reservationStartDate, DateOnly reservationEndDate, int bookCopyId) + { + this.reservationStartDate = reservationStartDate; + this.reservationEndDate = reservationEndDate; + this.bookCopyId = bookCopyId; + } +} diff --git a/web-library/Api/Reservation/Model/ReservationModel.cs b/web-library/Api/Reservation/Model/ReservationModel.cs new file mode 100644 index 0000000..935c8b5 --- /dev/null +++ b/web-library/Api/Reservation/Model/ReservationModel.cs @@ -0,0 +1,33 @@ +using web_library.Api.Book.Entity; + +namespace web_library.Api.Reservation.Model +{ + public class ReservationModel + { + public int ReservationId { get; set; } + public int BookId { get; set; } + public string ISBN { get; set; } + public string Title { get; set; } + public string Author { get; set; } + public string Publisher { get; set; } + public DateOnly Publication_date { get; set; } + public int BookCopyId { get; set; } + public DateOnly StartDate { get; set; } + public DateOnly EndDate { get; set; } + public ReservationModel() { } + + public ReservationModel(int reservationId, int bookId, string iSBN, string title, string author, string publisher, DateOnly publication_date, int bookCopyId, DateOnly startDate, DateOnly endDate) + { + ReservationId = reservationId; + BookId = bookId; + ISBN = iSBN; + Title = title; + Author = author; + Publisher = publisher; + Publication_date = publication_date; + BookCopyId = bookCopyId; + StartDate = startDate; + EndDate = endDate; + } + } +} diff --git a/web-library/Api/Reservation/Repostiory/IReservationRepository.cs b/web-library/Api/Reservation/Repostiory/IReservationRepository.cs new file mode 100644 index 0000000..006d719 --- /dev/null +++ b/web-library/Api/Reservation/Repostiory/IReservationRepository.cs @@ -0,0 +1,7 @@ +namespace web_library.Api.Reservation.Repostiory +{ + using Entity; + public interface IReservationRepository : IGenericRepository + { + } +} \ No newline at end of file diff --git a/web-library/Api/Reservation/Repostiory/ReservationRepository.cs b/web-library/Api/Reservation/Repostiory/ReservationRepository.cs new file mode 100644 index 0000000..1ef827e --- /dev/null +++ b/web-library/Api/Reservation/Repostiory/ReservationRepository.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; + +namespace web_library.Api.Reservation.Repostiory +{ + using Entity; + using Shared; + + public class ReservationRepository : IReservationRepository + { + private readonly DataContext _context; + + public ReservationRepository(DataContext context) + { + _context = context; + } + + public void Add(Reservation entity) + { + _context.Reservations.Add(entity); + _context.SaveChanges(); + } + + public IEnumerable FindAll() + { + return _context.Reservations + .Include(b => b.bookCopy) + .ThenInclude(b => b.Book) + .ToList(); + } + + public Reservation FindByIdOrThrow(int id) + { + return _context.Reservations.Find(id) ?? throw new NotFoundException("Reservation not found repository"); + } + + public void Remove(Reservation entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/web-library/Api/Reservation/Request/CreateReservationRequest.cs b/web-library/Api/Reservation/Request/CreateReservationRequest.cs new file mode 100644 index 0000000..280f2e7 --- /dev/null +++ b/web-library/Api/Reservation/Request/CreateReservationRequest.cs @@ -0,0 +1,13 @@ + +namespace web_library.Api.Reservation.Request; +public class CreateReservationRequest +{ + public int book_copy_id { get; set; } + public DateOnly reservation_start_date { get; set; } + public DateOnly reservation_end_date { get; set; } + public CreateReservationRequest() + { + reservation_start_date = new(); + reservation_end_date = new(); + } +} diff --git a/web-library/Api/Reservation/Service/IReservationService.cs b/web-library/Api/Reservation/Service/IReservationService.cs new file mode 100644 index 0000000..389d8a8 --- /dev/null +++ b/web-library/Api/Reservation/Service/IReservationService.cs @@ -0,0 +1,9 @@ +using web_library.Api.Reservation.Request; + +namespace web_library.Api.Reservation.Service +{ + public interface IReservationService + { + void createReservation(CreateReservationRequest request); + } +} \ No newline at end of file diff --git a/web-library/Api/Reservation/Service/ReservationService.cs b/web-library/Api/Reservation/Service/ReservationService.cs new file mode 100644 index 0000000..5909726 --- /dev/null +++ b/web-library/Api/Reservation/Service/ReservationService.cs @@ -0,0 +1,24 @@ +namespace web_library.Api.Reservation.Service; +using Book.Entity; +using Book.Repository; +using Entity; +using Repostiory; +using Request; +public class ReservationService : IReservationService +{ + private readonly IReservationRepository _reservationRepository; + private readonly IBookCopyRepository _bookCopyRepository; + + public ReservationService(IReservationRepository reservationRepository, IBookCopyRepository bookCopyRepository) + { + _reservationRepository = reservationRepository; + _bookCopyRepository = bookCopyRepository; + } + + public void createReservation(CreateReservationRequest request) + { + BookCopy bookCopy = _bookCopyRepository.FindByIdOrThrow(request.book_copy_id); + Reservation reservation = new(request.reservation_start_date, request.reservation_end_date,request.book_copy_id); + _reservationRepository.Add(reservation); + } +} diff --git a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs b/web-library/Api/User/Repository/IUserBasicInfoRepository.cs index 9572188..94ab817 100644 --- a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs +++ b/web-library/Api/User/Repository/IUserBasicInfoRepository.cs @@ -1,7 +1,5 @@ namespace web_library.Api.User.Repository; using Entity; -using web_library.Api.User.Entity; - public interface IUserBasicInfoRepository { void Add(UserBasicInfo userBasicInfo); diff --git a/web-library/Api/User/Repository/UserRepository.cs b/web-library/Api/User/Repository/UserRepository.cs index 7ea0f15..b081d51 100644 --- a/web-library/Api/User/Repository/UserRepository.cs +++ b/web-library/Api/User/Repository/UserRepository.cs @@ -2,8 +2,6 @@ namespace web_library.Api.User.Repository; using Entity; -using web_library.Api.User.Entity; - public class UserRepository : IUserRepository { private readonly DataContext _dbContext; @@ -13,7 +11,7 @@ public UserRepository(DataContext dbContext) _dbContext = dbContext; } - public User GetByIdOrThrow(int id) + public User FindByIdOrThrow(int id) { User? user = _dbContext.Users.Find(id); @@ -28,7 +26,7 @@ public User GetByIdOrThrow(int id) return _dbContext.Users.SingleOrDefault(user => user.Email == email); } - public IEnumerable GetAll() + public IEnumerable FindAll() { return _dbContext.Users.ToList(); } diff --git a/web-library/Api/User/Service/AuthService.cs b/web-library/Api/User/Service/AuthService.cs index 46bbbcb..6a8a976 100644 --- a/web-library/Api/User/Service/AuthService.cs +++ b/web-library/Api/User/Service/AuthService.cs @@ -7,9 +7,8 @@ namespace web_library.Api.User.Service; using Entity; -using web_library.Api.User.Entity; -using web_library.Api.User.Repository; -using web_library.Api.User.Request; +using Repository; +using Request; public class AuthService : IAuthService { diff --git a/web-library/DataContext.cs b/web-library/DataContext.cs index 843c2ff..4a5d072 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -5,7 +5,7 @@ namespace web_library using Api.Book.Entity; using Api.Genre.Entity; using Api.User.Entity; - using Api.BookReservation.Entity; + using Api.Reservation.Entity; public class DataContext : DbContext { @@ -20,6 +20,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) { // connect to postgres with connection string from app settings options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); + options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/web-library/IGenericRepository.cs b/web-library/IGenericRepository.cs index 563e702..610b56a 100644 --- a/web-library/IGenericRepository.cs +++ b/web-library/IGenericRepository.cs @@ -2,8 +2,8 @@ public interface IGenericRepository where T : class { - T GetByIdOrThrow(int id); - IEnumerable GetAll(); + T FindByIdOrThrow(int id); + IEnumerable FindAll(); void Add(T entity); void Remove(T entity); } \ No newline at end of file diff --git a/web-library/Migrations/20231202061543_reservationEntity.Designer.cs b/web-library/Migrations/20231204004614_reservationEntity.Designer.cs similarity index 93% rename from web-library/Migrations/20231202061543_reservationEntity.Designer.cs rename to web-library/Migrations/20231204004614_reservationEntity.Designer.cs index d366f33..deff0e0 100644 --- a/web-library/Migrations/20231202061543_reservationEntity.Designer.cs +++ b/web-library/Migrations/20231204004614_reservationEntity.Designer.cs @@ -12,7 +12,7 @@ namespace web_library.Migrations { [DbContext(typeof(DataContext))] - [Migration("20231202061543_reservationEntity")] + [Migration("20231204004614_reservationEntity")] partial class reservationEntity { /// @@ -108,7 +108,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("book_copies"); }); - modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -117,19 +117,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("bookCopyId") - .HasColumnType("integer") - .HasColumnName("book_copy_id"); + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); b.HasKey("Id"); - b.HasIndex("bookCopyId") - .IsUnique(); - - b.ToTable("reservations"); + b.ToTable("genres"); }); - modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => + modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -138,14 +136,24 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); + b.Property("bookCopyId") + .HasColumnType("integer") + .HasColumnName("book_copy_id"); + + b.Property("reservationEndDate") + .HasColumnType("date") + .HasColumnName("reservation_end_date"); + + b.Property("reservationStartDate") + .HasColumnType("date") + .HasColumnName("reservation_start_date"); b.HasKey("Id"); - b.ToTable("genres"); + b.HasIndex("bookCopyId") + .IsUnique(); + + b.ToTable("reservations"); }); modelBuilder.Entity("web_library.Api.User.Entity.User", b => @@ -242,11 +250,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Book"); }); - modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => { b.HasOne("web_library.Api.Book.Entity.BookCopy", "bookCopy") .WithOne("reservation") - .HasForeignKey("web_library.Api.BookReservation.Entity.Reservation", "bookCopyId") + .HasForeignKey("web_library.Api.Reservation.Entity.Reservation", "bookCopyId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/web-library/Migrations/20231202061543_reservationEntity.cs b/web-library/Migrations/20231204004614_reservationEntity.cs similarity index 86% rename from web-library/Migrations/20231202061543_reservationEntity.cs rename to web-library/Migrations/20231204004614_reservationEntity.cs index 2cc4bba..41d71cf 100644 --- a/web-library/Migrations/20231202061543_reservationEntity.cs +++ b/web-library/Migrations/20231204004614_reservationEntity.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore.Migrations; +using System; +using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -17,6 +18,8 @@ protected override void Up(MigrationBuilder migrationBuilder) { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + reservation_start_date = table.Column(type: "date", nullable: false), + reservation_end_date = table.Column(type: "date", nullable: false), book_copy_id = table.Column(type: "integer", nullable: false) }, constraints: table => diff --git a/web-library/Migrations/DataContextModelSnapshot.cs b/web-library/Migrations/DataContextModelSnapshot.cs index 6043b64..29869c3 100644 --- a/web-library/Migrations/DataContextModelSnapshot.cs +++ b/web-library/Migrations/DataContextModelSnapshot.cs @@ -105,7 +105,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("book_copies"); }); - modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -114,19 +114,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("bookCopyId") - .HasColumnType("integer") - .HasColumnName("book_copy_id"); + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); b.HasKey("Id"); - b.HasIndex("bookCopyId") - .IsUnique(); - - b.ToTable("reservations"); + b.ToTable("genres"); }); - modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => + modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -135,14 +133,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); + b.Property("bookCopyId") + .HasColumnType("integer") + .HasColumnName("book_copy_id"); + + b.Property("reservationEndDate") + .HasColumnType("date") + .HasColumnName("reservation_end_date"); + + b.Property("reservationStartDate") + .HasColumnType("date") + .HasColumnName("reservation_start_date"); b.HasKey("Id"); - b.ToTable("genres"); + b.HasIndex("bookCopyId") + .IsUnique(); + + b.ToTable("reservations"); }); modelBuilder.Entity("web_library.Api.User.Entity.User", b => @@ -239,11 +247,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Book"); }); - modelBuilder.Entity("web_library.Api.BookReservation.Entity.Reservation", b => + modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => { b.HasOne("web_library.Api.Book.Entity.BookCopy", "bookCopy") .WithOne("reservation") - .HasForeignKey("web_library.Api.BookReservation.Entity.Reservation", "bookCopyId") + .HasForeignKey("web_library.Api.Reservation.Entity.Reservation", "bookCopyId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/web-library/Program.cs b/web-library/Program.cs index 95297ff..dc5e354 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -1,51 +1,53 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using System.Text; using web_library; using web_library.Api.Book.Repository; using web_library.Api.Book.Service; +using web_library.Api.Book.DataProvider; using web_library.Api.User.Repository; using web_library.Api.User.Service; +using web_library.Api.Reservation.Repostiory; +using web_library.Api.Reservation.Service; +using web_library.Api.Reservation.DataProvider; var builder = WebApplication.CreateBuilder(args); - builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("WebApiDatabase")) ); -builder.Services.AddAuthentication(options => -{ - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; -}).AddJwtBearer(o => -{ - o.TokenValidationParameters = new TokenValidationParameters - { - ValidIssuer = builder.Configuration["Jwt:Issuer"], - ValidAudience = builder.Configuration["Jwt:Audience"], - IssuerSigningKey = new SymmetricSecurityKey - (Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])), - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = false, - ValidateIssuerSigningKey = true - }; -}); - +//builder.Services.AddAuthorization(); +//builder.Services.AddAuthentication(options => +//{ +// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; +// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; +// options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; +//}).AddJwtBearer(o => +//{ +// o.TokenValidationParameters = new TokenValidationParameters +// { +// ValidIssuer = builder.Configuration["Jwt:Issuer"], +// ValidAudience = builder.Configuration["Jwt:Audience"], +// IssuerSigningKey = new SymmetricSecurityKey +// (Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])), +// ValidateIssuer = true, +// ValidateAudience = true, +// ValidateLifetime = false, +// ValidateIssuerSigningKey = true +// }; +//}); builder.Services.AddControllers(); +builder.Services.AddControllers().AddJsonOptions(options => +{ + options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; +}); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); - - // Add services to the container. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -81,18 +83,14 @@ }); }); -builder.Services.AddAuthorization(); -builder.Services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("WebApiDatabase")) -); -builder.Services.AddControllers().AddJsonOptions(options => -{ - options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; -}); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -104,8 +102,8 @@ app.UseRouting(); -app.UseAuthentication(); -app.UseAuthorization(); +//app.UseAuthentication(); +//app.UseAuthorization(); app.UseEndpoints(endpoints => { diff --git a/web-library/Shared/NotFoundException.cs b/web-library/Shared/NotFoundException.cs new file mode 100644 index 0000000..8b321dc --- /dev/null +++ b/web-library/Shared/NotFoundException.cs @@ -0,0 +1,9 @@ +namespace web_library.Shared; + +public class NotFoundException : Exception +{ + public NotFoundException(string message) + : base(message) + { + } +} \ No newline at end of file From 344fcf23b72d60f16f40daad6148f3fbe6bde72c Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Fri, 8 Dec 2023 15:27:19 +0100 Subject: [PATCH 08/17] fixes --- web-library/Genre/Controller/GenresController.cs | 4 ++-- web-library/Genre/Repository/GenreRepository.cs | 2 ++ ...31202031627_userAndUserBasicInfoEntity.Designer.cs | 6 ------ web-library/appsettings.Development.json | 11 ----------- 4 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 web-library/appsettings.Development.json diff --git a/web-library/Genre/Controller/GenresController.cs b/web-library/Genre/Controller/GenresController.cs index dada424..1f72c53 100644 --- a/web-library/Genre/Controller/GenresController.cs +++ b/web-library/Genre/Controller/GenresController.cs @@ -22,13 +22,13 @@ public ActionResult Post([FromBody] CreateGenreRequest request) try { _genreService.createGenre(request); + return Ok(); } catch (Exception) { - return NotFound(); + return BadRequest(); } - return Ok(); } } } diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs index 631c97f..0ae66ec 100644 --- a/web-library/Genre/Repository/GenreRepository.cs +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -1,6 +1,8 @@ namespace web_library.Genre.Repository { using Entity; + using web_library.Shared; + public class GenreRepository : IGenreRepository { private readonly DataContext _context; diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs index ab8ecfb..717fa9d 100644 --- a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs +++ b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs @@ -11,12 +11,6 @@ namespace web_library.Migrations { - [DbContext(typeof(DataContext))] -<<<<<<<< HEAD:web-library/Migrations/20231202024346_userAndUserBasicInfoEntity.Designer.cs - [Migration("20231202024346_userAndUserBasicInfoEntity")] -======== - [Migration("20231202031627_userAndUserBasicInfoEntity")] ->>>>>>>> 5-endpoint-do-dodawania-ksiązki:web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs partial class userAndUserBasicInfoEntity { /// diff --git a/web-library/appsettings.Development.json b/web-library/appsettings.Development.json deleted file mode 100644 index 43aa661..0000000 --- a/web-library/appsettings.Development.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConnectionStrings": { - "WebApiDatabase": "Host=localhost; Database=TinyLib; Username=postgres; Password=kuba" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} From 3d14d1a76b3107df1cc8a7adcbf54c25413ce179 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Fri, 8 Dec 2023 15:34:19 +0100 Subject: [PATCH 09/17] change directory tree --- .../Api/Book/Controller/BookController.cs | 73 ------------------- web-library/Api/User/Service/IUserService.cs | 5 -- web-library/{Api => }/Book/Entity/Book.cs | 5 +- web-library/{Api => }/Book/Entity/BookCopy.cs | 4 +- .../Book/Repository/BookCopyRepository.cs | 4 +- .../Book/Repository/BookRepository.cs | 3 +- .../Book/Repository/IBookCopyRepository.cs | 4 +- .../Book/Repository/IBookRepository.cs | 4 +- .../Book/Request/AssigneGenreToBookRequest.cs | 0 .../Book/Request/CreateBookRequest.cs | 2 +- .../{Api => }/Book/Service/BookService.cs | 3 +- .../{Api => }/Book/Service/IBookService.cs | 4 +- .../BookReservation/Entity/Reservation.cs | 5 +- web-library/DataContext.cs | 3 + web-library/{Api => }/Genre/Entity/Genre.cs | 5 +- web-library/Program.cs | 7 ++ .../User/Controller/AuthController.cs | 6 +- web-library/{Api => }/User/Entity/User.cs | 2 +- .../{Api => }/User/Entity/UserBasicInfo.cs | 2 +- .../Repository/IUserBasicInfoRepository.cs | 4 +- .../User/Repository/IUserRepository.cs | 4 +- .../Repository/UserBasicInfoRepository.cs | 4 +- .../User/Repository/UserRepository.cs | 4 +- .../User/Request/LoginUserRequest.cs | 2 +- .../User/Request/RegisterUserRequest.cs | 2 +- .../{Api => }/User/Service/AuthService.cs | 8 +- .../{Api => }/User/Service/IAuthService.cs | 4 +- web-library/User/Service/IUserService.cs | 5 ++ .../{Api => }/User/Service/UserService.cs | 4 +- web-library/web-library.csproj | 6 +- 30 files changed, 66 insertions(+), 122 deletions(-) delete mode 100644 web-library/Api/Book/Controller/BookController.cs delete mode 100644 web-library/Api/User/Service/IUserService.cs rename web-library/{Api => }/Book/Entity/Book.cs (94%) rename web-library/{Api => }/Book/Entity/BookCopy.cs (82%) rename web-library/{Api => }/Book/Repository/BookCopyRepository.cs (89%) rename web-library/{Api => }/Book/Repository/BookRepository.cs (92%) rename web-library/{Api => }/Book/Repository/IBookCopyRepository.cs (52%) rename web-library/{Api => }/Book/Repository/IBookRepository.cs (61%) rename web-library/{Api => }/Book/Request/AssigneGenreToBookRequest.cs (100%) rename web-library/{Api => }/Book/Request/CreateBookRequest.cs (90%) rename web-library/{Api => }/Book/Service/BookService.cs (95%) rename web-library/{Api => }/Book/Service/IBookService.cs (67%) rename web-library/{Api => }/BookReservation/Entity/Reservation.cs (90%) rename web-library/{Api => }/Genre/Entity/Genre.cs (85%) rename web-library/{Api => }/User/Controller/AuthController.cs (89%) rename web-library/{Api => }/User/Entity/User.cs (92%) rename web-library/{Api => }/User/Entity/UserBasicInfo.cs (96%) rename web-library/{Api => }/User/Repository/IUserBasicInfoRepository.cs (64%) rename web-library/{Api => }/User/Repository/IUserRepository.cs (61%) rename web-library/{Api => }/User/Repository/UserBasicInfoRepository.cs (85%) rename web-library/{Api => }/User/Repository/UserRepository.cs (92%) rename web-library/{Api => }/User/Request/LoginUserRequest.cs (76%) rename web-library/{Api => }/User/Request/RegisterUserRequest.cs (87%) rename web-library/{Api => }/User/Service/AuthService.cs (95%) rename web-library/{Api => }/User/Service/IAuthService.cs (73%) create mode 100644 web-library/User/Service/IUserService.cs rename web-library/{Api => }/User/Service/UserService.cs (72%) diff --git a/web-library/Api/Book/Controller/BookController.cs b/web-library/Api/Book/Controller/BookController.cs deleted file mode 100644 index 84582ef..0000000 --- a/web-library/Api/Book/Controller/BookController.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace web_library.Api.Book.Controller -{ - using Entity; - using web_library.Api.Book.Request; - using web_library.Api.Book.Service; - - [Route("api/[controller]")] - [ApiController] - public class BookController : ControllerBase - { - private readonly IBookService _bookService; - - public BookController(IBookService bookService) - { - _bookService = bookService; - } - - // GET: api/ - [HttpGet] - public ActionResult> Get() - { - return Ok(); - } - - // GET api//5 - [HttpGet("{id}")] - public ActionResult Get(int id) - { - - return Ok(); - } - - // POST api/ - [HttpPost] - public ActionResult Post([FromBody] CreateBookRequest request) - { - try - { - _bookService.createBook(request); - } - catch (Exception) - { - return NotFound(); - } - return Ok(); - } - - // PUT api//5 - [HttpPut("{id}")] - public ActionResult Put(int id, [FromBody] AssigneGenreToBookRequest request) - { - try - { - request.book_id = id; - _bookService.assigneGenre(request); - } catch (Exception) - { - return NotFound(); - } - return Ok(); - } - - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} diff --git a/web-library/Api/User/Service/IUserService.cs b/web-library/Api/User/Service/IUserService.cs deleted file mode 100644 index c98354a..0000000 --- a/web-library/Api/User/Service/IUserService.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace web_library.Api.User.Service; - -public interface IUserService -{ -} \ No newline at end of file diff --git a/web-library/Api/Book/Entity/Book.cs b/web-library/Book/Entity/Book.cs similarity index 94% rename from web-library/Api/Book/Entity/Book.cs rename to web-library/Book/Entity/Book.cs index 1d83af6..8742c7e 100644 --- a/web-library/Api/Book/Entity/Book.cs +++ b/web-library/Book/Entity/Book.cs @@ -1,7 +1,8 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Book.Entity; -using web_library.Api.Genre.Entity; +namespace web_library.Book.Entity; + +using web_library.Genre.Entity; [Table("books")] public class Book diff --git a/web-library/Api/Book/Entity/BookCopy.cs b/web-library/Book/Entity/BookCopy.cs similarity index 82% rename from web-library/Api/Book/Entity/BookCopy.cs rename to web-library/Book/Entity/BookCopy.cs index a7a6dc5..5c1a9d1 100644 --- a/web-library/Api/Book/Entity/BookCopy.cs +++ b/web-library/Book/Entity/BookCopy.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; -using web_library.Api.BookReservation.Entity; +using web_library.BookReservation.Entity; -namespace web_library.Api.Book.Entity; +namespace web_library.Book.Entity; [Table("book_copies")] public class BookCopy diff --git a/web-library/Api/Book/Repository/BookCopyRepository.cs b/web-library/Book/Repository/BookCopyRepository.cs similarity index 89% rename from web-library/Api/Book/Repository/BookCopyRepository.cs rename to web-library/Book/Repository/BookCopyRepository.cs index 4c69d7f..277c5f7 100644 --- a/web-library/Api/Book/Repository/BookCopyRepository.cs +++ b/web-library/Book/Repository/BookCopyRepository.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Entity; +using web_library.Book.Entity; -namespace web_library.Api.Book.Repository +namespace web_library.Book.Repository { public class BookCopyRepository : IBookCopyRepository { diff --git a/web-library/Api/Book/Repository/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs similarity index 92% rename from web-library/Api/Book/Repository/BookRepository.cs rename to web-library/Book/Repository/BookRepository.cs index 67103a6..bc74afb 100644 --- a/web-library/Api/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -1,8 +1,7 @@ using web_library.Shared; -namespace web_library.Book.DataProvider +namespace web_library.Book.Repository { using Entity; - using web_library.Api.Book.Entity; public class BookRepository : IBookRepository { diff --git a/web-library/Api/Book/Repository/IBookCopyRepository.cs b/web-library/Book/Repository/IBookCopyRepository.cs similarity index 52% rename from web-library/Api/Book/Repository/IBookCopyRepository.cs rename to web-library/Book/Repository/IBookCopyRepository.cs index b74b183..03e6934 100644 --- a/web-library/Api/Book/Repository/IBookCopyRepository.cs +++ b/web-library/Book/Repository/IBookCopyRepository.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Entity; +using web_library.Book.Entity; -namespace web_library.Api.Book.Repository +namespace web_library.Book.Repository { public interface IBookCopyRepository : IGenericRepository { diff --git a/web-library/Api/Book/Repository/IBookRepository.cs b/web-library/Book/Repository/IBookRepository.cs similarity index 61% rename from web-library/Api/Book/Repository/IBookRepository.cs rename to web-library/Book/Repository/IBookRepository.cs index 6d4c497..f0abed7 100644 --- a/web-library/Api/Book/Repository/IBookRepository.cs +++ b/web-library/Book/Repository/IBookRepository.cs @@ -1,7 +1,7 @@ -namespace web_library.Api.Book.Repository +namespace web_library.Book.Repository { using Entity; - using web_library.Api.Book.Entity; + using web_library.Book.Entity; public interface IBookRepository : IGenericRepository { diff --git a/web-library/Api/Book/Request/AssigneGenreToBookRequest.cs b/web-library/Book/Request/AssigneGenreToBookRequest.cs similarity index 100% rename from web-library/Api/Book/Request/AssigneGenreToBookRequest.cs rename to web-library/Book/Request/AssigneGenreToBookRequest.cs diff --git a/web-library/Api/Book/Request/CreateBookRequest.cs b/web-library/Book/Request/CreateBookRequest.cs similarity index 90% rename from web-library/Api/Book/Request/CreateBookRequest.cs rename to web-library/Book/Request/CreateBookRequest.cs index b97e554..d303b46 100644 --- a/web-library/Api/Book/Request/CreateBookRequest.cs +++ b/web-library/Book/Request/CreateBookRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.Book.Request +namespace web_library.Book.Request { public class CreateBookRequest { diff --git a/web-library/Api/Book/Service/BookService.cs b/web-library/Book/Service/BookService.cs similarity index 95% rename from web-library/Api/Book/Service/BookService.cs rename to web-library/Book/Service/BookService.cs index aa07026..523f5cf 100644 --- a/web-library/Api/Book/Service/BookService.cs +++ b/web-library/Book/Service/BookService.cs @@ -1,8 +1,9 @@ -namespace web_library.Api.Book.Service +namespace web_library.Book.Service { using Entity; using Genre.Entity; using Newtonsoft.Json; + using web_library.Book.Entity; using web_library.Book.Repository; using web_library.Genre.Repository; diff --git a/web-library/Api/Book/Service/IBookService.cs b/web-library/Book/Service/IBookService.cs similarity index 67% rename from web-library/Api/Book/Service/IBookService.cs rename to web-library/Book/Service/IBookService.cs index f723ba2..41ddd37 100644 --- a/web-library/Api/Book/Service/IBookService.cs +++ b/web-library/Book/Service/IBookService.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Request; +using web_library.Book.Request; -namespace web_library.Api.Book.Service +namespace web_library.Book.Service { public interface IBookService { diff --git a/web-library/Api/BookReservation/Entity/Reservation.cs b/web-library/BookReservation/Entity/Reservation.cs similarity index 90% rename from web-library/Api/BookReservation/Entity/Reservation.cs rename to web-library/BookReservation/Entity/Reservation.cs index 7710d16..6f389f4 100644 --- a/web-library/Api/BookReservation/Entity/Reservation.cs +++ b/web-library/BookReservation/Entity/Reservation.cs @@ -1,9 +1,10 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.BookReservation.Entity +namespace web_library.BookReservation.Entity { using System.ComponentModel.DataAnnotations; - using web_library.Api.Book.Entity; + using web_library.Book.Entity; + [Table("reservations")] public class Reservation { diff --git a/web-library/DataContext.cs b/web-library/DataContext.cs index 843c2ff..51565de 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -6,6 +6,9 @@ namespace web_library using Api.Genre.Entity; using Api.User.Entity; using Api.BookReservation.Entity; + using web_library.Book.Entity; + using web_library.BookReservation.Entity; + using web_library.User.Entity; public class DataContext : DbContext { diff --git a/web-library/Api/Genre/Entity/Genre.cs b/web-library/Genre/Entity/Genre.cs similarity index 85% rename from web-library/Api/Genre/Entity/Genre.cs rename to web-library/Genre/Entity/Genre.cs index 5c83e4f..48c3227 100644 --- a/web-library/Api/Genre/Entity/Genre.cs +++ b/web-library/Genre/Entity/Genre.cs @@ -1,8 +1,9 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Genre.Entity +namespace web_library.Genre.Entity { - using web_library.Api.Book.Entity; + using web_library.Book.Entity; + [Table("genres")] public class Genre { diff --git a/web-library/Program.cs b/web-library/Program.cs index d1536c6..0bbbafb 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -4,6 +4,12 @@ using Microsoft.OpenApi.Models; using System.Text; using web_library; +<<<<<<< HEAD +using web_library.Book.Repository; +using web_library.Book.Service; +using web_library.User.Repository; +using web_library.User.Service; +======= using web_library.Book.DataProvider; using web_library.Book.Repository; using web_library.Book.Service; @@ -11,6 +17,7 @@ using web_library.Genre.Service; using web_library.User.Repository; using web_library.User.Service; +>>>>>>> 6-endpoint-do-dodawania-gatunku var builder = WebApplication.CreateBuilder(args); diff --git a/web-library/Api/User/Controller/AuthController.cs b/web-library/User/Controller/AuthController.cs similarity index 89% rename from web-library/Api/User/Controller/AuthController.cs rename to web-library/User/Controller/AuthController.cs index f2f4a8a..12294a7 100644 --- a/web-library/Api/User/Controller/AuthController.cs +++ b/web-library/User/Controller/AuthController.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Authorization; -namespace web_library.Api.User.Controller; +namespace web_library.User.Controller; using Microsoft.AspNetCore.Mvc; -using web_library.Api.User.Request; -using web_library.Api.User.Service; +using web_library.User.Request; +using web_library.User.Service; [ApiController] [Route("api/auth")] diff --git a/web-library/Api/User/Entity/User.cs b/web-library/User/Entity/User.cs similarity index 92% rename from web-library/Api/User/Entity/User.cs rename to web-library/User/Entity/User.cs index 562d724..6c51c86 100644 --- a/web-library/Api/User/Entity/User.cs +++ b/web-library/User/Entity/User.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.User.Entity; +namespace web_library.User.Entity; [Table("users")] public class User diff --git a/web-library/Api/User/Entity/UserBasicInfo.cs b/web-library/User/Entity/UserBasicInfo.cs similarity index 96% rename from web-library/Api/User/Entity/UserBasicInfo.cs rename to web-library/User/Entity/UserBasicInfo.cs index 9907f79..83c32a6 100644 --- a/web-library/Api/User/Entity/UserBasicInfo.cs +++ b/web-library/User/Entity/UserBasicInfo.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.User.Entity; +namespace web_library.User.Entity; [Table("user_basic_info")] public class UserBasicInfo diff --git a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs b/web-library/User/Repository/IUserBasicInfoRepository.cs similarity index 64% rename from web-library/Api/User/Repository/IUserBasicInfoRepository.cs rename to web-library/User/Repository/IUserBasicInfoRepository.cs index 9572188..5ca44ca 100644 --- a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs +++ b/web-library/User/Repository/IUserBasicInfoRepository.cs @@ -1,6 +1,6 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public interface IUserBasicInfoRepository { diff --git a/web-library/Api/User/Repository/IUserRepository.cs b/web-library/User/Repository/IUserRepository.cs similarity index 61% rename from web-library/Api/User/Repository/IUserRepository.cs rename to web-library/User/Repository/IUserRepository.cs index 708e44f..e61248a 100644 --- a/web-library/Api/User/Repository/IUserRepository.cs +++ b/web-library/User/Repository/IUserRepository.cs @@ -1,6 +1,6 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public interface IUserRepository : IGenericRepository { diff --git a/web-library/Api/User/Repository/UserBasicInfoRepository.cs b/web-library/User/Repository/UserBasicInfoRepository.cs similarity index 85% rename from web-library/Api/User/Repository/UserBasicInfoRepository.cs rename to web-library/User/Repository/UserBasicInfoRepository.cs index 2f34828..4c5374d 100644 --- a/web-library/Api/User/Repository/UserBasicInfoRepository.cs +++ b/web-library/User/Repository/UserBasicInfoRepository.cs @@ -1,6 +1,6 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public class UserBasicInfoRepository : IUserBasicInfoRepository { diff --git a/web-library/Api/User/Repository/UserRepository.cs b/web-library/User/Repository/UserRepository.cs similarity index 92% rename from web-library/Api/User/Repository/UserRepository.cs rename to web-library/User/Repository/UserRepository.cs index 7ea0f15..8570275 100644 --- a/web-library/Api/User/Repository/UserRepository.cs +++ b/web-library/User/Repository/UserRepository.cs @@ -1,8 +1,8 @@ using web_library.Shared; -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public class UserRepository : IUserRepository { diff --git a/web-library/Api/User/Request/LoginUserRequest.cs b/web-library/User/Request/LoginUserRequest.cs similarity index 76% rename from web-library/Api/User/Request/LoginUserRequest.cs rename to web-library/User/Request/LoginUserRequest.cs index 8853c67..54ed1e4 100644 --- a/web-library/Api/User/Request/LoginUserRequest.cs +++ b/web-library/User/Request/LoginUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.User.Request +namespace web_library.User.Request { public class LoginUserRequest { diff --git a/web-library/Api/User/Request/RegisterUserRequest.cs b/web-library/User/Request/RegisterUserRequest.cs similarity index 87% rename from web-library/Api/User/Request/RegisterUserRequest.cs rename to web-library/User/Request/RegisterUserRequest.cs index 7618213..ff7d4cf 100644 --- a/web-library/Api/User/Request/RegisterUserRequest.cs +++ b/web-library/User/Request/RegisterUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.User.Request; +namespace web_library.User.Request; public class RegisterUserRequest { diff --git a/web-library/Api/User/Service/AuthService.cs b/web-library/User/Service/AuthService.cs similarity index 95% rename from web-library/Api/User/Service/AuthService.cs rename to web-library/User/Service/AuthService.cs index 46bbbcb..3c7f593 100644 --- a/web-library/Api/User/Service/AuthService.cs +++ b/web-library/User/Service/AuthService.cs @@ -5,11 +5,11 @@ using System.Security.Cryptography; using System.Text; -namespace web_library.Api.User.Service; +namespace web_library.User.Service; using Entity; -using web_library.Api.User.Entity; -using web_library.Api.User.Repository; -using web_library.Api.User.Request; +using web_library.User.Entity; +using web_library.User.Repository; +using web_library.User.Request; public class AuthService : IAuthService { diff --git a/web-library/Api/User/Service/IAuthService.cs b/web-library/User/Service/IAuthService.cs similarity index 73% rename from web-library/Api/User/Service/IAuthService.cs rename to web-library/User/Service/IAuthService.cs index d52185f..fbe4e80 100644 --- a/web-library/Api/User/Service/IAuthService.cs +++ b/web-library/User/Service/IAuthService.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; -using web_library.Api.User.Request; +using web_library.User.Request; -namespace web_library.Api.User.Service +namespace web_library.User.Service { public interface IAuthService { diff --git a/web-library/User/Service/IUserService.cs b/web-library/User/Service/IUserService.cs new file mode 100644 index 0000000..d9facb2 --- /dev/null +++ b/web-library/User/Service/IUserService.cs @@ -0,0 +1,5 @@ +namespace web_library.User.Service; + +public interface IUserService +{ +} \ No newline at end of file diff --git a/web-library/Api/User/Service/UserService.cs b/web-library/User/Service/UserService.cs similarity index 72% rename from web-library/Api/User/Service/UserService.cs rename to web-library/User/Service/UserService.cs index 0d977ab..ba1b9de 100644 --- a/web-library/Api/User/Service/UserService.cs +++ b/web-library/User/Service/UserService.cs @@ -1,6 +1,6 @@ -using web_library.Api.User.Repository; +using web_library.User.Repository; -namespace web_library.Api.User.Service; +namespace web_library.User.Service; public class UserService : IUserService { diff --git a/web-library/web-library.csproj b/web-library/web-library.csproj index 8035a6d..dbcbff7 100644 --- a/web-library/web-library.csproj +++ b/web-library/web-library.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -23,4 +23,8 @@ + + + + From 1b4a19f51cd6497a409e3d2df6d53eb661dfc969 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 07:31:35 +0100 Subject: [PATCH 10/17] fixes --- .../Api/Book/Controller/BookController.cs | 63 ------------ .../Book/Repository/IBookCopyRepository.cs | 7 -- web-library/Api/User/Service/IUserService.cs | 5 - .../Book/DataProvider/BookDataProvider.cs | 7 +- .../Book/DataProvider/IBookDataProvider.cs | 4 +- web-library/{Api => }/Book/Entity/Book.cs | 2 +- web-library/{Api => }/Book/Entity/BookCopy.cs | 2 +- web-library/{Api => }/Book/Model/BookModel.cs | 2 +- .../Book/Repository/BookCopyRepository.cs | 6 +- .../Book/Repository/BookRepository.cs | 6 +- .../Book/Repository/IBookCopyRepository.cs | 7 ++ .../Book/Repository/IBookRepository.cs | 4 +- .../Book/Request/CreateBookRequest.cs | 4 +- .../{Api => }/Book/Service/BookService.cs | 5 +- .../{Api => }/Book/Service/IBookService.cs | 4 +- web-library/DataContext.cs | 99 +++++++++---------- web-library/{Api => }/Genre/Entity/Genre.cs | 4 +- web-library/Program.cs | 16 +-- .../Controller/ReservationController.cs | 2 +- .../DataProvider/IReservationDataProvider.cs | 4 +- .../DataProvider/ReservationDataProvider.cs | 10 +- .../Reservation/Entity/Reservation.cs | 6 +- .../Reservation/Model/ReservationModel.cs | 6 +- .../Repostiory/IReservationRepository.cs | 4 +- .../Repostiory/ReservationRepository.cs | 3 +- .../Request/CreateReservationRequest.cs | 3 +- .../Service/IReservationService.cs | 4 +- .../Reservation/Service/ReservationService.cs | 10 +- .../User/Controller/AuthController.cs | 6 +- web-library/{Api => }/User/Entity/User.cs | 2 +- .../{Api => }/User/Entity/UserBasicInfo.cs | 2 +- .../Repository/IUserBasicInfoRepository.cs | 4 +- .../User/Repository/IUserRepository.cs | 4 +- .../Repository/UserBasicInfoRepository.cs | 4 +- .../User/Repository/UserRepository.cs | 4 +- .../User/Request/LoginUserRequest.cs | 2 +- .../User/Request/RegisterUserRequest.cs | 2 +- .../{Api => }/User/Service/AuthService.cs | 5 +- .../{Api => }/User/Service/IAuthService.cs | 4 +- web-library/User/Service/IUserService.cs | 5 + .../{Api => }/User/Service/UserService.cs | 4 +- 41 files changed, 150 insertions(+), 197 deletions(-) delete mode 100644 web-library/Api/Book/Controller/BookController.cs delete mode 100644 web-library/Api/Book/Repository/IBookCopyRepository.cs delete mode 100644 web-library/Api/User/Service/IUserService.cs rename web-library/{Api => }/Book/DataProvider/BookDataProvider.cs (88%) rename web-library/{Api => }/Book/DataProvider/IBookDataProvider.cs (56%) rename web-library/{Api => }/Book/Entity/Book.cs (97%) rename web-library/{Api => }/Book/Entity/BookCopy.cs (91%) rename web-library/{Api => }/Book/Model/BookModel.cs (95%) rename web-library/{Api => }/Book/Repository/BookCopyRepository.cs (84%) rename web-library/{Api => }/Book/Repository/BookRepository.cs (84%) create mode 100644 web-library/Book/Repository/IBookCopyRepository.cs rename web-library/{Api => }/Book/Repository/IBookRepository.cs (60%) rename web-library/{Api => }/Book/Request/CreateBookRequest.cs (93%) rename web-library/{Api => }/Book/Service/BookService.cs (87%) rename web-library/{Api => }/Book/Service/IBookService.cs (51%) rename web-library/{Api => }/Genre/Entity/Genre.cs (85%) rename web-library/{Api => }/Reservation/Controller/ReservationController.cs (95%) rename web-library/{Api => }/Reservation/DataProvider/IReservationDataProvider.cs (53%) rename web-library/{Api => }/Reservation/DataProvider/ReservationDataProvider.cs (85%) rename web-library/{Api => }/Reservation/Entity/Reservation.cs (88%) rename web-library/{Api => }/Reservation/Model/ReservationModel.cs (88%) rename web-library/{Api => }/Reservation/Repostiory/IReservationRepository.cs (54%) rename web-library/{Api => }/Reservation/Repostiory/ReservationRepository.cs (91%) rename web-library/{Api => }/Reservation/Request/CreateReservationRequest.cs (86%) rename web-library/{Api => }/Reservation/Service/IReservationService.cs (57%) rename web-library/{Api => }/Reservation/Service/ReservationService.cs (73%) rename web-library/{Api => }/User/Controller/AuthController.cs (89%) rename web-library/{Api => }/User/Entity/User.cs (92%) rename web-library/{Api => }/User/Entity/UserBasicInfo.cs (96%) rename web-library/{Api => }/User/Repository/IUserBasicInfoRepository.cs (66%) rename web-library/{Api => }/User/Repository/IUserRepository.cs (61%) rename web-library/{Api => }/User/Repository/UserBasicInfoRepository.cs (85%) rename web-library/{Api => }/User/Repository/UserRepository.cs (92%) rename web-library/{Api => }/User/Request/LoginUserRequest.cs (76%) rename web-library/{Api => }/User/Request/RegisterUserRequest.cs (87%) rename web-library/{Api => }/User/Service/AuthService.cs (96%) rename web-library/{Api => }/User/Service/IAuthService.cs (73%) create mode 100644 web-library/User/Service/IUserService.cs rename web-library/{Api => }/User/Service/UserService.cs (72%) diff --git a/web-library/Api/Book/Controller/BookController.cs b/web-library/Api/Book/Controller/BookController.cs deleted file mode 100644 index 146c857..0000000 --- a/web-library/Api/Book/Controller/BookController.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace web_library.Api.Book.Controller; - -using DataProvider; -using Request; -using Service; -using Model; - -[Route("api/[controller]")] -[ApiController] -public class BookController : ControllerBase -{ - private readonly IBookService _bookService; - private readonly IBookDataProvider _bookDataProvider; - - public BookController(IBookService bookService, IBookDataProvider bookDataProvider) - { - _bookService = bookService; - _bookDataProvider = bookDataProvider; - } - - [HttpGet] - public ActionResult> Index() - { - return Ok(_bookDataProvider.getAll()); - } - - [HttpGet("{id}")] - public ActionResult Index(int id) - { - - return Ok(_bookDataProvider.getById(id)); - } - - // POST api/ - [HttpPost] - public ActionResult Create([FromBody] CreateBookRequest request) - { - try - { - _bookService.createBook(request); - } - catch - (Exception) - { - return NotFound(); - } - return Ok(); - } - - // SEED - [HttpPost("seed")] - public ActionResult Seed(CreateBookRequest request) - { - - CreateBookRequest bookRequest = new CreateBookRequest("random"); - _bookService.createBook(bookRequest); - - return Ok(); - } -} - diff --git a/web-library/Api/Book/Repository/IBookCopyRepository.cs b/web-library/Api/Book/Repository/IBookCopyRepository.cs deleted file mode 100644 index d03a296..0000000 --- a/web-library/Api/Book/Repository/IBookCopyRepository.cs +++ /dev/null @@ -1,7 +0,0 @@ -using web_library.Api.Book.Entity; - -namespace web_library.Api.Book.Repository; - -public interface IBookCopyRepository : IGenericRepository -{ -} \ No newline at end of file diff --git a/web-library/Api/User/Service/IUserService.cs b/web-library/Api/User/Service/IUserService.cs deleted file mode 100644 index c98354a..0000000 --- a/web-library/Api/User/Service/IUserService.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace web_library.Api.User.Service; - -public interface IUserService -{ -} \ No newline at end of file diff --git a/web-library/Api/Book/DataProvider/BookDataProvider.cs b/web-library/Book/DataProvider/BookDataProvider.cs similarity index 88% rename from web-library/Api/Book/DataProvider/BookDataProvider.cs rename to web-library/Book/DataProvider/BookDataProvider.cs index 12a443a..8709268 100644 --- a/web-library/Api/Book/DataProvider/BookDataProvider.cs +++ b/web-library/Book/DataProvider/BookDataProvider.cs @@ -1,8 +1,7 @@ -using web_library.Api.Book.Model; -using web_library.Api.Book.Repository; - -namespace web_library.Api.Book.DataProvider; +namespace web_library.Book.DataProvider; using Entity; +using web_library.Book.Model; +using web_library.Book.Repository; public class BookDataProvider : IBookDataProvider { diff --git a/web-library/Api/Book/DataProvider/IBookDataProvider.cs b/web-library/Book/DataProvider/IBookDataProvider.cs similarity index 56% rename from web-library/Api/Book/DataProvider/IBookDataProvider.cs rename to web-library/Book/DataProvider/IBookDataProvider.cs index 9939e06..d3ba205 100644 --- a/web-library/Api/Book/DataProvider/IBookDataProvider.cs +++ b/web-library/Book/DataProvider/IBookDataProvider.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Model; +using web_library.Book.Model; -namespace web_library.Api.Book.DataProvider; +namespace web_library.Book.DataProvider; public interface IBookDataProvider { diff --git a/web-library/Api/Book/Entity/Book.cs b/web-library/Book/Entity/Book.cs similarity index 97% rename from web-library/Api/Book/Entity/Book.cs rename to web-library/Book/Entity/Book.cs index 85c729c..d61b81e 100644 --- a/web-library/Api/Book/Entity/Book.cs +++ b/web-library/Book/Entity/Book.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Book.Entity; +namespace web_library.Book.Entity; using Genre.Entity; [Table("books")] diff --git a/web-library/Api/Book/Entity/BookCopy.cs b/web-library/Book/Entity/BookCopy.cs similarity index 91% rename from web-library/Api/Book/Entity/BookCopy.cs rename to web-library/Book/Entity/BookCopy.cs index c02acbe..9a4ec50 100644 --- a/web-library/Api/Book/Entity/BookCopy.cs +++ b/web-library/Book/Entity/BookCopy.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Book.Entity; +namespace web_library.Book.Entity; using Reservation.Entity; [Table("book_copies")] diff --git a/web-library/Api/Book/Model/BookModel.cs b/web-library/Book/Model/BookModel.cs similarity index 95% rename from web-library/Api/Book/Model/BookModel.cs rename to web-library/Book/Model/BookModel.cs index 6fefc88..0b98ed0 100644 --- a/web-library/Api/Book/Model/BookModel.cs +++ b/web-library/Book/Model/BookModel.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.Book.Model; +namespace web_library.Book.Model; public class BookModel { diff --git a/web-library/Api/Book/Repository/BookCopyRepository.cs b/web-library/Book/Repository/BookCopyRepository.cs similarity index 84% rename from web-library/Api/Book/Repository/BookCopyRepository.cs rename to web-library/Book/Repository/BookCopyRepository.cs index 9f7437b..d109ef2 100644 --- a/web-library/Api/Book/Repository/BookCopyRepository.cs +++ b/web-library/Book/Repository/BookCopyRepository.cs @@ -1,7 +1,9 @@ -namespace web_library.Api.Book.Repository; +namespace web_library.Book.Repository; using Entity; using Microsoft.EntityFrameworkCore; using Shared; +using web_library.Book.Entity; + public class BookCopyRepository : IBookCopyRepository { private readonly DataContext _context; @@ -23,7 +25,7 @@ public IEnumerable FindAll() public BookCopy FindByIdOrThrow(int id) { - return _context.BooksCopy.Find(id) ?? throw new NotFoundException("Book copy (" + id +") not found repository"); + return _context.BooksCopy.Find(id) ?? throw new NotFoundException("Book copy (" + id + ") not found repository"); } public void Remove(BookCopy entity) diff --git a/web-library/Api/Book/Repository/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs similarity index 84% rename from web-library/Api/Book/Repository/BookRepository.cs rename to web-library/Book/Repository/BookRepository.cs index de1cf3a..411837c 100644 --- a/web-library/Api/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -1,8 +1,10 @@ -namespace web_library.Api.Book.Repository; +namespace web_library.Book.Repository; using Entity; using Microsoft.EntityFrameworkCore; using Shared; +using web_library.Book.Entity; + public class BookRepository : IBookRepository { private readonly DataContext _context; @@ -19,7 +21,7 @@ public void Add(Book entity) public IEnumerable FindAll() { - return _context.Books.Include(b=>b.Copies).ToList(); + return _context.Books.Include(b => b.Copies).ToList(); } public Book FindByIdOrThrow(int id) diff --git a/web-library/Book/Repository/IBookCopyRepository.cs b/web-library/Book/Repository/IBookCopyRepository.cs new file mode 100644 index 0000000..50ffe95 --- /dev/null +++ b/web-library/Book/Repository/IBookCopyRepository.cs @@ -0,0 +1,7 @@ +using web_library.Book.Entity; + +namespace web_library.Book.Repository; + +public interface IBookCopyRepository : IGenericRepository +{ +} \ No newline at end of file diff --git a/web-library/Api/Book/Repository/IBookRepository.cs b/web-library/Book/Repository/IBookRepository.cs similarity index 60% rename from web-library/Api/Book/Repository/IBookRepository.cs rename to web-library/Book/Repository/IBookRepository.cs index 76534eb..867bd78 100644 --- a/web-library/Api/Book/Repository/IBookRepository.cs +++ b/web-library/Book/Repository/IBookRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Api.Book.Repository; +namespace web_library.Book.Repository; using Entity; +using web_library.Book.Entity; + public interface IBookRepository : IGenericRepository { public void Update(Book book); diff --git a/web-library/Api/Book/Request/CreateBookRequest.cs b/web-library/Book/Request/CreateBookRequest.cs similarity index 93% rename from web-library/Api/Book/Request/CreateBookRequest.cs rename to web-library/Book/Request/CreateBookRequest.cs index 853d8d1..29ba343 100644 --- a/web-library/Api/Book/Request/CreateBookRequest.cs +++ b/web-library/Book/Request/CreateBookRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.Book.Request +namespace web_library.Book.Request { public class CreateBookRequest { @@ -14,7 +14,7 @@ public class CreateBookRequest public CreateBookRequest() { } public CreateBookRequest(string type) { - List isbnList = new() { 9780439023528, 9780747532743, 9780451524935, 9780618260300, 9780141439600 }; + List isbnList = new() { 9780439023528, 9780747532743, 9780451524935, 9780618260300, 9780141439600 }; List titleList = new() { "The Hunger Games", "Harry Potter and the Philosopher's Stone", "1984", "The Hobbit", "Pride and Prejudice" }; List authorList = new() { "Suzanne Collins", "J.K. Rowling", "George Orwell", "J.R.R. Tolkien", "Jane Austen" }; List publisherList = new() { "Scholastic Press", "Bloomsbury", "Harcourt Brace Jovanovich", "Houghton Mifflin", "Penguin Books" }; diff --git a/web-library/Api/Book/Service/BookService.cs b/web-library/Book/Service/BookService.cs similarity index 87% rename from web-library/Api/Book/Service/BookService.cs rename to web-library/Book/Service/BookService.cs index 3c7a2dd..2919ba2 100644 --- a/web-library/Api/Book/Service/BookService.cs +++ b/web-library/Book/Service/BookService.cs @@ -1,9 +1,12 @@ -namespace web_library.Api.Book.Service; +namespace web_library.Book.Service; using Entity; using Newtonsoft.Json; using Repository; using Request; +using web_library.Book.Entity; +using web_library.Book.Repository; +using web_library.Book.Request; public class BookService : IBookService { diff --git a/web-library/Api/Book/Service/IBookService.cs b/web-library/Book/Service/IBookService.cs similarity index 51% rename from web-library/Api/Book/Service/IBookService.cs rename to web-library/Book/Service/IBookService.cs index 8627ee9..9afe3aa 100644 --- a/web-library/Api/Book/Service/IBookService.cs +++ b/web-library/Book/Service/IBookService.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Request; +using web_library.Book.Request; -namespace web_library.Api.Book.Service; +namespace web_library.Book.Service; public interface IBookService { diff --git a/web-library/DataContext.cs b/web-library/DataContext.cs index 4a5d072..4c48f50 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -1,70 +1,61 @@ using Microsoft.EntityFrameworkCore; +namespace web_library; -namespace web_library +public class DataContext : DbContext { - using Api.Book.Entity; - using Api.Genre.Entity; - using Api.User.Entity; - using Api.Reservation.Entity; + protected readonly IConfiguration Configuration; - public class DataContext : DbContext + public DataContext(IConfiguration configuration) { - protected readonly IConfiguration Configuration; - - public DataContext(IConfiguration configuration) - { - Configuration = configuration; - } + Configuration = configuration; + } - protected override void OnConfiguring(DbContextOptionsBuilder options) - { - // connect to postgres with connection string from app settings - options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); - options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); - } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to postgres with connection string from app settings + options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); + options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); + } - protected override void OnModelCreating(ModelBuilder modelBuilder) + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasMany(left => left.Genres) + .WithMany(right => right.Books) + .UsingEntity>( + "book_genres", + j => j.HasOne().WithMany().HasForeignKey("genre_id"), + j => j.HasOne().WithMany().HasForeignKey("book_id") + ); + + modelBuilder.Entity(entity => { - modelBuilder.Entity() - .HasMany(left => left.Genres) - .WithMany(right => right.Books) - .UsingEntity>( - "book_genres", - j => j.HasOne().WithMany().HasForeignKey("genre_id"), - j => j.HasOne().WithMany().HasForeignKey("book_id") - ); + entity.ToTable("users"); + entity.HasIndex(u => u.Email).IsUnique(); - modelBuilder.Entity(entity => - { - entity.ToTable("users"); - entity.HasIndex(u => u.Email).IsUnique(); + entity.HasOne(u => u.UserBasicInfo) + .WithOne(ubi => ubi.User) + .HasForeignKey(ubi => ubi.UserId) + .OnDelete(DeleteBehavior.Cascade); + }); - entity.HasOne(u => u.UserBasicInfo) - .WithOne(ubi => ubi.User) - .HasForeignKey(ubi => ubi.UserId) - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity(entity => - { - entity.ToTable("user_basic_info"); - - entity.Property(ubi => ubi.UserId).IsRequired(); - - entity.HasIndex(ubi => ubi.UserId).IsUnique(); - - }); + modelBuilder.Entity(entity => + { + entity.ToTable("user_basic_info"); - base.OnModelCreating(modelBuilder); - } + entity.Property(ubi => ubi.UserId).IsRequired(); - public DbSet Users { get; set; } + entity.HasIndex(ubi => ubi.UserId).IsUnique(); + }); - public DbSet Books { get; set; } - public DbSet BooksCopy { get; set; } - public DbSet Genres { get; set; } - public DbSet Reservations { get; set; } - public DbSet UserBasicInfos { get; set; } + base.OnModelCreating(modelBuilder); } + + public DbSet Users { get; set; } + public DbSet Books { get; set; } + public DbSet BooksCopy { get; set; } + public DbSet Genres { get; set; } + public DbSet Reservations { get; set; } + public DbSet UserBasicInfos { get; set; } } \ No newline at end of file diff --git a/web-library/Api/Genre/Entity/Genre.cs b/web-library/Genre/Entity/Genre.cs similarity index 85% rename from web-library/Api/Genre/Entity/Genre.cs rename to web-library/Genre/Entity/Genre.cs index 33767bf..abcfbb3 100644 --- a/web-library/Api/Genre/Entity/Genre.cs +++ b/web-library/Genre/Entity/Genre.cs @@ -1,8 +1,10 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Genre.Entity; +namespace web_library.Genre.Entity; using Book.Entity; +using web_library.Book.Entity; + [Table("genres")] public class Genre { diff --git a/web-library/Program.cs b/web-library/Program.cs index dc5e354..d7bbe51 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -1,14 +1,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; using web_library; -using web_library.Api.Book.Repository; -using web_library.Api.Book.Service; -using web_library.Api.Book.DataProvider; -using web_library.Api.User.Repository; -using web_library.Api.User.Service; -using web_library.Api.Reservation.Repostiory; -using web_library.Api.Reservation.Service; -using web_library.Api.Reservation.DataProvider; +using web_library.Book.DataProvider; +using web_library.Book.Repository; +using web_library.Book.Service; +using web_library.User.Repository; +using web_library.User.Service; +using web_library.Reservation.DataProvider; +using web_library.Reservation.Repostiory; +using web_library.Reservation.Service; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => diff --git a/web-library/Api/Reservation/Controller/ReservationController.cs b/web-library/Reservation/Controller/ReservationController.cs similarity index 95% rename from web-library/Api/Reservation/Controller/ReservationController.cs rename to web-library/Reservation/Controller/ReservationController.cs index 12d6d63..2ab369c 100644 --- a/web-library/Api/Reservation/Controller/ReservationController.cs +++ b/web-library/Reservation/Controller/ReservationController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace web_library.Api.Reservation.Controller +namespace web_library.Reservation.Controller { using DataProvider; using Request; diff --git a/web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs b/web-library/Reservation/DataProvider/IReservationDataProvider.cs similarity index 53% rename from web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs rename to web-library/Reservation/DataProvider/IReservationDataProvider.cs index f5a08e9..d3ff166 100644 --- a/web-library/Api/Reservation/DataProvider/IReservationDataProvider.cs +++ b/web-library/Reservation/DataProvider/IReservationDataProvider.cs @@ -1,6 +1,6 @@ -using web_library.Api.Reservation.Model; +using web_library.Reservation.Model; -namespace web_library.Api.Reservation.DataProvider +namespace web_library.Reservation.DataProvider { public interface IReservationDataProvider { diff --git a/web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs b/web-library/Reservation/DataProvider/ReservationDataProvider.cs similarity index 85% rename from web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs rename to web-library/Reservation/DataProvider/ReservationDataProvider.cs index e4ec9ca..0975588 100644 --- a/web-library/Api/Reservation/DataProvider/ReservationDataProvider.cs +++ b/web-library/Reservation/DataProvider/ReservationDataProvider.cs @@ -1,12 +1,10 @@ -using web_library.Api.Reservation.Model; -using web_library.Api.Reservation.Repostiory; - -namespace web_library.Api.Reservation.DataProvider; +namespace web_library.Reservation.DataProvider; using Entity; using System.Security.Policy; -using web_library.Api.Book.Entity; -using web_library.Api.Book.Repository; +using web_library.Book.Repository; +using web_library.Reservation.Model; +using web_library.Reservation.Repostiory; public class ReservationDataProvider : IReservationDataProvider { diff --git a/web-library/Api/Reservation/Entity/Reservation.cs b/web-library/Reservation/Entity/Reservation.cs similarity index 88% rename from web-library/Api/Reservation/Entity/Reservation.cs rename to web-library/Reservation/Entity/Reservation.cs index a324137..363a76f 100644 --- a/web-library/Api/Reservation/Entity/Reservation.cs +++ b/web-library/Reservation/Entity/Reservation.cs @@ -1,9 +1,11 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.Reservation.Entity; +namespace web_library.Reservation.Entity; using System.ComponentModel.DataAnnotations; using Book.Entity; +using web_library.Book.Entity; + [Table("reservations")] public class Reservation { @@ -22,7 +24,7 @@ public class Reservation public BookCopy bookCopy { get; set; } = null!; - public Reservation() {} + public Reservation() { } public Reservation(DateOnly reservationStartDate, DateOnly reservationEndDate, int bookCopyId) { diff --git a/web-library/Api/Reservation/Model/ReservationModel.cs b/web-library/Reservation/Model/ReservationModel.cs similarity index 88% rename from web-library/Api/Reservation/Model/ReservationModel.cs rename to web-library/Reservation/Model/ReservationModel.cs index 935c8b5..965cbd8 100644 --- a/web-library/Api/Reservation/Model/ReservationModel.cs +++ b/web-library/Reservation/Model/ReservationModel.cs @@ -1,6 +1,6 @@ -using web_library.Api.Book.Entity; +using web_library.Book.Entity; -namespace web_library.Api.Reservation.Model +namespace web_library.Reservation.Model { public class ReservationModel { @@ -12,7 +12,7 @@ public class ReservationModel public string Publisher { get; set; } public DateOnly Publication_date { get; set; } public int BookCopyId { get; set; } - public DateOnly StartDate { get; set; } + public DateOnly StartDate { get; set; } public DateOnly EndDate { get; set; } public ReservationModel() { } diff --git a/web-library/Api/Reservation/Repostiory/IReservationRepository.cs b/web-library/Reservation/Repostiory/IReservationRepository.cs similarity index 54% rename from web-library/Api/Reservation/Repostiory/IReservationRepository.cs rename to web-library/Reservation/Repostiory/IReservationRepository.cs index 006d719..39a2fcc 100644 --- a/web-library/Api/Reservation/Repostiory/IReservationRepository.cs +++ b/web-library/Reservation/Repostiory/IReservationRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Api.Reservation.Repostiory +namespace web_library.Reservation.Repostiory { using Entity; + using web_library.Reservation.Entity; + public interface IReservationRepository : IGenericRepository { } diff --git a/web-library/Api/Reservation/Repostiory/ReservationRepository.cs b/web-library/Reservation/Repostiory/ReservationRepository.cs similarity index 91% rename from web-library/Api/Reservation/Repostiory/ReservationRepository.cs rename to web-library/Reservation/Repostiory/ReservationRepository.cs index 1ef827e..868f32c 100644 --- a/web-library/Api/Reservation/Repostiory/ReservationRepository.cs +++ b/web-library/Reservation/Repostiory/ReservationRepository.cs @@ -1,9 +1,10 @@ using Microsoft.EntityFrameworkCore; -namespace web_library.Api.Reservation.Repostiory +namespace web_library.Reservation.Repostiory { using Entity; using Shared; + using web_library.Reservation.Entity; public class ReservationRepository : IReservationRepository { diff --git a/web-library/Api/Reservation/Request/CreateReservationRequest.cs b/web-library/Reservation/Request/CreateReservationRequest.cs similarity index 86% rename from web-library/Api/Reservation/Request/CreateReservationRequest.cs rename to web-library/Reservation/Request/CreateReservationRequest.cs index 280f2e7..dd06841 100644 --- a/web-library/Api/Reservation/Request/CreateReservationRequest.cs +++ b/web-library/Reservation/Request/CreateReservationRequest.cs @@ -1,5 +1,4 @@ - -namespace web_library.Api.Reservation.Request; +namespace web_library.Reservation.Request; public class CreateReservationRequest { public int book_copy_id { get; set; } diff --git a/web-library/Api/Reservation/Service/IReservationService.cs b/web-library/Reservation/Service/IReservationService.cs similarity index 57% rename from web-library/Api/Reservation/Service/IReservationService.cs rename to web-library/Reservation/Service/IReservationService.cs index 389d8a8..605996d 100644 --- a/web-library/Api/Reservation/Service/IReservationService.cs +++ b/web-library/Reservation/Service/IReservationService.cs @@ -1,6 +1,6 @@ -using web_library.Api.Reservation.Request; +using web_library.Reservation.Request; -namespace web_library.Api.Reservation.Service +namespace web_library.Reservation.Service { public interface IReservationService { diff --git a/web-library/Api/Reservation/Service/ReservationService.cs b/web-library/Reservation/Service/ReservationService.cs similarity index 73% rename from web-library/Api/Reservation/Service/ReservationService.cs rename to web-library/Reservation/Service/ReservationService.cs index 5909726..396f4a3 100644 --- a/web-library/Api/Reservation/Service/ReservationService.cs +++ b/web-library/Reservation/Service/ReservationService.cs @@ -1,9 +1,15 @@ -namespace web_library.Api.Reservation.Service; +namespace web_library.Reservation.Service; using Book.Entity; using Book.Repository; using Entity; using Repostiory; using Request; +using web_library.Book.Entity; +using web_library.Book.Repository; +using web_library.Reservation.Entity; +using web_library.Reservation.Repostiory; +using web_library.Reservation.Request; + public class ReservationService : IReservationService { private readonly IReservationRepository _reservationRepository; @@ -18,7 +24,7 @@ public ReservationService(IReservationRepository reservationRepository, IBookCop public void createReservation(CreateReservationRequest request) { BookCopy bookCopy = _bookCopyRepository.FindByIdOrThrow(request.book_copy_id); - Reservation reservation = new(request.reservation_start_date, request.reservation_end_date,request.book_copy_id); + Reservation reservation = new(request.reservation_start_date, request.reservation_end_date, request.book_copy_id); _reservationRepository.Add(reservation); } } diff --git a/web-library/Api/User/Controller/AuthController.cs b/web-library/User/Controller/AuthController.cs similarity index 89% rename from web-library/Api/User/Controller/AuthController.cs rename to web-library/User/Controller/AuthController.cs index f2f4a8a..12294a7 100644 --- a/web-library/Api/User/Controller/AuthController.cs +++ b/web-library/User/Controller/AuthController.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Authorization; -namespace web_library.Api.User.Controller; +namespace web_library.User.Controller; using Microsoft.AspNetCore.Mvc; -using web_library.Api.User.Request; -using web_library.Api.User.Service; +using web_library.User.Request; +using web_library.User.Service; [ApiController] [Route("api/auth")] diff --git a/web-library/Api/User/Entity/User.cs b/web-library/User/Entity/User.cs similarity index 92% rename from web-library/Api/User/Entity/User.cs rename to web-library/User/Entity/User.cs index 562d724..6c51c86 100644 --- a/web-library/Api/User/Entity/User.cs +++ b/web-library/User/Entity/User.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.User.Entity; +namespace web_library.User.Entity; [Table("users")] public class User diff --git a/web-library/Api/User/Entity/UserBasicInfo.cs b/web-library/User/Entity/UserBasicInfo.cs similarity index 96% rename from web-library/Api/User/Entity/UserBasicInfo.cs rename to web-library/User/Entity/UserBasicInfo.cs index 9907f79..83c32a6 100644 --- a/web-library/Api/User/Entity/UserBasicInfo.cs +++ b/web-library/User/Entity/UserBasicInfo.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace web_library.Api.User.Entity; +namespace web_library.User.Entity; [Table("user_basic_info")] public class UserBasicInfo diff --git a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs b/web-library/User/Repository/IUserBasicInfoRepository.cs similarity index 66% rename from web-library/Api/User/Repository/IUserBasicInfoRepository.cs rename to web-library/User/Repository/IUserBasicInfoRepository.cs index 94ab817..5ca44ca 100644 --- a/web-library/Api/User/Repository/IUserBasicInfoRepository.cs +++ b/web-library/User/Repository/IUserBasicInfoRepository.cs @@ -1,5 +1,7 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; + public interface IUserBasicInfoRepository { void Add(UserBasicInfo userBasicInfo); diff --git a/web-library/Api/User/Repository/IUserRepository.cs b/web-library/User/Repository/IUserRepository.cs similarity index 61% rename from web-library/Api/User/Repository/IUserRepository.cs rename to web-library/User/Repository/IUserRepository.cs index 708e44f..e61248a 100644 --- a/web-library/Api/User/Repository/IUserRepository.cs +++ b/web-library/User/Repository/IUserRepository.cs @@ -1,6 +1,6 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public interface IUserRepository : IGenericRepository { diff --git a/web-library/Api/User/Repository/UserBasicInfoRepository.cs b/web-library/User/Repository/UserBasicInfoRepository.cs similarity index 85% rename from web-library/Api/User/Repository/UserBasicInfoRepository.cs rename to web-library/User/Repository/UserBasicInfoRepository.cs index 2f34828..4c5374d 100644 --- a/web-library/Api/User/Repository/UserBasicInfoRepository.cs +++ b/web-library/User/Repository/UserBasicInfoRepository.cs @@ -1,6 +1,6 @@ -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; -using web_library.Api.User.Entity; +using web_library.User.Entity; public class UserBasicInfoRepository : IUserBasicInfoRepository { diff --git a/web-library/Api/User/Repository/UserRepository.cs b/web-library/User/Repository/UserRepository.cs similarity index 92% rename from web-library/Api/User/Repository/UserRepository.cs rename to web-library/User/Repository/UserRepository.cs index b081d51..e090176 100644 --- a/web-library/Api/User/Repository/UserRepository.cs +++ b/web-library/User/Repository/UserRepository.cs @@ -1,7 +1,9 @@ using web_library.Shared; -namespace web_library.Api.User.Repository; +namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; + public class UserRepository : IUserRepository { private readonly DataContext _dbContext; diff --git a/web-library/Api/User/Request/LoginUserRequest.cs b/web-library/User/Request/LoginUserRequest.cs similarity index 76% rename from web-library/Api/User/Request/LoginUserRequest.cs rename to web-library/User/Request/LoginUserRequest.cs index 8853c67..54ed1e4 100644 --- a/web-library/Api/User/Request/LoginUserRequest.cs +++ b/web-library/User/Request/LoginUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.User.Request +namespace web_library.User.Request { public class LoginUserRequest { diff --git a/web-library/Api/User/Request/RegisterUserRequest.cs b/web-library/User/Request/RegisterUserRequest.cs similarity index 87% rename from web-library/Api/User/Request/RegisterUserRequest.cs rename to web-library/User/Request/RegisterUserRequest.cs index 7618213..ff7d4cf 100644 --- a/web-library/Api/User/Request/RegisterUserRequest.cs +++ b/web-library/User/Request/RegisterUserRequest.cs @@ -1,4 +1,4 @@ -namespace web_library.Api.User.Request; +namespace web_library.User.Request; public class RegisterUserRequest { diff --git a/web-library/Api/User/Service/AuthService.cs b/web-library/User/Service/AuthService.cs similarity index 96% rename from web-library/Api/User/Service/AuthService.cs rename to web-library/User/Service/AuthService.cs index 6a8a976..bad45fd 100644 --- a/web-library/Api/User/Service/AuthService.cs +++ b/web-library/User/Service/AuthService.cs @@ -5,10 +5,13 @@ using System.Security.Cryptography; using System.Text; -namespace web_library.Api.User.Service; +namespace web_library.User.Service; using Entity; using Repository; using Request; +using web_library.User.Entity; +using web_library.User.Repository; +using web_library.User.Request; public class AuthService : IAuthService { diff --git a/web-library/Api/User/Service/IAuthService.cs b/web-library/User/Service/IAuthService.cs similarity index 73% rename from web-library/Api/User/Service/IAuthService.cs rename to web-library/User/Service/IAuthService.cs index d52185f..fbe4e80 100644 --- a/web-library/Api/User/Service/IAuthService.cs +++ b/web-library/User/Service/IAuthService.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; -using web_library.Api.User.Request; +using web_library.User.Request; -namespace web_library.Api.User.Service +namespace web_library.User.Service { public interface IAuthService { diff --git a/web-library/User/Service/IUserService.cs b/web-library/User/Service/IUserService.cs new file mode 100644 index 0000000..d9facb2 --- /dev/null +++ b/web-library/User/Service/IUserService.cs @@ -0,0 +1,5 @@ +namespace web_library.User.Service; + +public interface IUserService +{ +} \ No newline at end of file diff --git a/web-library/Api/User/Service/UserService.cs b/web-library/User/Service/UserService.cs similarity index 72% rename from web-library/Api/User/Service/UserService.cs rename to web-library/User/Service/UserService.cs index 0d977ab..ba1b9de 100644 --- a/web-library/Api/User/Service/UserService.cs +++ b/web-library/User/Service/UserService.cs @@ -1,6 +1,6 @@ -using web_library.Api.User.Repository; +using web_library.User.Repository; -namespace web_library.Api.User.Service; +namespace web_library.User.Service; public class UserService : IUserService { From 64813cde6cd9fc6f7ea56977487692ef089a6a61 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 07:39:37 +0100 Subject: [PATCH 11/17] end date set to +30 days from start reservation --- web-library/Reservation/Request/CreateReservationRequest.cs | 6 +++--- web-library/Reservation/Service/ReservationService.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web-library/Reservation/Request/CreateReservationRequest.cs b/web-library/Reservation/Request/CreateReservationRequest.cs index dd06841..48b98fd 100644 --- a/web-library/Reservation/Request/CreateReservationRequest.cs +++ b/web-library/Reservation/Request/CreateReservationRequest.cs @@ -1,12 +1,12 @@ -namespace web_library.Reservation.Request; +using System.Text.Json.Serialization; + +namespace web_library.Reservation.Request; public class CreateReservationRequest { public int book_copy_id { get; set; } public DateOnly reservation_start_date { get; set; } - public DateOnly reservation_end_date { get; set; } public CreateReservationRequest() { reservation_start_date = new(); - reservation_end_date = new(); } } diff --git a/web-library/Reservation/Service/ReservationService.cs b/web-library/Reservation/Service/ReservationService.cs index 396f4a3..3b55bf8 100644 --- a/web-library/Reservation/Service/ReservationService.cs +++ b/web-library/Reservation/Service/ReservationService.cs @@ -24,7 +24,7 @@ public ReservationService(IReservationRepository reservationRepository, IBookCop public void createReservation(CreateReservationRequest request) { BookCopy bookCopy = _bookCopyRepository.FindByIdOrThrow(request.book_copy_id); - Reservation reservation = new(request.reservation_start_date, request.reservation_end_date, request.book_copy_id); + Reservation reservation = new(request.reservation_start_date, request.reservation_start_date.AddDays(30), request.book_copy_id); _reservationRepository.Add(reservation); } } From f41ac8130c9d1867c9fcff34f61ccf49e2ab481e Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 07:46:10 +0100 Subject: [PATCH 12/17] test1 --- ...231130154456_BookAndCopyEntity.Designer.cs | 114 ------- .../20231130154456_BookAndCopyEntity.cs | 69 ----- .../20231201212648_genreEntity.Designer.cs | 163 ---------- .../Migrations/20231201212648_genreEntity.cs | 67 ---- ...627_userAndUserBasicInfoEntity.Designer.cs | 247 --------------- ...231202031627_userAndUserBasicInfoEntity.cs | 74 ----- ...231204004614_reservationEntity.Designer.cs | 292 ------------------ .../20231204004614_reservationEntity.cs | 50 --- web-library/web-library.csproj | 4 + 9 files changed, 4 insertions(+), 1076 deletions(-) delete mode 100644 web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs delete mode 100644 web-library/Migrations/20231130154456_BookAndCopyEntity.cs delete mode 100644 web-library/Migrations/20231201212648_genreEntity.Designer.cs delete mode 100644 web-library/Migrations/20231201212648_genreEntity.cs delete mode 100644 web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs delete mode 100644 web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs delete mode 100644 web-library/Migrations/20231204004614_reservationEntity.Designer.cs delete mode 100644 web-library/Migrations/20231204004614_reservationEntity.cs diff --git a/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs b/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs deleted file mode 100644 index eff212e..0000000 --- a/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231130154456_BookAndCopyEntity")] - partial class BookAndCopyEntity - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231130154456_BookAndCopyEntity.cs b/web-library/Migrations/20231130154456_BookAndCopyEntity.cs deleted file mode 100644 index ded8d00..0000000 --- a/web-library/Migrations/20231130154456_BookAndCopyEntity.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class BookAndCopyEntity : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "books", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - isbn = table.Column(type: "text", nullable: false), - title = table.Column(type: "text", nullable: false), - author = table.Column(type: "text", nullable: false), - publisher = table.Column(type: "text", nullable: false), - publication_date = table.Column(type: "date", nullable: false), - location = table.Column(type: "text", nullable: false), - description = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_books", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "book_copies", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - book_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_book_copies", x => x.id); - table.ForeignKey( - name: "FK_book_copies_books_book_id", - column: x => x.book_id, - principalTable: "books", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_book_copies_book_id", - table: "book_copies", - column: "book_id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "book_copies"); - - migrationBuilder.DropTable( - name: "books"); - } - } -} diff --git a/web-library/Migrations/20231201212648_genreEntity.Designer.cs b/web-library/Migrations/20231201212648_genreEntity.Designer.cs deleted file mode 100644 index a8f9899..0000000 --- a/web-library/Migrations/20231201212648_genreEntity.Designer.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231201212648_genreEntity")] - partial class genreEntity - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("book_genres", b => - { - b.Property("book_id") - .HasColumnType("integer"); - - b.Property("genre_id") - .HasColumnType("integer"); - - b.HasKey("book_id", "genre_id"); - - b.HasIndex("genre_id"); - - b.ToTable("book_genres"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("book_genres", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("book_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("genre_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231201212648_genreEntity.cs b/web-library/Migrations/20231201212648_genreEntity.cs deleted file mode 100644 index 7c6a395..0000000 --- a/web-library/Migrations/20231201212648_genreEntity.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class genreEntity : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "genres", - 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_genres", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "book_genres", - columns: table => new - { - book_id = table.Column(type: "integer", nullable: false), - genre_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_book_genres", x => new { x.book_id, x.genre_id }); - table.ForeignKey( - name: "FK_book_genres_books_book_id", - column: x => x.book_id, - principalTable: "books", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_book_genres_genres_genre_id", - column: x => x.genre_id, - principalTable: "genres", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_book_genres_genre_id", - table: "book_genres", - column: "genre_id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "book_genres"); - - migrationBuilder.DropTable( - name: "genres"); - } - } -} diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs deleted file mode 100644 index 768949e..0000000 --- a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs +++ /dev/null @@ -1,247 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231202031627_userAndUserBasicInfoEntity")] - partial class userAndUserBasicInfoEntity - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("book_genres", b => - { - b.Property("book_id") - .HasColumnType("integer"); - - b.Property("genre_id") - .HasColumnType("integer"); - - b.HasKey("book_id", "genre_id"); - - b.HasIndex("genre_id"); - - b.ToTable("book_genres"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("book_genres", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("book_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("genre_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs deleted file mode 100644 index 5e8fc5c..0000000 --- a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class userAndUserBasicInfoEntity : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "users", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - email = table.Column(type: "text", nullable: false), - password = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_users", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "user_basic_info", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - user_id = table.Column(type: "integer", nullable: false), - first_name = table.Column(type: "text", nullable: false), - last_name = table.Column(type: "text", nullable: false), - phone_number = table.Column(type: "text", nullable: false), - address = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_user_basic_info", x => x.id); - table.ForeignKey( - name: "FK_user_basic_info_users_user_id", - column: x => x.user_id, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_user_basic_info_user_id", - table: "user_basic_info", - column: "user_id", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_users_email", - table: "users", - column: "email", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "user_basic_info"); - - migrationBuilder.DropTable( - name: "users"); - } - } -} diff --git a/web-library/Migrations/20231204004614_reservationEntity.Designer.cs b/web-library/Migrations/20231204004614_reservationEntity.Designer.cs deleted file mode 100644 index deff0e0..0000000 --- a/web-library/Migrations/20231204004614_reservationEntity.Designer.cs +++ /dev/null @@ -1,292 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231204004614_reservationEntity")] - partial class reservationEntity - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("book_genres", b => - { - b.Property("book_id") - .HasColumnType("integer"); - - b.Property("genre_id") - .HasColumnType("integer"); - - b.HasKey("book_id", "genre_id"); - - b.HasIndex("genre_id"); - - b.ToTable("book_genres"); - }); - - modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Api.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("bookCopyId") - .HasColumnType("integer") - .HasColumnName("book_copy_id"); - - b.Property("reservationEndDate") - .HasColumnType("date") - .HasColumnName("reservation_end_date"); - - b.Property("reservationStartDate") - .HasColumnType("date") - .HasColumnName("reservation_start_date"); - - b.HasKey("Id"); - - b.HasIndex("bookCopyId") - .IsUnique(); - - b.ToTable("reservations"); - }); - - modelBuilder.Entity("web_library.Api.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("book_genres", b => - { - b.HasOne("web_library.Api.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("book_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Api.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("genre_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Api.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.Api.Reservation.Entity.Reservation", b => - { - b.HasOne("web_library.Api.Book.Entity.BookCopy", "bookCopy") - .WithOne("reservation") - .HasForeignKey("web_library.Api.Reservation.Entity.Reservation", "bookCopyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("bookCopy"); - }); - - modelBuilder.Entity("web_library.Api.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.Api.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.Api.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Api.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.Api.Book.Entity.BookCopy", b => - { - b.Navigation("reservation"); - }); - - modelBuilder.Entity("web_library.Api.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231204004614_reservationEntity.cs b/web-library/Migrations/20231204004614_reservationEntity.cs deleted file mode 100644 index 41d71cf..0000000 --- a/web-library/Migrations/20231204004614_reservationEntity.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class reservationEntity : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "reservations", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - reservation_start_date = table.Column(type: "date", nullable: false), - reservation_end_date = table.Column(type: "date", nullable: false), - book_copy_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_reservations", x => x.id); - table.ForeignKey( - name: "FK_reservations_book_copies_book_copy_id", - column: x => x.book_copy_id, - principalTable: "book_copies", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_reservations_book_copy_id", - table: "reservations", - column: "book_copy_id", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "reservations"); - } - } -} diff --git a/web-library/web-library.csproj b/web-library/web-library.csproj index 6f912b3..a72a77b 100644 --- a/web-library/web-library.csproj +++ b/web-library/web-library.csproj @@ -23,4 +23,8 @@ + + + + From 63189b950573ae31572656d55d6b866c6da55826 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 07:53:04 +0100 Subject: [PATCH 13/17] test2 --- .../20231204020115_Roles.Designer.cs | 245 --------------- .../Migrations/20231204020115_Roles.cs | 131 -------- .../20231204020308_InsertRoles.Designer.cs | 283 ------------------ .../Migrations/20231204020308_InsertRoles.cs | 45 --- .../Migrations/DataContextModelSnapshot.cs | 280 ----------------- 5 files changed, 984 deletions(-) delete mode 100644 web-library/Migrations/20231204020115_Roles.Designer.cs delete mode 100644 web-library/Migrations/20231204020115_Roles.cs delete mode 100644 web-library/Migrations/20231204020308_InsertRoles.Designer.cs delete mode 100644 web-library/Migrations/20231204020308_InsertRoles.cs delete mode 100644 web-library/Migrations/DataContextModelSnapshot.cs diff --git a/web-library/Migrations/20231204020115_Roles.Designer.cs b/web-library/Migrations/20231204020115_Roles.Designer.cs deleted file mode 100644 index 717fa9d..0000000 --- a/web-library/Migrations/20231204020115_Roles.Designer.cs +++ /dev/null @@ -1,245 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - partial class userAndUserBasicInfoEntity - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("book_genres", b => - { - b.Property("book_id") - .HasColumnType("integer"); - - b.Property("genre_id") - .HasColumnType("integer"); - - b.HasKey("book_id", "genre_id"); - - b.HasIndex("genre_id"); - - b.ToTable("book_genres"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("book_genres", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("book_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("genre_id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231204020115_Roles.cs b/web-library/Migrations/20231204020115_Roles.cs deleted file mode 100644 index aeddaa2..0000000 --- a/web-library/Migrations/20231204020115_Roles.cs +++ /dev/null @@ -1,131 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class Roles : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "book_genres"); - - migrationBuilder.AddColumn( - name: "role_id", - table: "users", - type: "integer", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "BookGenre", - columns: table => new - { - BooksId = table.Column(type: "integer", nullable: false), - GenresId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_BookGenre", x => new { x.BooksId, x.GenresId }); - table.ForeignKey( - name: "FK_BookGenre_books_BooksId", - column: x => x.BooksId, - principalTable: "books", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_BookGenre_genres_GenresId", - column: x => x.GenresId, - principalTable: "genres", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "roles", - 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_roles", x => x.id); - }); - - migrationBuilder.CreateIndex( - name: "IX_users_role_id", - table: "users", - column: "role_id"); - - migrationBuilder.CreateIndex( - name: "IX_BookGenre_GenresId", - table: "BookGenre", - column: "GenresId"); - - migrationBuilder.AddForeignKey( - name: "FK_users_roles_role_id", - table: "users", - column: "role_id", - principalTable: "roles", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_users_roles_role_id", - table: "users"); - - migrationBuilder.DropTable( - name: "BookGenre"); - - migrationBuilder.DropTable( - name: "roles"); - - migrationBuilder.DropIndex( - name: "IX_users_role_id", - table: "users"); - - migrationBuilder.DropColumn( - name: "role_id", - table: "users"); - - migrationBuilder.CreateTable( - name: "book_genres", - columns: table => new - { - book_id = table.Column(type: "integer", nullable: false), - genre_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_book_genres", x => new { x.book_id, x.genre_id }); - table.ForeignKey( - name: "FK_book_genres_books_book_id", - column: x => x.book_id, - principalTable: "books", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_book_genres_genres_genre_id", - column: x => x.genre_id, - principalTable: "genres", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_book_genres_genre_id", - table: "book_genres", - column: "genre_id"); - } - } -} diff --git a/web-library/Migrations/20231204020308_InsertRoles.Designer.cs b/web-library/Migrations/20231204020308_InsertRoles.Designer.cs deleted file mode 100644 index a6e1b0d..0000000 --- a/web-library/Migrations/20231204020308_InsertRoles.Designer.cs +++ /dev/null @@ -1,283 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20231204020308_InsertRoles")] - partial class InsertRoles - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("BookGenre", b => - { - b.Property("BooksId") - .HasColumnType("integer"); - - b.Property("GenresId") - .HasColumnType("integer"); - - b.HasKey("BooksId", "GenresId"); - - b.HasIndex("GenresId"); - - b.ToTable("BookGenre"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.Role.Entity.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.Property("RoleId") - .HasColumnType("integer") - .HasColumnName("role_id"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.HasIndex("RoleId"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("BookGenre", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("BooksId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("GenresId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.HasOne("web_library.Role.Entity.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/web-library/Migrations/20231204020308_InsertRoles.cs b/web-library/Migrations/20231204020308_InsertRoles.cs deleted file mode 100644 index 3e569b4..0000000 --- a/web-library/Migrations/20231204020308_InsertRoles.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace web_library.Migrations -{ - /// - public partial class InsertRoles : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.InsertData( - table: "roles", - columns: new[] { "id", "name" }, - values: new object[,] - { - { 1, "Admin" }, - { 2, "Librarian" }, - { 3, "Client"} - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "roles", - keyColumn: "id", - keyValue: 1); - - migrationBuilder.DeleteData( - table: "roles", - keyColumn: "id", - keyValue: 2 - ); - - migrationBuilder.DeleteData( - table: "roles", - keyColumn: "id", - keyValue: 3 - ); - } - } -} diff --git a/web-library/Migrations/DataContextModelSnapshot.cs b/web-library/Migrations/DataContextModelSnapshot.cs deleted file mode 100644 index 2a61a6f..0000000 --- a/web-library/Migrations/DataContextModelSnapshot.cs +++ /dev/null @@ -1,280 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - partial class DataContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("BookGenre", b => - { - b.Property("BooksId") - .HasColumnType("integer"); - - b.Property("GenresId") - .HasColumnType("integer"); - - b.HasKey("BooksId", "GenresId"); - - b.HasIndex("GenresId"); - - b.ToTable("BookGenre"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.Role.Entity.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.Property("RoleId") - .HasColumnType("integer") - .HasColumnName("role_id"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.HasIndex("RoleId"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("BookGenre", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("BooksId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("GenresId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.HasOne("web_library.Role.Entity.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} From 06a4c46dd60e9ec148454755b5f606d9cd83f3d0 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 07:55:54 +0100 Subject: [PATCH 14/17] add migrations --- ...231130154456_BookAndCopyEntity.Designer.cs | 114 +++++++ .../20231130154456_BookAndCopyEntity.cs | 69 +++++ .../20231201212648_genreEntity.Designer.cs | 163 ++++++++++ .../Migrations/20231201212648_genreEntity.cs | 67 +++++ ...627_userAndUserBasicInfoEntity.Designer.cs | 247 +++++++++++++++ ...231202031627_userAndUserBasicInfoEntity.cs | 74 +++++ .../20231204020115_Roles.Designer.cs | 283 ++++++++++++++++++ .../Migrations/20231204020115_Roles.cs | 131 ++++++++ .../20231204020308_InsertRoles.Designer.cs | 283 ++++++++++++++++++ .../Migrations/20231204020308_InsertRoles.cs | 45 +++ 10 files changed, 1476 insertions(+) create mode 100644 web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs create mode 100644 web-library/Migrations/20231130154456_BookAndCopyEntity.cs create mode 100644 web-library/Migrations/20231201212648_genreEntity.Designer.cs create mode 100644 web-library/Migrations/20231201212648_genreEntity.cs create mode 100644 web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs create mode 100644 web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs create mode 100644 web-library/Migrations/20231204020115_Roles.Designer.cs create mode 100644 web-library/Migrations/20231204020115_Roles.cs create mode 100644 web-library/Migrations/20231204020308_InsertRoles.Designer.cs create mode 100644 web-library/Migrations/20231204020308_InsertRoles.cs diff --git a/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs b/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs new file mode 100644 index 0000000..eff212e --- /dev/null +++ b/web-library/Migrations/20231130154456_BookAndCopyEntity.Designer.cs @@ -0,0 +1,114 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231130154456_BookAndCopyEntity")] + partial class BookAndCopyEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231130154456_BookAndCopyEntity.cs b/web-library/Migrations/20231130154456_BookAndCopyEntity.cs new file mode 100644 index 0000000..ded8d00 --- /dev/null +++ b/web-library/Migrations/20231130154456_BookAndCopyEntity.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class BookAndCopyEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "books", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + isbn = table.Column(type: "text", nullable: false), + title = table.Column(type: "text", nullable: false), + author = table.Column(type: "text", nullable: false), + publisher = table.Column(type: "text", nullable: false), + publication_date = table.Column(type: "date", nullable: false), + location = table.Column(type: "text", nullable: false), + description = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_books", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "book_copies", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + book_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_book_copies", x => x.id); + table.ForeignKey( + name: "FK_book_copies_books_book_id", + column: x => x.book_id, + principalTable: "books", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_book_copies_book_id", + table: "book_copies", + column: "book_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "book_copies"); + + migrationBuilder.DropTable( + name: "books"); + } + } +} diff --git a/web-library/Migrations/20231201212648_genreEntity.Designer.cs b/web-library/Migrations/20231201212648_genreEntity.Designer.cs new file mode 100644 index 0000000..a8f9899 --- /dev/null +++ b/web-library/Migrations/20231201212648_genreEntity.Designer.cs @@ -0,0 +1,163 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231201212648_genreEntity")] + partial class genreEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("book_genres", b => + { + b.Property("book_id") + .HasColumnType("integer"); + + b.Property("genre_id") + .HasColumnType("integer"); + + b.HasKey("book_id", "genre_id"); + + b.HasIndex("genre_id"); + + b.ToTable("book_genres"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + + modelBuilder.Entity("book_genres", b => + { + b.HasOne("web_library.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("book_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("genre_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231201212648_genreEntity.cs b/web-library/Migrations/20231201212648_genreEntity.cs new file mode 100644 index 0000000..7c6a395 --- /dev/null +++ b/web-library/Migrations/20231201212648_genreEntity.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class genreEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "genres", + 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_genres", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "book_genres", + columns: table => new + { + book_id = table.Column(type: "integer", nullable: false), + genre_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_book_genres", x => new { x.book_id, x.genre_id }); + table.ForeignKey( + name: "FK_book_genres_books_book_id", + column: x => x.book_id, + principalTable: "books", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_book_genres_genres_genre_id", + column: x => x.genre_id, + principalTable: "genres", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_book_genres_genre_id", + table: "book_genres", + column: "genre_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "book_genres"); + + migrationBuilder.DropTable( + name: "genres"); + } + } +} diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs new file mode 100644 index 0000000..768949e --- /dev/null +++ b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs @@ -0,0 +1,247 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231202031627_userAndUserBasicInfoEntity")] + partial class userAndUserBasicInfoEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("book_genres", b => + { + b.Property("book_id") + .HasColumnType("integer"); + + b.Property("genre_id") + .HasColumnType("integer"); + + b.HasKey("book_id", "genre_id"); + + b.HasIndex("genre_id"); + + b.ToTable("book_genres"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text") + .HasColumnName("password"); + + b.HasKey("Id"); + + b.HasIndex("Email") + .IsUnique(); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text") + .HasColumnName("address"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text") + .HasColumnName("phone_number"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_basic_info", (string)null); + }); + + modelBuilder.Entity("book_genres", b => + { + b.HasOne("web_library.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("book_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("genre_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.HasOne("web_library.User.Entity.User", "User") + .WithOne("UserBasicInfo") + .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Navigation("UserBasicInfo"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs new file mode 100644 index 0000000..5e8fc5c --- /dev/null +++ b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.cs @@ -0,0 +1,74 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class userAndUserBasicInfoEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "users", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + email = table.Column(type: "text", nullable: false), + password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_users", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "user_basic_info", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + user_id = table.Column(type: "integer", nullable: false), + first_name = table.Column(type: "text", nullable: false), + last_name = table.Column(type: "text", nullable: false), + phone_number = table.Column(type: "text", nullable: false), + address = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_basic_info", x => x.id); + table.ForeignKey( + name: "FK_user_basic_info_users_user_id", + column: x => x.user_id, + principalTable: "users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_user_basic_info_user_id", + table: "user_basic_info", + column: "user_id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_users_email", + table: "users", + column: "email", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "user_basic_info"); + + migrationBuilder.DropTable( + name: "users"); + } + } +} diff --git a/web-library/Migrations/20231204020115_Roles.Designer.cs b/web-library/Migrations/20231204020115_Roles.Designer.cs new file mode 100644 index 0000000..e744fdc --- /dev/null +++ b/web-library/Migrations/20231204020115_Roles.Designer.cs @@ -0,0 +1,283 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231204020115_Roles")] + partial class Roles + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("BookGenre", b => + { + b.Property("BooksId") + .HasColumnType("integer"); + + b.Property("GenresId") + .HasColumnType("integer"); + + b.HasKey("BooksId", "GenresId"); + + b.HasIndex("GenresId"); + + b.ToTable("BookGenre"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + + modelBuilder.Entity("web_library.Role.Entity.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("roles", (string)null); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text") + .HasColumnName("password"); + + b.Property("RoleId") + .HasColumnType("integer") + .HasColumnName("role_id"); + + b.HasKey("Id"); + + b.HasIndex("Email") + .IsUnique(); + + b.HasIndex("RoleId"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text") + .HasColumnName("address"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text") + .HasColumnName("phone_number"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_basic_info", (string)null); + }); + + modelBuilder.Entity("BookGenre", b => + { + b.HasOne("web_library.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("BooksId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("GenresId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.HasOne("web_library.Role.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.HasOne("web_library.User.Entity.User", "User") + .WithOne("UserBasicInfo") + .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Navigation("UserBasicInfo"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231204020115_Roles.cs b/web-library/Migrations/20231204020115_Roles.cs new file mode 100644 index 0000000..aeddaa2 --- /dev/null +++ b/web-library/Migrations/20231204020115_Roles.cs @@ -0,0 +1,131 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class Roles : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "book_genres"); + + migrationBuilder.AddColumn( + name: "role_id", + table: "users", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "BookGenre", + columns: table => new + { + BooksId = table.Column(type: "integer", nullable: false), + GenresId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BookGenre", x => new { x.BooksId, x.GenresId }); + table.ForeignKey( + name: "FK_BookGenre_books_BooksId", + column: x => x.BooksId, + principalTable: "books", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_BookGenre_genres_GenresId", + column: x => x.GenresId, + principalTable: "genres", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "roles", + 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_roles", x => x.id); + }); + + migrationBuilder.CreateIndex( + name: "IX_users_role_id", + table: "users", + column: "role_id"); + + migrationBuilder.CreateIndex( + name: "IX_BookGenre_GenresId", + table: "BookGenre", + column: "GenresId"); + + migrationBuilder.AddForeignKey( + name: "FK_users_roles_role_id", + table: "users", + column: "role_id", + principalTable: "roles", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_users_roles_role_id", + table: "users"); + + migrationBuilder.DropTable( + name: "BookGenre"); + + migrationBuilder.DropTable( + name: "roles"); + + migrationBuilder.DropIndex( + name: "IX_users_role_id", + table: "users"); + + migrationBuilder.DropColumn( + name: "role_id", + table: "users"); + + migrationBuilder.CreateTable( + name: "book_genres", + columns: table => new + { + book_id = table.Column(type: "integer", nullable: false), + genre_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_book_genres", x => new { x.book_id, x.genre_id }); + table.ForeignKey( + name: "FK_book_genres_books_book_id", + column: x => x.book_id, + principalTable: "books", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_book_genres_genres_genre_id", + column: x => x.genre_id, + principalTable: "genres", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_book_genres_genre_id", + table: "book_genres", + column: "genre_id"); + } + } +} diff --git a/web-library/Migrations/20231204020308_InsertRoles.Designer.cs b/web-library/Migrations/20231204020308_InsertRoles.Designer.cs new file mode 100644 index 0000000..a6e1b0d --- /dev/null +++ b/web-library/Migrations/20231204020308_InsertRoles.Designer.cs @@ -0,0 +1,283 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using web_library; + +#nullable disable + +namespace web_library.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20231204020308_InsertRoles")] + partial class InsertRoles + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("BookGenre", b => + { + b.Property("BooksId") + .HasColumnType("integer"); + + b.Property("GenresId") + .HasColumnType("integer"); + + b.HasKey("BooksId", "GenresId"); + + b.HasIndex("GenresId"); + + b.ToTable("BookGenre"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text") + .HasColumnName("author"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("text") + .HasColumnName("isbn"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text") + .HasColumnName("location"); + + b.Property("Publication_date") + .HasColumnType("date") + .HasColumnName("publication_date"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text") + .HasColumnName("publisher"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.HasKey("Id"); + + b.ToTable("books"); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BookId") + .HasColumnType("integer") + .HasColumnName("book_id"); + + b.HasKey("Id"); + + b.HasIndex("BookId"); + + b.ToTable("book_copies"); + }); + + modelBuilder.Entity("web_library.Genre.Entity.Genre", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("genres"); + }); + + modelBuilder.Entity("web_library.Role.Entity.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id"); + + b.ToTable("roles", (string)null); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text") + .HasColumnName("password"); + + b.Property("RoleId") + .HasColumnType("integer") + .HasColumnName("role_id"); + + b.HasKey("Id"); + + b.HasIndex("Email") + .IsUnique(); + + b.HasIndex("RoleId"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text") + .HasColumnName("address"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text") + .HasColumnName("phone_number"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("user_basic_info", (string)null); + }); + + modelBuilder.Entity("BookGenre", b => + { + b.HasOne("web_library.Book.Entity.Book", null) + .WithMany() + .HasForeignKey("BooksId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("web_library.Genre.Entity.Genre", null) + .WithMany() + .HasForeignKey("GenresId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => + { + b.HasOne("web_library.Book.Entity.Book", "Book") + .WithMany("Copies") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.HasOne("web_library.Role.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => + { + b.HasOne("web_library.User.Entity.User", "User") + .WithOne("UserBasicInfo") + .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("web_library.Book.Entity.Book", b => + { + b.Navigation("Copies"); + }); + + modelBuilder.Entity("web_library.User.Entity.User", b => + { + b.Navigation("UserBasicInfo"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/web-library/Migrations/20231204020308_InsertRoles.cs b/web-library/Migrations/20231204020308_InsertRoles.cs new file mode 100644 index 0000000..3e569b4 --- /dev/null +++ b/web-library/Migrations/20231204020308_InsertRoles.cs @@ -0,0 +1,45 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace web_library.Migrations +{ + /// + public partial class InsertRoles : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.InsertData( + table: "roles", + columns: new[] { "id", "name" }, + values: new object[,] + { + { 1, "Admin" }, + { 2, "Librarian" }, + { 3, "Client"} + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "roles", + keyColumn: "id", + keyValue: 1); + + migrationBuilder.DeleteData( + table: "roles", + keyColumn: "id", + keyValue: 2 + ); + + migrationBuilder.DeleteData( + table: "roles", + keyColumn: "id", + keyValue: 3 + ); + } + } +} From fee339d4e118cd39b10304da8b5d5d3b3cfd55c5 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 08:20:44 +0100 Subject: [PATCH 15/17] dziala! --- .../Book/Request/AssigneGenreToBookRequest.cs | 12 ++++++ web-library/DependencyInjection.cs | 7 +++- .../Genre/Controller/GenresController.cs | 34 +++++++++++++++++ .../Genre/Repository/GenreRepository.cs | 38 +++++++++++++++++++ .../Genre/Repository/IGenreRepository.cs | 7 ++++ .../Genre/Request/CreateGenreRequest.cs | 7 ++++ web-library/Genre/Service/GenreService.cs | 28 ++++++++++++++ web-library/Genre/Service/IGenreService.cs | 9 +++++ 8 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 web-library/Book/Request/AssigneGenreToBookRequest.cs create mode 100644 web-library/Genre/Controller/GenresController.cs create mode 100644 web-library/Genre/Repository/GenreRepository.cs create mode 100644 web-library/Genre/Repository/IGenreRepository.cs create mode 100644 web-library/Genre/Request/CreateGenreRequest.cs create mode 100644 web-library/Genre/Service/GenreService.cs create mode 100644 web-library/Genre/Service/IGenreService.cs diff --git a/web-library/Book/Request/AssigneGenreToBookRequest.cs b/web-library/Book/Request/AssigneGenreToBookRequest.cs new file mode 100644 index 0000000..36ad43f --- /dev/null +++ b/web-library/Book/Request/AssigneGenreToBookRequest.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace web_library.Book.Request +{ + public class AssigneGenreToBookRequest + { + + public ICollection genres_ids { get; set; } + [JsonIgnore] + public int book_id { get; set; } + } +} diff --git a/web-library/DependencyInjection.cs b/web-library/DependencyInjection.cs index 072c83a..2f3c6ee 100644 --- a/web-library/DependencyInjection.cs +++ b/web-library/DependencyInjection.cs @@ -2,7 +2,8 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using web_library.Book.DataProvider; +using web_library.Genre.Service; +using web_library.Genre.Repository; using web_library.Book.Repository; using web_library.Book.Service; using web_library.Role.Repository; @@ -94,11 +95,15 @@ public static IServiceCollection ServicesInjection(this IServiceCollection servi services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); return services; diff --git a/web-library/Genre/Controller/GenresController.cs b/web-library/Genre/Controller/GenresController.cs new file mode 100644 index 0000000..1f72c53 --- /dev/null +++ b/web-library/Genre/Controller/GenresController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Mvc; + +namespace web_library.Genre.Controller +{ + using web_library.Genre.Request; + using web_library.Genre.Service; + + [Route("api/[controller]")] + [ApiController] + public class GenresController : ControllerBase + { + private readonly IGenreService _genreService; + + public GenresController(IGenreService genreService) + { + _genreService = genreService; + } + + [HttpPost] + public ActionResult Post([FromBody] CreateGenreRequest request) + { + try + { + _genreService.createGenre(request); + return Ok(); + } + catch + (Exception) + { + return BadRequest(); + } + } + } +} diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs new file mode 100644 index 0000000..1cfe000 --- /dev/null +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -0,0 +1,38 @@ +namespace web_library.Genre.Repository +{ + using Entity; + using SharedExceptions; + + public class GenreRepository : IGenreRepository + { + private readonly DataContext _context; + public GenreRepository(DataContext context) + { + _context = context; + } + + public void Add(Genre entity) + { + _context.Genres.Add(entity); + _context.Add(entity); + _context.SaveChanges(); + } + + public IEnumerable FindAll() + { + throw new NotImplementedException(); + } + + public Genre FindByIdOrThrow(int id) + { + Genre? genre = _context.Genres.Find(id) ?? throw new NotFoundException("Genre not found"); + return genre; + throw new NotImplementedException(); + } + + public void Remove(Genre entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/web-library/Genre/Repository/IGenreRepository.cs b/web-library/Genre/Repository/IGenreRepository.cs new file mode 100644 index 0000000..c862514 --- /dev/null +++ b/web-library/Genre/Repository/IGenreRepository.cs @@ -0,0 +1,7 @@ +namespace web_library.Genre.Repository +{ + using Entity; + public interface IGenreRepository : IGenericRepository + { + } +} \ No newline at end of file diff --git a/web-library/Genre/Request/CreateGenreRequest.cs b/web-library/Genre/Request/CreateGenreRequest.cs new file mode 100644 index 0000000..93a9d16 --- /dev/null +++ b/web-library/Genre/Request/CreateGenreRequest.cs @@ -0,0 +1,7 @@ +namespace web_library.Genre.Request +{ + public class CreateGenreRequest + { + public string Name { get; set; } + } +} diff --git a/web-library/Genre/Service/GenreService.cs b/web-library/Genre/Service/GenreService.cs new file mode 100644 index 0000000..8a9636e --- /dev/null +++ b/web-library/Genre/Service/GenreService.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; +using web_library.Genre.Repository; +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + using Entity; + using Newtonsoft.Json; + + public class GenreService : IGenreService + { + private readonly IGenreRepository _genreRepository; + + public GenreService(IGenreRepository genreRepository) + { + _genreRepository = genreRepository; + } + + public void createGenre(CreateGenreRequest request) + { + var jsonString = JsonConvert.SerializeObject(request); + + Genre? genre = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); + + _genreRepository.Add(genre); + } + } +} diff --git a/web-library/Genre/Service/IGenreService.cs b/web-library/Genre/Service/IGenreService.cs new file mode 100644 index 0000000..8960d6d --- /dev/null +++ b/web-library/Genre/Service/IGenreService.cs @@ -0,0 +1,9 @@ +using web_library.Genre.Request; + +namespace web_library.Genre.Service +{ + public interface IGenreService + { + void createGenre(CreateGenreRequest request); + } +} \ No newline at end of file From a6e7b34220995f3e51efdbe7d7be651159a55940 Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 09:04:56 +0100 Subject: [PATCH 16/17] fixes v1 --- web-library/Book/Controller/BookController.cs | 44 +-- web-library/Book/Repository/BookRepository.cs | 63 ++-- .../Book/Repository/IBookRepository.cs | 2 - web-library/Book/Service/BookService.cs | 74 +++-- web-library/Book/Service/IBookService.cs | 1 + web-library/DataContext.cs | 29 +- web-library/DependencyInjection.cs | 11 + .../Migrations/DataContextModelSnapshot.cs | 280 ------------------ 8 files changed, 126 insertions(+), 378 deletions(-) delete mode 100644 web-library/Migrations/DataContextModelSnapshot.cs diff --git a/web-library/Book/Controller/BookController.cs b/web-library/Book/Controller/BookController.cs index ea04b89..67a89cb 100644 --- a/web-library/Book/Controller/BookController.cs +++ b/web-library/Book/Controller/BookController.cs @@ -5,54 +5,54 @@ namespace web_library.Book.Controller { using Entity; - using web_library.Book.Request; - using web_library.Book.Service; + using Request; + using Service; + using DataProvider; + using Microsoft.AspNetCore.Authorization; [Route("api/[controller]")] [ApiController] public class BookController : ControllerBase { private readonly IBookService _bookService; + private readonly IBookDataProvider _bookDataProvider; - public BookController(IBookService bookService) + public BookController(IBookService bookService, IBookDataProvider bookDataProvider) { _bookService = bookService; + _bookDataProvider = bookDataProvider; } // GET: api/ [HttpGet] public ActionResult> Get() { - return Ok(); - } - - // GET api//5 - [HttpGet("{id}")] - public string Get(int id) - { - return "value"; + return Ok(_bookDataProvider.getAll()); } // POST api/ [HttpPost] public ActionResult Post([FromBody] CreateBookRequest request) { - try - { - _bookService.createBook(request); - } - catch - (Exception) - { - return NotFound(); - } + _bookService.createBook(request); return Ok(); } + // POST api/ [HttpPost("seed")] - public ActionResult Post2([FromBody] CreateBookRequest request) + public ActionResult Seed([FromBody] CreateBookRequest request) { + request = new("seed"); _bookService.createBook(request); - return Ok("bqu"); + return Ok(); + } + + // PUT api//5 + [HttpPut("{id}")] + public ActionResult Put(int id, [FromBody] AssigneGenreToBookRequest request) + { + request.book_id = id; + _bookService.assigneGenre(request); + return Ok(); } } } diff --git a/web-library/Book/Repository/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs index aad481e..d9e0746 100644 --- a/web-library/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -1,42 +1,41 @@ -using System; -using System.Collections.Generic; -using web_library.Book.DataProvider; +using Microsoft.EntityFrameworkCore; +using web_library.SharedExceptions; -namespace web_library.Book.Repository +namespace web_library.Book.Repository; +using Entity; + +public class BookRepository : IBookRepository { - public class BookRepository : IBookRepository + private readonly DataContext _context; + public BookRepository(DataContext context) { - private readonly DataContext _context; - public BookRepository(DataContext context) - { - _context = context; - } + _context = context; + } - public void Add(Entity.Book entity) - { - _context.Books.Add(entity); - _context.SaveChanges(); - } + public void Add(Book entity) + { + _context.Books.Add(entity); + _context.SaveChanges(); + } - public IEnumerable FindAll() - { - throw new NotImplementedException(); - } + public IEnumerable FindAll() + { + return _context.Books.Include(b => b.Copies).ToList(); + } - public Entity.Book FindByIdOrThrow(int id) - { - throw new NotImplementedException(); - } + public Book FindByIdOrThrow(int id) + { + return _context.Books.Find(id) ?? throw new NotFoundException("Book not found"); + } - public void Remove(Entity.Book entity) - { - throw new NotImplementedException(); - } + public void Remove(Book entity) + { + throw new NotImplementedException(); + } - public void Update(Entity.Book entity) - { - _context.Books.Update(entity); - _context.SaveChanges(); - } + public void Update(Book entity) + { + _context.Books.Update(entity); + _context.SaveChanges(); } } diff --git a/web-library/Book/Repository/IBookRepository.cs b/web-library/Book/Repository/IBookRepository.cs index 867bd78..48676cd 100644 --- a/web-library/Book/Repository/IBookRepository.cs +++ b/web-library/Book/Repository/IBookRepository.cs @@ -1,8 +1,6 @@ namespace web_library.Book.Repository; using Entity; -using web_library.Book.Entity; - public interface IBookRepository : IGenericRepository { public void Update(Book book); diff --git a/web-library/Book/Service/BookService.cs b/web-library/Book/Service/BookService.cs index b95c701..4345924 100644 --- a/web-library/Book/Service/BookService.cs +++ b/web-library/Book/Service/BookService.cs @@ -1,50 +1,60 @@ using Microsoft.AspNetCore.Authorization; using Newtonsoft.Json; -using web_library.Book.DataProvider; -using web_library.Book.Entity; -using web_library.Book.Repository; -using web_library.Book.Request; using web_library.Role.Enum; using web_library.SharedExceptions; using web_library.User.Service; -namespace web_library.Book.Service +namespace web_library.Book.Service; +using Entity; +using Repository; +using Request; +using Genre.Entity; +using Genre.Repository; +public class BookService : IBookService { - public class BookService : IBookService + private readonly IGenreRepository _genreRepository; + private readonly IBookRepository _bookRepository; + private readonly IBookCopyRepository _bookCopyRepository; + private readonly IUserService _userService; + + public BookService(IGenreRepository genreRepository, IBookRepository bookRepository, IBookCopyRepository bookCopyRepository, IUserService userService) { - private readonly IBookRepository _bookRepository; - private readonly IBookCopyRepository _bookCopyRepository; - private readonly IUserService _userService; + _genreRepository = genreRepository; + _bookRepository = bookRepository; + _bookCopyRepository = bookCopyRepository; + _userService = userService; + } - public BookService(IBookRepository bookRepository, IBookCopyRepository bookCopyRepository, - IUserService userService) - { - _bookRepository = bookRepository; - _bookCopyRepository = bookCopyRepository; - _userService = userService; - } + public void createBook(CreateBookRequest request) + { + //if (!_userService.HasRole(_userService.GetUser(), Roles.Librarian)) + //{ + // throw new UnauthorizedException(); + //} - [Authorize] - public void createBook(CreateBookRequest request) - { - if (!_userService.HasRole(_userService.GetUser(), Roles.Librarian)) - { - throw new UnauthorizedException(); - } + var jsonString = JsonConvert.SerializeObject(request); - var jsonString = JsonConvert.SerializeObject(request); + Book? entity = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); - Entity.Book? entity = JsonConvert.DeserializeObject(jsonString) ?? throw new JsonException(); + _bookRepository.Add(entity); - _bookRepository.Add(entity); + for (int i = 0; i < request.numberOfCopies; i++) + { + BookCopy copy = new(entity); + _bookCopyRepository.Add(copy); + } - for (int i = 0; i < request.numberOfCopies; i++) - { - BookCopy copy = new(entity); - _bookCopyRepository.Add(copy); - } + _bookRepository.Update(entity); + } - _bookRepository.Update(entity); + public void assigneGenre(AssigneGenreToBookRequest request) + { + Entity.Book? book = _bookRepository.FindByIdOrThrow(request.book_id); + foreach (var id in request.genres_ids) + { + Genre? genre = _genreRepository.FindByIdOrThrow(id); + book.AddGenre(genre); } + _bookRepository.Update(book); } } \ No newline at end of file diff --git a/web-library/Book/Service/IBookService.cs b/web-library/Book/Service/IBookService.cs index 9afe3aa..b628362 100644 --- a/web-library/Book/Service/IBookService.cs +++ b/web-library/Book/Service/IBookService.cs @@ -5,4 +5,5 @@ namespace web_library.Book.Service; public interface IBookService { void createBook(CreateBookRequest request); + void assigneGenre(AssigneGenreToBookRequest request); } \ No newline at end of file diff --git a/web-library/DataContext.cs b/web-library/DataContext.cs index fa8d035..e7f83db 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -1,9 +1,9 @@ using Microsoft.EntityFrameworkCore; using web_library.Book.Entity; +using web_library.Genre.Entity; +using web_library.Reservation.Entity; +using web_library.Role.Entity; using web_library.User.Entity; - -namespace web_library; - public class DataContext : DbContext { protected readonly IConfiguration Configuration; @@ -20,7 +20,16 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(entity => + //modelBuilder.Entity() + // .HasMany(left => left.Genres) + // .WithMany(right => right.Books) + // .UsingEntity>( + // "book_genres", + // j => j.HasOne().WithMany().HasForeignKey("genre_id"), + // j => j.HasOne().WithMany().HasForeignKey("book_id") + //); + + modelBuilder.Entity(entity => { entity.ToTable("users"); entity.HasIndex(u => u.Email).IsUnique(); @@ -40,7 +49,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasIndex(ubi => ubi.UserId).IsUnique(); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.ToTable("roles"); entity.HasKey(r => r.Id); @@ -49,11 +58,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) base.OnModelCreating(modelBuilder); } - public DbSet Users { get; set; } - public DbSet Books { get; set; } + public DbSet Users { get; set; } + public DbSet Books { get; set; } public DbSet BooksCopy { get; set; } - public DbSet Genres { get; set; } + public DbSet Genres { get; set; } public DbSet UserBasicInfos { get; set; } - public DbSet Roles { get; set; } - public DbSet Reservations{ get; set; } + public DbSet Roles { get; set; } + public DbSet Reservations{ get; set; } } \ No newline at end of file diff --git a/web-library/DependencyInjection.cs b/web-library/DependencyInjection.cs index 2f3c6ee..0bc12fa 100644 --- a/web-library/DependencyInjection.cs +++ b/web-library/DependencyInjection.cs @@ -9,6 +9,10 @@ using web_library.Role.Repository; using web_library.User.Repository; using web_library.User.Service; +using web_library.Reservation.Service; +using web_library.Reservation.Repostiory; +using web_library.Reservation.DataProvider; +using web_library.Book.DataProvider; namespace web_library; @@ -93,11 +97,18 @@ public static IServiceCollection ServicesInjection(this IServiceCollection servi { services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); diff --git a/web-library/Migrations/DataContextModelSnapshot.cs b/web-library/Migrations/DataContextModelSnapshot.cs deleted file mode 100644 index 2a61a6f..0000000 --- a/web-library/Migrations/DataContextModelSnapshot.cs +++ /dev/null @@ -1,280 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using web_library; - -#nullable disable - -namespace web_library.Migrations -{ - [DbContext(typeof(DataContext))] - partial class DataContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("BookGenre", b => - { - b.Property("BooksId") - .HasColumnType("integer"); - - b.Property("GenresId") - .HasColumnType("integer"); - - b.HasKey("BooksId", "GenresId"); - - b.HasIndex("GenresId"); - - b.ToTable("BookGenre"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Author") - .IsRequired() - .HasColumnType("text") - .HasColumnName("author"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text") - .HasColumnName("description"); - - b.Property("ISBN") - .IsRequired() - .HasColumnType("text") - .HasColumnName("isbn"); - - b.Property("Location") - .IsRequired() - .HasColumnType("text") - .HasColumnName("location"); - - b.Property("Publication_date") - .HasColumnType("date") - .HasColumnName("publication_date"); - - b.Property("Publisher") - .IsRequired() - .HasColumnType("text") - .HasColumnName("publisher"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text") - .HasColumnName("title"); - - b.HasKey("Id"); - - b.ToTable("books"); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BookId") - .HasColumnType("integer") - .HasColumnName("book_id"); - - b.HasKey("Id"); - - b.HasIndex("BookId"); - - b.ToTable("book_copies"); - }); - - modelBuilder.Entity("web_library.Genre.Entity.Genre", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("genres"); - }); - - modelBuilder.Entity("web_library.Role.Entity.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text") - .HasColumnName("name"); - - b.HasKey("Id"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("text") - .HasColumnName("email"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text") - .HasColumnName("password"); - - b.Property("RoleId") - .HasColumnType("integer") - .HasColumnName("role_id"); - - b.HasKey("Id"); - - b.HasIndex("Email") - .IsUnique(); - - b.HasIndex("RoleId"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasColumnName("id"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("text") - .HasColumnName("address"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("first_name"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("last_name"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("text") - .HasColumnName("phone_number"); - - b.Property("UserId") - .HasColumnType("integer") - .HasColumnName("user_id"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_basic_info", (string)null); - }); - - modelBuilder.Entity("BookGenre", b => - { - b.HasOne("web_library.Book.Entity.Book", null) - .WithMany() - .HasForeignKey("BooksId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("web_library.Genre.Entity.Genre", null) - .WithMany() - .HasForeignKey("GenresId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("web_library.Book.Entity.BookCopy", b => - { - b.HasOne("web_library.Book.Entity.Book", "Book") - .WithMany("Copies") - .HasForeignKey("BookId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Book"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.HasOne("web_library.Role.Entity.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("web_library.User.Entity.UserBasicInfo", b => - { - b.HasOne("web_library.User.Entity.User", "User") - .WithOne("UserBasicInfo") - .HasForeignKey("web_library.User.Entity.UserBasicInfo", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("web_library.Book.Entity.Book", b => - { - b.Navigation("Copies"); - }); - - modelBuilder.Entity("web_library.User.Entity.User", b => - { - b.Navigation("UserBasicInfo"); - }); -#pragma warning restore 612, 618 - } - } -} From 03f7f3746f04d1a6a15f8d25c6e0e1c6849f28cf Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 9 Dec 2023 09:15:45 +0100 Subject: [PATCH 17/17] add more detalied exception messages --- web-library/Book/Repository/BookCopyRepository.cs | 3 ++- web-library/Book/Repository/BookRepository.cs | 2 +- web-library/Genre/Repository/GenreRepository.cs | 2 +- web-library/Reservation/Repostiory/ReservationRepository.cs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/web-library/Book/Repository/BookCopyRepository.cs b/web-library/Book/Repository/BookCopyRepository.cs index c1b21dd..194a483 100644 --- a/web-library/Book/Repository/BookCopyRepository.cs +++ b/web-library/Book/Repository/BookCopyRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using web_library.Book.Entity; +using web_library.SharedExceptions; namespace web_library.Book.Repository { @@ -25,7 +26,7 @@ public IEnumerable FindAll() public BookCopy FindByIdOrThrow(int id) { - throw new NotImplementedException(); + return _context.BooksCopy.Find(id) ?? throw new NotFoundException("Book copy" + id + " not found in repository"); } public void Remove(BookCopy entity) diff --git a/web-library/Book/Repository/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs index d9e0746..271654f 100644 --- a/web-library/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -25,7 +25,7 @@ public IEnumerable FindAll() public Book FindByIdOrThrow(int id) { - return _context.Books.Find(id) ?? throw new NotFoundException("Book not found"); + return _context.Books.Find(id) ?? throw new NotFoundException("Book " + id + " not found in repository"); } public void Remove(Book entity) diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs index 1cfe000..1e7353f 100644 --- a/web-library/Genre/Repository/GenreRepository.cs +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -25,7 +25,7 @@ public IEnumerable FindAll() public Genre FindByIdOrThrow(int id) { - Genre? genre = _context.Genres.Find(id) ?? throw new NotFoundException("Genre not found"); + Genre? genre = _context.Genres.Find(id) ?? throw new NotFoundException("Genre " + id + " not found in repository"); return genre; throw new NotImplementedException(); } diff --git a/web-library/Reservation/Repostiory/ReservationRepository.cs b/web-library/Reservation/Repostiory/ReservationRepository.cs index 4372af2..c29dc9e 100644 --- a/web-library/Reservation/Repostiory/ReservationRepository.cs +++ b/web-library/Reservation/Repostiory/ReservationRepository.cs @@ -27,7 +27,7 @@ public IEnumerable FindAll() public Reservation FindByIdOrThrow(int id) { - return _context.Reservations.Find(id) ?? throw new NotFoundException("Reservation not found repository"); + return _context.Reservations.Find(id) ?? throw new NotFoundException("Reservation " + id + " not found in repository"); } public void Remove(Reservation entity)