Skip to content

Commit ff28336

Browse files
Feat[ECommerceAPI] (#103)
1 parent 54f67a7 commit ff28336

File tree

102 files changed

+528
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+528
-605
lines changed

.github/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ dotnet tool install --global dotnet-ef
8585

8686
### Environment
8787

88-
[appsettings.development.Example](../App/ECommerceInfrastructure/appsettings.development.Example)
88+
[appsettings.development.Example](../App/ECommerceAPI/appsettings.development.Example)
8989

9090
```sh
9191
# copy appsettings.development.Example to appsettings.development.json
92-
cp App/ECommerceInfrastructure/appsettings.development.Example App/ECommerceInfrastructure/appsettings.development.json
92+
cp App/ECommerceAPI/appsettings.development.Example App/ECommerceAPI/appsettings.development.json
9393

9494
```
9595

@@ -158,17 +158,17 @@ dotnet tool install --global dotnet-ef
158158

159159
- Using > Database > Select all
160160
```sh
161-
.scripts/cmd/select.table.sh < Name >
161+
.scripts/cmd/select-table.sh < Name >
162162
```
163163

164164
- Using > Database > Count
165165
```sh
166-
.scripts/cmd/count.table.sh < Name >
166+
.scripts/cmd/count-table.sh < Name >
167167
```
168168

169169
- Using > Database > Truncate
170170
```sh
171-
.scripts/cmd/truncate.table.sh < Name >
171+
.scripts/cmd/truncate-table.sh < Name >
172172
```
173173

174174
#### Tests
@@ -193,8 +193,8 @@ dotnet tool install --global dotnet-ef
193193
## Entity Relationship Diagram (ERD)
194194

195195
- See:
196-
- Entities -> [Models](../App/ECommerceInfrastructure/Persistence/Models/)
197-
- Relationship -> [Database Context](../App/ECommerceInfrastructure/Persistence/Contexts/DatabaseContext.cs)
196+
- Entities -> [Models](../App/ECommercePersistence/Model)
197+
- Relationship -> [Database Context](../App/ECommercePersistence/Context/DatabaseContext.cs)
198198
> ERD print 04/09/23
199199
200200
![ERD](ERD-ECommerce.png)

.scripts/database/drop.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
context=$1
44

5-
cd App/ECommerceInfrastructure
5+
cd App/ECommerceAPI
66

77
dotnet ef database drop -c $context

.scripts/database/update.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
context=$1
44

5-
cd App/ECommerceInfrastructure
5+
cd App/ECommerceAPI
66

77
dotnet ef database update -c $context

.scripts/migration/add.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
name=$1
44
context=$2
55

6-
cd App/ECommerceInfrastructure
6+
cd App/ECommerceAPI
77

88
dotnet ef migrations add $name -o Migrations/"$context"Migrations -c $context

.scripts/migration/list.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
context=$1
44

5-
cd App/ECommerceInfrastructure
5+
cd App/ECommerceAPI
66

77
dotnet ef migrations list -c $context

.scripts/migration/remove.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
context=$1
44

5-
cd App/ECommerceInfrastructure
5+
cd App/ECommerceAPI
66

77
dotnet ef migrations remove -c $context
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

3-
dotnet build App/ECommerceInfrastructure/ --configuration Release
3+
dotnet build App/ECommerceAPI/ --configuration Release
44

5-
dotnet publish App/ECommerceInfrastructure/ -c Release -o dist
5+
dotnet publish App/ECommerceAPI/ -c Release -o dist
66

7-
cp App/ECommerceInfrastructure/appsettings.development.json dist/appsettings.development.json
7+
cp App/ECommerceAPI/appsettings.development.json dist/appsettings.development.json
88

9-
dotnet dist/ECommerceInfrastructure.dll
9+
dotnet dist/ECommerceAPI.dll

App/ECommerceAPI/ECommerceAPI.csproj

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
<PrivateAssets>all</PrivateAssets>
13+
</PackageReference>
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\ECommerceInfrastructure\ECommerceInfrastructure.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

App/ECommerceAPI/ECommerceAPI.http

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@ECommerceAPI_HostAddress = https://localhost:7096
2+
3+
GET {{ECommerceAPI_HostAddress}}/api/v1/customers
4+
Accept: application/json
5+
6+
POST {{ECommerceAPI_HostAddress}}/api/v1/customers
7+
Accept: application/json
8+
9+
PATCH {{ECommerceAPI_HostAddress}}/api/v1/customers
10+
Accept: application/json
11+
12+
DELETE {{ECommerceAPI_HostAddress}}/api/v1/customers
13+
Accept: application/json
14+

App/ECommerceAPI/Endpoint.cs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using ECommerceAPI.Resource;
2+
using ECommerceApplication.Request;
3+
using ECommerceApplication.UseCase;
4+
using ECommerceInfrastructure.Auth.Identities;
5+
using Microsoft.AspNetCore.Mvc;
6+
using System.Security.Claims;
7+
8+
namespace ECommerceAPI;
9+
10+
internal static class Endpoint
11+
{
12+
public static void Configure(IEndpointRouteBuilder app)
13+
{
14+
app.MapGet("/api/v1/customers", async (
15+
[FromServices] FindOneCustomer useCase,
16+
ClaimsPrincipal user) =>
17+
{
18+
var customer = new CustomerIdentity(user);
19+
var customerDto = await useCase.Execute(new(Id: customer.Id));
20+
return Results.Ok(new CustomerResource(customerDto));
21+
})
22+
.RequireAuthorization()
23+
.WithSummary("Find")
24+
.WithOpenApi()
25+
.Produces(200, typeof(CustomerResource));
26+
27+
app.MapPost("/api/v1/customers", async (
28+
[FromServices] RegisterCustomer useCase,
29+
[FromBody] CreateCustomerRequest request) =>
30+
{
31+
await useCase.Execute(request);
32+
return Results.Created();
33+
})
34+
.AllowAnonymous()
35+
.WithSummary("Register")
36+
.WithOpenApi()
37+
.Produces(201);
38+
39+
app.MapPatch("/api/v1/customers", async (
40+
[FromServices] UpdateCustomerNameAndEmail useCase,
41+
[FromBody] UpdateCustomerRequest request,
42+
ClaimsPrincipal user) =>
43+
{
44+
var customer = new CustomerIdentity(user);
45+
request.Id = customer.Id;
46+
await useCase.Execute(request);
47+
return Results.NoContent();
48+
})
49+
.RequireAuthorization()
50+
.WithSummary("Update")
51+
.WithOpenApi()
52+
.Produces(204);
53+
54+
app.MapDelete("/api/v1/customers", async (
55+
[FromServices] RemoveCustomer useCase,
56+
ClaimsPrincipal user) =>
57+
{
58+
var customer = new CustomerIdentity(user);
59+
await useCase.Execute(new(Id: customer.Id));
60+
return Results.NoContent();
61+
})
62+
.RequireAuthorization()
63+
.WithSummary("Remove")
64+
.WithOpenApi()
65+
.Produces(204);
66+
}
67+
}

App/ECommerceInfrastructure/Migrations/DatabaseContextMigrations/20240304205412_Initial.Designer.cs App/ECommerceAPI/Migrations/DatabaseContextMigrations/20240311215045_Initial.Designer.cs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

App/ECommerceInfrastructure/Migrations/DatabaseContextMigrations/20240304205412_Initial.cs App/ECommerceAPI/Migrations/DatabaseContextMigrations/20240311215045_Initial.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#nullable disable
55

6-
namespace ECommerceInfrastructure.Migrations.DatabaseContextMigrations
6+
namespace ECommerceAPI.Migrations.DatabaseContextMigrations
77
{
88
/// <inheritdoc />
99
public partial class Initial : Migration

App/ECommerceInfrastructure/Migrations/DatabaseContextMigrations/DatabaseContextModelSnapshot.cs App/ECommerceAPI/Migrations/DatabaseContextMigrations/DatabaseContextModelSnapshot.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#nullable disable
1010

11-
namespace ECommerceInfrastructure.Migrations.DatabaseContextMigrations
11+
namespace ECommerceAPI.Migrations.DatabaseContextMigrations
1212
{
1313
[DbContext(typeof(DatabaseContext))]
1414
partial class DatabaseContextModelSnapshot : ModelSnapshot
@@ -22,7 +22,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
2222

2323
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
2424

25-
modelBuilder.Entity("ECommercePersistence.Models.Customer", b =>
25+
modelBuilder.Entity("ECommercePersistence.Model.Customer", b =>
2626
{
2727
b.Property<string>("Id")
2828
.HasMaxLength(36)

App/ECommerceInfrastructure/Migrations/LoggerContextMigrations/20240304205434_Initial.Designer.cs App/ECommerceAPI/Migrations/LoggerContextMigrations/20240311215101_Initial.Designer.cs

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

App/ECommerceInfrastructure/Migrations/LoggerContextMigrations/20240304205434_Initial.cs App/ECommerceAPI/Migrations/LoggerContextMigrations/20240311215101_Initial.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#nullable disable
66

7-
namespace ECommerceInfrastructure.Migrations.LoggerContextMigrations
7+
namespace ECommerceAPI.Migrations.LoggerContextMigrations
88
{
99
/// <inheritdoc />
1010
public partial class Initial : Migration

App/ECommerceInfrastructure/Migrations/LoggerContextMigrations/LoggerContextModelSnapshot.cs App/ECommerceAPI/Migrations/LoggerContextMigrations/LoggerContextModelSnapshot.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#nullable disable
1010

11-
namespace ECommerceInfrastructure.Migrations.LoggerContextMigrations
11+
namespace ECommerceAPI.Migrations.LoggerContextMigrations
1212
{
1313
[DbContext(typeof(LoggerContext))]
1414
partial class LoggerContextModelSnapshot : ModelSnapshot
@@ -22,7 +22,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
2222

2323
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
2424

25-
modelBuilder.Entity("ECommercePersistence.Models.LogRequest", b =>
25+
modelBuilder.Entity("ECommercePersistence.Model.LogRequest", b =>
2626
{
2727
b.Property<long?>("Id")
2828
.ValueGeneratedOnAdd()
@@ -67,7 +67,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
6767
b.ToTable("LogRequests");
6868
});
6969

70-
modelBuilder.Entity("ECommercePersistence.Models.LogResponse", b =>
70+
modelBuilder.Entity("ECommercePersistence.Model.LogResponse", b =>
7171
{
7272
b.Property<long?>("Id")
7373
.ValueGeneratedOnAdd()

App/ECommerceInfrastructure/Program.cs App/ECommerceAPI/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ECommerceInfrastructure;
1+
namespace ECommerceAPI;
22

33
public class Program
44
{

App/ECommerceInfrastructure/Properties/launchSettings.json App/ECommerceAPI/Properties/launchSettings.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"$schema": "https://json.schemastore.org/launchsettings.json",
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
33
"iisSettings": {
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:50977",
8-
"sslPort": 44335
7+
"applicationUrl": "http://localhost:20042",
8+
"sslPort": 44302
99
}
1010
},
1111
"profiles": {
@@ -14,7 +14,7 @@
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,
1616
"launchUrl": "swagger",
17-
"applicationUrl": "http://localhost:5232",
17+
"applicationUrl": "http://localhost:5211",
1818
"environmentVariables": {
1919
"ASPNETCORE_ENVIRONMENT": "Development"
2020
}
@@ -24,7 +24,7 @@
2424
"dotnetRunMessages": true,
2525
"launchBrowser": true,
2626
"launchUrl": "swagger",
27-
"applicationUrl": "https://localhost:7262;http://localhost:5232",
27+
"applicationUrl": "https://localhost:7096;http://localhost:5211",
2828
"environmentVariables": {
2929
"ASPNETCORE_ENVIRONMENT": "Development"
3030
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using ECommerceDomain.DTO;
3+
4+
namespace ECommerceAPI.Resource;
5+
6+
public readonly struct CustomerResource(CustomerDTO x)
7+
{
8+
public string? Id { get; init; } = x.Id;
9+
public string? Name { get; init; } = x.Name;
10+
public string? FirstName { get; init; } = x.FirstName;
11+
public string? LastName { get; init; } = x.LastName;
12+
[EmailAddress]
13+
public string? Email { get; init; } = x.Email;
14+
public DateOnly CreatedOn { get; init; } = DateOnly.FromDateTime(x.CreatedOn!.Value.DateTime);
15+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using ECommerceInfrastructure.Auth.Tokens;
2+
3+
namespace ECommerceAPI.Resource;
4+
5+
public readonly struct TokenResource(Token x)
6+
{
7+
public string Token { get; init; } = x.Value;
8+
public string Type { get; init; } = Enum.GetName(x.Type)!;
9+
public string Scope { get; init; } = Enum.GetName(x.Scope)!;
10+
}

0 commit comments

Comments
 (0)