Skip to content

Commit d4f2e21

Browse files
committed
Adding the M4 code files
1 parent 7cbf1d7 commit d4f2e21

39 files changed

+2833
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2+
[Bb]in/
3+
[Oo]bj/
4+
5+
# mstest test results
6+
TestResults
7+
8+
## VSCode
9+
.vscode/*
10+
11+
## Ignore Visual Studio temporary files, build results, and
12+
## files generated by popular Visual Studio add-ons.
13+
14+
# User-specific files
15+
*.suo
16+
*.user
17+
*.sln.docstates
18+
19+
# Include dlls if theyfre in the NuGet packages directory
20+
!/packages/*/lib/*.dll
21+
!/packages/*/lib/*/*.dll
22+
# Include dlls if they're in the CommonReferences directory
23+
!*CommonReferences/*.dll
24+
25+
# Build results
26+
[Dd]ebug/
27+
[Rr]elease/
28+
x64/
29+
*_i.c
30+
*_p.c
31+
*.ilk
32+
*.meta
33+
*.obj
34+
*.pch
35+
*.pdb
36+
*.pgc
37+
*.pgd
38+
*.rsp
39+
*.sbr
40+
*.tlb
41+
*.tli
42+
*.tlh
43+
*.tmp
44+
*.log
45+
*.vspscc
46+
*.vssscc
47+
*.sln
48+
.builds
49+
50+
# Visual C++ cache files
51+
ipch/
52+
*.aps
53+
*.ncb
54+
*.opensdf
55+
*.sdf
56+
57+
# Visual Studio profiler
58+
*.psess
59+
*.vsp
60+
*.vspx
61+
62+
# Guidance Automation Toolkit
63+
*.gpState
64+
65+
# ReSharper is a .NET coding add-in
66+
_ReSharper*
67+
68+
# NCrunch
69+
*.ncrunch*
70+
.*crunch*.local.xml
71+
72+
# Installshield output folder
73+
[Ee]xpress
74+
75+
# DocProject is a documentation generator add-in
76+
DocProject/buildhelp/
77+
DocProject/Help/*.HxT
78+
DocProject/Help/*.HxC
79+
DocProject/Help/*.hhc
80+
DocProject/Help/*.hhk
81+
DocProject/Help/*.hhp
82+
DocProject/Help/Html2
83+
DocProject/Help/html
84+
85+
# Click-Once directory
86+
publish
87+
88+
# Publish Web Output
89+
*.Publish.xml
90+
91+
# NuGet Packages Directory
92+
# packages
93+
94+
# Windows Azure Build Output
95+
csx
96+
*.build.csdef
97+
98+
# Windows Store app package directory
99+
AppPackages/
100+
101+
# Others
102+
[Bb]in
103+
[Oo]bj
104+
sql
105+
TestResults
106+
[Tt]est[Rr]esult*
107+
*.[Cc]ache
108+
*.editorconfig
109+
ClientBin
110+
[Ss]tyle[Cc]op.*
111+
~$*
112+
*.dbmdl
113+
Generated_Code #added for RIA/Silverlight projects
114+
115+
# Backup & report files from converting an old project file to a newer
116+
# Visual Studio version. Backup files are not needed, because we have git ;-)
117+
_UpgradeReport_Files/
118+
Backup*/
119+
UpgradeLog*.XML
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Library App
2+
3+
## Description
4+
5+
Library App is a modular application designed to manage library operations such as book loans, patron management, and inventory tracking. It is built using .NET and follows a clean architecture approach to ensure scalability and maintainability.
6+
7+
## Project Structure
8+
9+
- `AccelerateDevGHCopilot.sln` - Solution file for the project.
10+
- `src/`
11+
- `Library.ApplicationCore/`
12+
- `Entities/` - Contains core domain entities.
13+
- `Enums/` - Defines enumerations used across the application.
14+
- `Interfaces/` - Declares interfaces for core abstractions.
15+
- `Services/` - Implements business logic and domain services.
16+
- `Library.ApplicationCore.csproj` - Project file for the Application Core.
17+
- `Library.Console/`
18+
- `appSettings.json` - Configuration file for the console application.
19+
- `CommonActions.cs` - Contains reusable actions for the console app.
20+
- `ConsoleApp.cs` - Main application logic for the console interface.
21+
- `ConsoleState.cs` - Manages the state of the console application.
22+
- `Program.cs` - Entry point for the console application.
23+
- `Json/` - Contains JSON-related utilities or data.
24+
- `Library.Console.csproj` - Project file for the Console application.
25+
- `Library.Infrastructure/`
26+
- `Data/` - Contains data access implementations.
27+
- `Library.Infrastructure.csproj` - Project file for the Infrastructure layer.
28+
- `tests/`
29+
- `UnitTests/`
30+
- `LoanFactory.cs` - Factory for creating test data related to loans.
31+
- `PatronFactory.cs` - Factory for creating test data related to patrons.
32+
- `ApplicationCore/` - Contains unit tests for the Application Core.
33+
- `UnitTests.csproj` - Project file for unit tests.
34+
35+
## Key Classes and Interfaces
36+
37+
- **Entities**
38+
- `Book` - Represents a book in the library.
39+
- `Patron` - Represents a library patron.
40+
- `Loan` - Represents a loan transaction.
41+
- **Interfaces**
42+
- `IBookRepository` - Interface for book-related data operations.
43+
- `IPatronRepository` - Interface for patron-related data operations.
44+
- `ILoanService` - Interface for managing loan operations.
45+
- **Services**
46+
- `LoanService` - Implements loan-related business logic.
47+
- `NotificationService` - Handles notifications for overdue loans.
48+
49+
## Usage
50+
51+
1. Clone the repository:
52+
53+
```bash
54+
git clone <repository-url>
55+
```
56+
57+
2. Open the solution file `AccelerateDevGHCopilot.sln` in Visual Studio.
58+
59+
3. Build the solution to restore dependencies and compile the code.
60+
61+
4. Run the console application:
62+
63+
```bash
64+
dotnet run --project src/Library.Console/Library.Console.csproj
65+
```
66+
67+
5. Execute unit tests:
68+
69+
```bash
70+
dotnet test tests/UnitTests/UnitTests.csproj
71+
```
72+
73+
## License
74+
75+
This project is licensed under the MIT License. See the `LICENSE` file for details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Author
4+
{
5+
public int Id { get; set; }
6+
public required string Name { get; set; }
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Book
4+
{
5+
public int Id { get; set; }
6+
public required string Title { get; set; }
7+
public int AuthorId { get; set; }
8+
public required string Genre { get; set; }
9+
public required string ImageName { get; set; }
10+
public required string ISBN { get; set; }
11+
public Author? Author { get; set; }
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class BookItem
4+
{
5+
public int Id { get; set; }
6+
public int BookId { get; set; }
7+
public DateTime AcquisitionDate { get; set; }
8+
public string? Condition { get; set; }
9+
public Book? Book { get; set; }
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Loan
4+
{
5+
public int Id { get; set; }
6+
public int BookItemId { get; set; }
7+
public int PatronId { get; set; }
8+
public Patron? Patron { get; set; }
9+
public DateTime LoanDate { get; set; }
10+
public DateTime DueDate { get; set; }
11+
public DateTime? ReturnDate { get; set; }
12+
public BookItem? BookItem { get; set; }
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Patron
4+
{
5+
public int Id { get; set; }
6+
public required string Name { get; set; }
7+
public DateTime MembershipEnd { get; set; }
8+
public DateTime MembershipStart { get; set; }
9+
public string? ImageName { get; set; }
10+
public ICollection<Loan> Loans { get; set; } = new HashSet<Loan>();
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace Library.ApplicationCore.Enums;
5+
6+
public static class EnumHelper
7+
{
8+
public static string GetDescription(Enum value)
9+
{
10+
if (value == null)
11+
return string.Empty;
12+
13+
FieldInfo fieldInfo = value.GetType().GetField(value.ToString())!;
14+
15+
DescriptionAttribute[] attributes =
16+
(DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
17+
18+
if (attributes != null && attributes.Length > 0)
19+
{
20+
return attributes[0].Description;
21+
}
22+
else
23+
{
24+
return value.ToString();
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum LoanExtensionStatus
6+
{
7+
[Description("Book loan extension was successful.")]
8+
Success,
9+
10+
[Description("Loan not found.")]
11+
LoanNotFound,
12+
13+
[Description("Cannot extend book loan as it already has expired. Return the book instead.")]
14+
LoanExpired,
15+
16+
[Description("Cannot extend book loan due to expired patron's membership.")]
17+
MembershipExpired,
18+
19+
[Description("Cannot extend book loan as the book is already returned.")]
20+
LoanReturned,
21+
22+
[Description("Cannot extend book loan due to an error.")]
23+
Error
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum LoanReturnStatus
6+
{
7+
[Description("Book was successfully returned.")]
8+
Success,
9+
10+
[Description("Loan not found.")]
11+
LoanNotFound,
12+
13+
[Description("Cannot return book as the book is already returned.")]
14+
AlreadyReturned,
15+
16+
[Description("Cannot return book due to an error.")]
17+
Error
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum MembershipRenewalStatus
6+
{
7+
[Description("Membership renewal was successful.")]
8+
Success,
9+
10+
[Description("Patron not found.")]
11+
PatronNotFound,
12+
13+
[Description("It is too early to renew the membership.")]
14+
TooEarlyToRenew,
15+
16+
[Description("Cannot renew membership due to an outstanding loan.")]
17+
LoanNotReturned,
18+
19+
[Description("Cannot renew membership due to an error.")]
20+
Error
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Library.ApplicationCore.Entities;
2+
3+
namespace Library.ApplicationCore;
4+
5+
public interface ILoanRepository {
6+
Task<Loan?> GetLoan(int loanId);
7+
Task UpdateLoan(Loan loan);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Library.ApplicationCore.Enums;
2+
3+
public interface ILoanService
4+
{
5+
Task<LoanReturnStatus> ReturnLoan(int loanId);
6+
Task<LoanExtensionStatus> ExtendLoan(int loanId);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Library.ApplicationCore.Entities;
2+
3+
namespace Library.ApplicationCore;
4+
5+
public interface IPatronRepository {
6+
Task<Patron?> GetPatron(int patronId);
7+
Task<List<Patron>> SearchPatrons(string searchInput);
8+
Task UpdatePatron(Patron patron);
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using Library.ApplicationCore.Enums;
2+
3+
public interface IPatronService
4+
{
5+
Task<MembershipRenewalStatus> RenewMembership(int patronId);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)