Skip to content

Commit 3ca8e2c

Browse files
Merge pull request #49 from DilmurodDeveloper/users/DilmurodDeveloper/exposers-reader-post
EXPOSERS: Post Reader
2 parents 6fd4621 + 6794d76 commit 3ca8e2c

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.Readers;
7+
using LibraryManagement.Api.Models.Foundations.Readers.Exceptions;
8+
using LibraryManagement.Api.Services.Foundations.Readers;
9+
using Microsoft.AspNetCore.Mvc;
10+
using RESTFulSense.Controllers;
11+
12+
namespace LibraryManagement.Api.Controllers
13+
{
14+
[ApiController]
15+
[Route("api/[controller]")]
16+
public class ReadersController : RESTFulController
17+
{
18+
private readonly IReaderService readerService;
19+
20+
public ReadersController(IReaderService readerService)
21+
{
22+
this.readerService = readerService;
23+
}
24+
25+
[HttpPost]
26+
public async ValueTask<ActionResult<Reader>> PostReaderAsync(Reader reader)
27+
{
28+
try
29+
{
30+
Reader postedReader =
31+
await this.readerService.AddReaderAsync(reader);
32+
33+
return Created(postedReader);
34+
}
35+
catch (ReaderValidationException readerValidationException)
36+
{
37+
return BadRequest(readerValidationException.InnerException);
38+
}
39+
catch (ReaderDependencyValidationException readerDependencyValidationException)
40+
when (readerDependencyValidationException.InnerException is AlreadyExistsReaderException)
41+
{
42+
return Conflict(readerDependencyValidationException.InnerException);
43+
}
44+
catch (ReaderDependencyValidationException readerDependencyValidationException)
45+
{
46+
return BadRequest(readerDependencyValidationException.InnerException);
47+
}
48+
catch (ReaderDependencyException readerDependencyException)
49+
{
50+
return InternalServerError(readerDependencyException.InnerException);
51+
}
52+
catch (ReaderServiceException readerServiceException)
53+
{
54+
return InternalServerError(readerServiceException.InnerException);
55+
}
56+
}
57+
}
58+
}

LibraryManagement.Api/Models/Foundations/Readers/Reader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Free To Use To Build Reliable Library Management Solutions
44
//-----------------------------------------------------------
55

6+
using System.Text.Json.Serialization;
67
using LibraryManagement.Api.Models.Foundations.Books;
78

89
namespace LibraryManagement.Api.Models.Foundations.Readers
@@ -13,6 +14,9 @@ public class Reader
1314
public string FirstName { get; set; }
1415
public string LastName { get; set; }
1516
public DateTimeOffset DateOfBirth { get; set; }
16-
public List<Book> Books { get; set; }
17+
18+
[JsonIgnore]
19+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
20+
public List<Book> Books { get; set; } = new();
1721
}
1822
}

LibraryManagement.Api/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using LibraryManagement.Api.Brokers.Loggings;
77
using LibraryManagement.Api.Brokers.Storages;
88
using LibraryManagement.Api.Services.Foundations.Books;
9+
using LibraryManagement.Api.Services.Foundations.Readers;
910
using Microsoft.OpenApi.Models;
1011

1112
var builder = WebApplication.CreateBuilder(args);
@@ -20,6 +21,7 @@
2021
builder.Services.AddTransient<IStorageBroker, StorageBroker>();
2122
builder.Services.AddTransient<ILoggingBroker, LoggingBroker>();
2223
builder.Services.AddTransient<IBookService, BookService>();
24+
builder.Services.AddTransient<IReaderService, ReaderService>();
2325
builder.Services.AddControllers();
2426
builder.Services.AddEndpointsApiExplorer();
2527

0 commit comments

Comments
 (0)