Skip to content

Commit

Permalink
Add supplier management functionality with CRUD operations
Browse files Browse the repository at this point in the history
Implemented a complete supplier management system, including repository, service, and controller layers, with CRUD functionality. Introduced `Supplier` and related entities, configured EF Core with SQLite, and added exception handling middleware to handle database-specific errors. Dependency injection setup was updated to register necessary services and repositories.
  • Loading branch information
HSPiira committed Dec 22, 2024
1 parent 7817120 commit 8a4d25c
Show file tree
Hide file tree
Showing 24 changed files with 742 additions and 34 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Henry Piira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
153 changes: 153 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Sereno

## Overview
The Sereno is designed to manage all aspects of running a relaxation garden business. It facilitates:

- **Booking Management**: Schedule and track events and parties.
- **Inventory Management**: Monitor and manage stock levels for drinks.
- **External Providers**: Track food orders and payments to partner restaurants.
- **Accounting**: Manage revenue, expenses, and generate financial reports.
- **Receipt and Invoice Management**: Automate generation and tracking of receipts and invoices.
- **Mobile Money Integration**: Allow seamless mobile money payments for bookings, orders, and other transactions.

---

## Domain-Driven Design (DDD) Structure
The system follows a clean architecture approach, organizing components into core domains and layers to ensure maintainability, scalability, and adherence to business logic.

### **Domains**

1. **Booking Domain**
- **Entities**:
- `Booking`: Represents a reservation, including customer details, event details, and schedule.
- `Customer`: Stores information about the individual or group making the booking.
- **Value Objects**:
- `TimeSlot`: Specifies the start and end time of a booking.
- `BookingStatus`: Enum to define states (e.g., Pending, Confirmed, Cancelled).

2. **Inventory Domain**
- **Entities**:
- `InventoryItem`: Represents a stock item, such as a drink or supply.
- `Supplier`: Represents suppliers providing stock items.
- **Value Objects**:
- `StockLevel`: Encapsulates current stock levels and reorder thresholds.
- `ItemCategory`: Enum for categorizing inventory (e.g., Beverages, Miscellaneous).

3. **External Providers Domain**
- **Entities**:
- `Provider`: Represents external food providers or restaurants.
- `FoodOrder`: Tracks orders placed with providers, linked to bookings.
- **Value Objects**:
- `MenuItem`: Represents an item offered by an external provider, including pricing.
- `OrderStatus`: Enum to define the state of an order (e.g., Pending, Delivered).

4. **Accounting Domain**
- **Entities**:
- `Transaction`: Represents financial transactions (income or expense).
- `Expense`: Tracks operational costs, such as salaries or maintenance.
- **Value Objects**:
- `TransactionType`: Enum to classify transactions (e.g., Revenue, Expense).
- `PaymentMethod`: Enum for payment modes (e.g., Cash, Mobile Money).

5. **Payment Domain**
- **Entities**:
- `Payment`: Represents a payment transaction linked to bookings or orders.
- **Value Objects**:
- `PaymentStatus`: Enum for states (e.g., Paid, Pending, Failed).

---

### **Key Layers**

1. **Core**
- Contains the domain models, entities, value objects, and interfaces.
- This layer encapsulates the business logic and rules.

2. **Application Layer**
- Contains use cases (application services) that orchestrate operations involving domain objects.
- Example Use Cases:
- `MakeBooking`
- `TrackInventory`
- `GenerateInvoice`

3. **Infrastructure Layer**
- Implements external integrations like database access, payment gateways, and API calls.
- Example Components:
- Repository patterns for entities (e.g., `BookingRepository`).
- Mobile money API adapters.

4. **Presentation Layer**
- The user interface for interacting with the system.
- Provides options for web or mobile implementations (e.g., React, Angular, or Flutter).

---

## Technology Stack

### Backend
- **Language/Framework**: C# (ASP.NET Core)
- **Database**: PostgreSQL

### Frontend
- (Pending Decision: Options include React, Angular, or Flutter for mobile applications.)

### Additional Tools
- RESTful APIs for seamless data exchange between frontend and backend.
- Payment gateway integration for mobile money transactions.

---

## System Architecture

### 1. Frontend
- User-friendly interface for staff and customers.
- Features include booking forms, inventory updates, and payment tracking.

### 2. Backend
- RESTful APIs to handle booking, inventory, external provider management, and accounting.

### 3. Database Schema (Sample Tables)
- `Bookings`
- `Customers`
- `Inventory`
- `Sales`
- `ExternalProviders`
- `Expenses`
- `Receipts`
- `Invoices`
- `Payments`

---

## Future Enhancements
- **Advanced Reporting**: Add analytics dashboards for deeper insights.
- **Multi-Location Support**: Expand the system for businesses with multiple branches.
- **Customer Loyalty Programs**: Integrate rewards for frequent customers.
- **E-commerce Support**: Allow customers to book and pay directly from a web or mobile app.

---

## Setup and Installation

### Prerequisites
- Install .NET 9.0 or later.
- Install PostgreSQL.
- Mobile Money API credentials (e.g., MTN MoMo, M-Pesa).

### Steps
1. Clone the repository.
2. Configure the database connection in the backend settings.
3. Install required dependencies for ASP.NET Core.
4. Run database migrations to set up schema.
5. Launch the backend server.
6. Set up and integrate the chosen frontend technology.

---

## License
This project is licensed under the MIT License.

---

