Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using AutoMapper;
using Library_Management_System.Models.Dtos;
using Library_Management_System.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Library_Management_System.Controllers
{
[Route("api")]
[ApiController]
public class AuthorController : ControllerBase
{
private readonly IAuthor _author;
private readonly IMapper _mapper;
public AuthorController(IAuthor author, IMapper mapper)
{
_author = author;
_mapper = mapper;
}


//Create
[HttpPost("author/create")]
public ActionResult Create([FromBody]AuthorForCreationDto author)
{
//Author bookAuthor = _mapper.Map<Author>(author);

if (author == null) { return BadRequest(); }
var status = _author.CreateAuthor(author);
return Ok(status);
}

//GetAllAuthors
[HttpGet("author/getAll")]
public ActionResult GetAllAuthors()
{
var allAuthors = _author.GetAllAuthors();

//return Ok(_mapper.Map<AuthorForDisplayDto>(allAuthors));
List<AuthorForDisplayDto> allAuthorsDto = new List<AuthorForDisplayDto>();
foreach (var authors in allAuthors)
{
allAuthorsDto.Add(new AuthorForDisplayDto()
{
AuthorDetails = authors.AuthorDetails,
AuthorName = authors.AuthorName,
//Publisher= authors.Publisher,
Books = authors.Books,
});
}
return Ok(allAuthorsDto);
}

//GetAnAuthor
[HttpGet("author/getAuthor")]
public ActionResult GetAnAuthor(string authorName)
{
if (authorName == null) { return BadRequest(); }
var authors = _author.GetAuthor(authorName);
if (authors == null)
{
return Ok("No author not found");
}

return Ok(authors);
}

//GetBooksAttachedToAnAuthor
[HttpGet("author/getBooksByAuthor")]
public ActionResult GetBooksAttachedToAnAuthor(string authorName)
{
if (authorName == null) { return BadRequest(); }
var books = _author.GetAllBooksByAuthor(authorName);
return Ok(books);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using AutoMapper;
using Library_Management_System.Models.Dtos;
using Library_Management_System.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Library_Management_System.Controllers
{
[Route("api")]
[ApiController]
public class BookController : ControllerBase
{
private readonly IBook _book;
private readonly IMapper _mapper;
public BookController(IBook book, IMapper mapper)
{
_book = book;
_mapper = mapper;
}

// Create
[HttpPost("create-book")]
public ActionResult Create(BookForCreationDto bookDto)
{
if (bookDto == null)
{
return BadRequest();
}
var book = _book.CreateBook(bookDto);
return Ok(book);
}

// GetABook
[HttpGet("get-book")]
public ActionResult GetABook(string bookName)
{
if (bookName == null)
{
return BadRequest();
}
var book = _book.GetABook(bookName);
return Ok(book);
}

// GetAllBooks
[HttpGet("books")]
public ActionResult GetAllBooks()
{
var books = _book.GetAllBooks();
return Ok(books);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using AutoMapper;
using Library_Management_System.Models.Dtos;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Library_Management_System.Controllers
{
[Route("api")]
[ApiController]
public class PublisherController : ControllerBase
{
private readonly IPublisher _publisher;
private readonly IMapper _mapper;
public PublisherController(IPublisher publisher, IMapper mapper)
{
_publisher = publisher;
_mapper = mapper;
}

/// <summary>
/// Endpoint creates a new publisher
/// </summary>
/// <param name="publisherDto">An object representing a publisher</param>
/// <returns>200(Success) or 400(BadRequest)</returns>
[HttpPost("publisher/create")]
public ActionResult Create(PublisherForCreation publisherDto)
{

if (publisherDto == null) { return BadRequest(); }
_publisher.CreatePublisher(publisherDto);
return Ok("Publisher created successfully");
}

//Get A Publisher
[HttpGet("publisher/getpublisher")]
public ActionResult GetAPublisher(string publisherName)
{
if (publisherName == null)
{
return BadRequest();
}
var publisher = _publisher.GetAPublisher(publisherName);
return Ok(publisher);
}

//GetAllPublishers
[HttpGet("publisher/getAllPublisher")]
public ActionResult GetAllPublishers()
{
var publishers = _publisher.GetAllPublishers();
return Ok(publishers);
}

//GetAuthorsAttachedToAPublisher
[HttpGet("publisher/getAuthorsByPublishers")]
public ActionResult GetAuthorsAttachedToAPublisher(string publisherName)
{
if (publisherName == null)
{
return BadRequest();
}
var authors = _publisher.GetAuthorsAttachedToAPublisher(publisherName);
return Ok(authors);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Library_Management_System.Entities;

namespace Library_Management_System.Data
{
public class ApplicationDbContext: DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options): base(options) { }



protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Book_Author>()
.HasOne(book => book.Book)
.WithMany(book_author => book_author.Book_Authors)
.HasForeignKey(book_id => book_id.BookId);

modelBuilder.Entity<Book_Author>()
.HasOne(author => author.Author)
.WithMany(book_author => book_author.Book_Authors)
.HasForeignKey(author_id => author_id.AuthorId);
}

public DbSet<Publisher> Publishers { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
public DbSet<Book_Author> Book_Authors { get; set; }
}
}
21 changes: 21 additions & 0 deletions Joseph/StageThreeTask/Library Management System/Entities/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Library_Management_System.Entities
{
public class Author
{
[Key]
public int AuthorId { get; set; }
[Required]
public string AuthorName { get; set; }

[Required]
[MaxLength(100)]
public string AuthorDetails { get; set; }
public List<Book_Author> Book_Authors { get; set; }
public int PublisherId { get; set; }
public Publisher Publisher { get; set; }


}
}
23 changes: 23 additions & 0 deletions Joseph/StageThreeTask/Library Management System/Entities/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Library_Management_System.Entities
{
public class Book
{
[Key]
public int BookId { get; set; }

public string Title { get; set; }

[MaxLength(150)]
public string Description { get; set; }

[Required]
public string ISBNNumber { get; set; }

public string Version { get; set; }

public List<Book_Author> Book_Authors { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Library_Management_System.Entities
{
public class Book_Author
{
public int Id { get; set; }
public int BookId { get; set; }
public Book Book { get; set; }

public int AuthorId { get; set; }
public Author Author { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Library_Management_System.Entities
{
public class Publisher
{
[Key]
public int PublisherId { get; set; }

[Required]
public string PublisherName { get; set; }

[Required]
[MaxLength(250)]
public string CopyRightLicense { get; set; }

[Required]
public string PublisherAddress { get; set; }


public List<Author> Authors{ get; set; } = new List<Author>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global using Microsoft.EntityFrameworkCore;
global using System.ComponentModel.DataAnnotations;
global using Library_Management_System.Entities;
global using Library_Management_System.Services;
global using Library_Management_System.Models.Dtos;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Library_Management_System</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library Management System", "Library Management System.csproj", "{BAA55578-8C10-47D8-8551-D99071DD4D3A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAA55578-8C10-47D8-8551-D99071DD4D3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAA55578-8C10-47D8-8551-D99071DD4D3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAA55578-8C10-47D8-8551-D99071DD4D3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAA55578-8C10-47D8-8551-D99071DD4D3A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D5372C8E-773E-4F5A-A7CF-BB441F2F6028}
EndGlobalSection
EndGlobal
Loading