From 927ce4826b2d751d27c4c6682512932912b757ef Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Sat, 2 Dec 2023 03:44:29 +0100 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 344fcf23b72d60f16f40daad6148f3fbe6bde72c Mon Sep 17 00:00:00 2001 From: kmaliszewski Date: Fri, 8 Dec 2023 15:27:19 +0100 Subject: [PATCH 7/8] 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 8/8] 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 @@ + + + +