## Contact
For inquiries or support, reach out to [Your Contact Information].
42 changes: 42 additions & 0 deletions Sereno.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{89B06F18-D0B2-43DC-A560-8388BBA06F37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sereno.Core", "src\Sereno.Core\Sereno.Core.csproj", "{ED236974-C392-4502-947E-1812639724FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sereno.Application", "src\Sereno.Application\Sereno.Application.csproj", "{D4152F50-642E-4A43-A4B8-685A4498DDA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sereno.Infrastructure", "src\Sereno.Infrastructure\Sereno.Infrastructure.csproj", "{5D415202-D2B9-4E31-84BC-10E5079BBA7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sereno.API", "src\Sereno.API\Sereno.API.csproj", "{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ED236974-C392-4502-947E-1812639724FF} = {89B06F18-D0B2-43DC-A560-8388BBA06F37}
{D4152F50-642E-4A43-A4B8-685A4498DDA7} = {89B06F18-D0B2-43DC-A560-8388BBA06F37}
{5D415202-D2B9-4E31-84BC-10E5079BBA7D} = {89B06F18-D0B2-43DC-A560-8388BBA06F37}
{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3} = {89B06F18-D0B2-43DC-A560-8388BBA06F37}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED236974-C392-4502-947E-1812639724FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED236974-C392-4502-947E-1812639724FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED236974-C392-4502-947E-1812639724FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED236974-C392-4502-947E-1812639724FF}.Release|Any CPU.Build.0 = Release|Any CPU
{D4152F50-642E-4A43-A4B8-685A4498DDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4152F50-642E-4A43-A4B8-685A4498DDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4152F50-642E-4A43-A4B8-685A4498DDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4152F50-642E-4A43-A4B8-685A4498DDA7}.Release|Any CPU.Build.0 = Release|Any CPU
{5D415202-D2B9-4E31-84BC-10E5079BBA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D415202-D2B9-4E31-84BC-10E5079BBA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D415202-D2B9-4E31-84BC-10E5079BBA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D415202-D2B9-4E31-84BC-10E5079BBA7D}.Release|Any CPU.Build.0 = Release|Any CPU
{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEEAC8FE-F0DD-4D21-B656-BC52963ADBF3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
65 changes: 64 additions & 1 deletion src/Sereno.API/Controllers/SupplierController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
using Microsoft.AspNetCore.Mvc;
using Sereno.Application.IService;
using Sereno.Core;
using Sereno.Infrastructure.Dtos;

namespace Sereno.API.Controllers;

public class SupplierController
[Route("api/[controller]")]
[ApiController]
public class SupplierController : ControllerBase
{
private readonly ISupplierService _supplierService;
public SupplierController(ISupplierService supplierService)
{
_supplierService = supplierService;
}
[HttpGet("get-all")]
public IActionResult GetAllSuppliers()
{
var suppliers = _supplierService.GetAllSuppliers();
return Ok(suppliers);
}

[HttpPost("add")]
public async Task<IActionResult> AddSupplier([FromBody] SupplierDto? supplierDto)
{
if (supplierDto == null)
return BadRequest("Invalid supplier data.");

var supplier = new
Supplier(
Guid.NewGuid(),
supplierDto.Name,
supplierDto.Address
);
await _supplierService.AddAsync(supplier);

return CreatedAtAction(nameof(GetSupplierById), new { id = supplier.Id }, supplier);
}

[HttpGet("{id:guid}")]
public async Task<IActionResult> GetSupplierById(Guid id)
{
var supplier = await _supplierService.GetByIdAsync(id);
return Ok(supplier);
}

[HttpPut("update/{id:guid}")]
public async Task<IActionResult> UpdateSupplier([FromBody] SupplierDto supplierDto, Guid id)
{
var supplier = await _supplierService.GetByIdAsync(id)
?? throw new ArgumentException("Supplier not found.");

supplier.Name = supplierDto.Name;
supplier.Address = supplierDto.Address;
await _supplierService.UpdateAsync(supplier);

return Ok(supplier);
}

[HttpDelete("remove/{id}")]
public async Task<IActionResult> DeleteSupplier(Guid id)
{
var supplier = await _supplierService.GetByIdAsync(id)
?? throw new ArgumentException("Supplier not found.");
await _supplierService.DeleteAsync(id: supplier.Id);
return NoContent();
}
}
37 changes: 37 additions & 0 deletions src/Sereno.API/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore;
using Scalar.AspNetCore;
using Sereno.Infrastructure;
using Sereno.Infrastructure.Persistence;
using Sereno.Infrastructure.Persistence.Middleware;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddOpenApi();

builder.Services.AddPersistence(builder.Configuration);
// builder.Services.AddDbContext<AppDbContext>(options =>
// options.UseSqlite("Data Source=suppliers.db"));

var app = builder.Build();

app.UseMiddleware<ExceptionHandlingMiddleware>();


if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference();
}

using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
dbContext.Database.Migrate(); // Apply migrations at startup
Console.WriteLine("Database migrations applied successfully.");
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
23 changes: 23 additions & 0 deletions src/Sereno.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5281",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7070;http://localhost:5281",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
23 changes: 23 additions & 0 deletions src/Sereno.API/Sereno.API.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="1.2.67" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Sereno.Application\Sereno.Application.csproj" />
<ProjectReference Include="..\Sereno.Infrastructure\Sereno.Infrastructure.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Sereno.API/Sereno.API.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Sereno.API_HostAddress = http://localhost:5281

GET {{Sereno.API_HostAddress}}/weatherforecast/
Accept: application/json

###
11 changes: 11 additions & 0 deletions src/Sereno.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=Sereno.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Loading

0 comments on commit 8a4d25c

Please sign in to comment.