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 diff --git a/web-library/Book/Controller/BookController.cs b/web-library/Book/Controller/BookController.cs deleted file mode 100644 index 4d7bacf..0000000 --- a/web-library/Book/Controller/BookController.cs +++ /dev/null @@ -1,64 +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.Book.Controller -{ - using Entity; - using web_library.Book.Request; - using web_library.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 string Get(int id) - { - return "value"; - } - - // 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 void Put(int id, [FromBody] string value) - { - } - - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} diff --git a/web-library/Book/Entity/Book.cs b/web-library/Book/Entity/Book.cs index 1207615..8742c7e 100644 --- a/web-library/Book/Entity/Book.cs +++ b/web-library/Book/Entity/Book.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations.Schema; + namespace web_library.Book.Entity; using web_library.Genre.Entity; @@ -46,7 +47,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/Book/Entity/BookCopy.cs index 5fba106..5c1a9d1 100644 --- a/web-library/Book/Entity/BookCopy.cs +++ b/web-library/Book/Entity/BookCopy.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations.Schema; +using web_library.BookReservation.Entity; namespace web_library.Book.Entity; @@ -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/BookRepository.cs b/web-library/Book/Repository/BookRepository.cs index d2bec19..bc74afb 100644 --- a/web-library/Book/Repository/BookRepository.cs +++ b/web-library/Book/Repository/BookRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Book.DataProvider +using web_library.Shared; +namespace web_library.Book.Repository { using Entity; + public class BookRepository : IBookRepository { private readonly DataContext _context; @@ -22,7 +24,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/Repository/IBookRepository.cs b/web-library/Book/Repository/IBookRepository.cs index c0c8412..f0abed7 100644 --- a/web-library/Book/Repository/IBookRepository.cs +++ b/web-library/Book/Repository/IBookRepository.cs @@ -1,6 +1,8 @@ -namespace web_library.Book.DataProvider +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/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..523f5cf 100644 --- a/web-library/Book/Service/BookService.cs +++ b/web-library/Book/Service/BookService.cs @@ -1,19 +1,23 @@ -using web_library.Book.DataProvider; -using web_library.Book.Request; -namespace web_library.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; 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 +38,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/BookReservation/Entity/Reservation.cs b/web-library/BookReservation/Entity/Reservation.cs new file mode 100644 index 0000000..6f389f4 --- /dev/null +++ b/web-library/BookReservation/Entity/Reservation.cs @@ -0,0 +1,32 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace web_library.BookReservation.Entity +{ + using System.ComponentModel.DataAnnotations; + using web_library.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/DataContext.cs b/web-library/DataContext.cs index 83bf13d..51565de 100644 --- a/web-library/DataContext.cs +++ b/web-library/DataContext.cs @@ -1,65 +1,72 @@ 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; - } - - protected override void OnConfiguring(DbContextOptionsBuilder options) - { - // connect to postgres with connection string from app settings - options.UseNpgsql(Configuration.GetConnectionString("WebApiDatabase")); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) + using Api.Book.Entity; + 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 { - 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") - ); + protected readonly IConfiguration Configuration; - 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(); + + entity.HasIndex(ubi => ubi.UserId).IsUnique(); - public DbSet Users { get; set; } + }); + base.OnModelCreating(modelBuilder); + } - public DbSet Books { get; set; } - public DbSet BooksCopy { get; set; } - public DbSet Genres { get; set; } + 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/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/Entity/Genre.cs b/web-library/Genre/Entity/Genre.cs index e8c8ece..48c3227 100644 --- a/web-library/Genre/Entity/Genre.cs +++ b/web-library/Genre/Entity/Genre.cs @@ -3,6 +3,7 @@ namespace web_library.Genre.Entity { using web_library.Book.Entity; + [Table("genres")] public class Genre { diff --git a/web-library/Genre/Repository/GenreRepository.cs b/web-library/Genre/Repository/GenreRepository.cs new file mode 100644 index 0000000..0ae66ec --- /dev/null +++ b/web-library/Genre/Repository/GenreRepository.cs @@ -0,0 +1,38 @@ +namespace web_library.Genre.Repository +{ + using Entity; + using web_library.Shared; + + 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 GetAll() + { + throw new NotImplementedException(); + } + + public Genre GetByIdOrThrow(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 diff --git a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs index 768949e..717fa9d 100644 --- a/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs +++ b/web-library/Migrations/20231202031627_userAndUserBasicInfoEntity.Designer.cs @@ -11,8 +11,6 @@ namespace web_library.Migrations { - [DbContext(typeof(DataContext))] - [Migration("20231202031627_userAndUserBasicInfoEntity")] partial class userAndUserBasicInfoEntity { /// 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..0bbbafb 100644 --- a/web-library/Program.cs +++ b/web-library/Program.cs @@ -4,11 +4,20 @@ 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; +using web_library.Genre.Repository; +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); @@ -44,7 +53,12 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // Add services to the container. @@ -91,9 +105,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/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 diff --git a/web-library/User/Controller/AuthController.cs b/web-library/User/Controller/AuthController.cs index 6785a1a..12294a7 100644 --- a/web-library/User/Controller/AuthController.cs +++ b/web-library/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; using Microsoft.AspNetCore.Mvc; - +using web_library.User.Request; +using web_library.User.Service; [ApiController] [Route("api/auth")] diff --git a/web-library/User/Repository/IUserBasicInfoRepository.cs b/web-library/User/Repository/IUserBasicInfoRepository.cs index 57ed8d6..5ca44ca 100644 --- a/web-library/User/Repository/IUserBasicInfoRepository.cs +++ b/web-library/User/Repository/IUserBasicInfoRepository.cs @@ -1,5 +1,6 @@ namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; public interface IUserBasicInfoRepository { diff --git a/web-library/User/Repository/IUserRepository.cs b/web-library/User/Repository/IUserRepository.cs index 2ff4778..e61248a 100644 --- a/web-library/User/Repository/IUserRepository.cs +++ b/web-library/User/Repository/IUserRepository.cs @@ -1,5 +1,6 @@ namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; public interface IUserRepository : IGenericRepository { diff --git a/web-library/User/Repository/UserBasicInfoRepository.cs b/web-library/User/Repository/UserBasicInfoRepository.cs index 5991d01..4c5374d 100644 --- a/web-library/User/Repository/UserBasicInfoRepository.cs +++ b/web-library/User/Repository/UserBasicInfoRepository.cs @@ -1,5 +1,6 @@ namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; public class UserBasicInfoRepository : IUserBasicInfoRepository { diff --git a/web-library/User/Repository/UserRepository.cs b/web-library/User/Repository/UserRepository.cs index 57454df..8570275 100644 --- a/web-library/User/Repository/UserRepository.cs +++ b/web-library/User/Repository/UserRepository.cs @@ -2,6 +2,7 @@ namespace web_library.User.Repository; using Entity; +using web_library.User.Entity; public class UserRepository : IUserRepository { diff --git a/web-library/User/Service/AuthService.cs b/web-library/User/Service/AuthService.cs index 4651b78..3c7f593 100644 --- a/web-library/User/Service/AuthService.cs +++ b/web-library/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; using Entity; +using web_library.User.Entity; +using web_library.User.Repository; +using web_library.User.Request; public class AuthService : IAuthService { diff --git a/web-library/appsettings.Development.json b/web-library/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/web-library/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/web-library/web-library.csproj b/web-library/web-library.csproj index 6f912b3..dbcbff7 100644 --- a/web-library/web-library.csproj +++ b/web-library/web-library.csproj @@ -23,4 +23,8 @@ + + + +