Skip to content

Commit be7f459

Browse files
committed
add open api
1 parent 1089316 commit be7f459

File tree

11 files changed

+1650
-19
lines changed

11 files changed

+1650
-19
lines changed

src/Services/Basket/Basket.API.IntegrationTests/Features/DeleteBasket/DeleteBasketTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task DeleteBasket_No_Token_Returns_Unauthorized(string username)
3535

3636
// Act
3737
var result = await _client
38-
.DeleteAsync($"api/v1/basket/{username}", timeout);
38+
.DeleteAsync($"api/v1/basket/customers/{username}", timeout);
3939

4040
// Assert
4141
result.StatusCode.ShouldBe(HttpStatusCode.Unauthorized);
@@ -51,7 +51,7 @@ public async Task DeleteBasket_No_Permission_Returns_Forbidden(string username)
5151
// Act
5252
var result = await _client
5353
.SetFakeBearerToken("sub")
54-
.DeleteAsync($"api/v1/basket/{username}", timeout);
54+
.DeleteAsync($"api/v1/basket/customers/{username}", timeout);
5555

5656
// Assert
5757
result.StatusCode.ShouldBe(HttpStatusCode.Forbidden);
@@ -96,7 +96,7 @@ public async Task DeleteBasket_Deletes_Basket_From_Cache_And_PostgresDb_Returns_
9696
FakePermission.GetPermissions(
9797
[Policies.BasketUserBasketDeletePermission],
9898
username: username))
99-
.DeleteAsync($"api/v1/basket/{username}", timeout);
99+
.DeleteAsync($"api/v1/basket/customers/{username}", timeout);
100100
var response = await result.Content.ReadFromJsonAsync<DeleteBasketResponse>(timeout);
101101

102102
// Assert

src/Services/Basket/Basket.API.IntegrationTests/Features/GetBasket/GetBasketTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task GetBasket_No_Token_Returns_Unauthorized()
3535

3636
// Act
3737
var result = await _client
38-
.GetAsync($"api/v1/basket/{username}", timeout);
38+
.GetAsync($"api/v1/basket/customers/{username}", timeout);
3939

4040
// Assert
4141
result.StatusCode.ShouldBe(HttpStatusCode.Unauthorized);
@@ -51,7 +51,7 @@ public async Task GetBasket_No_Permission_Returns_Forbidden()
5151
// Act
5252
var result = await _client
5353
.SetFakeBearerToken(FakePermission.GetPermissions([], username: username))
54-
.GetAsync($"api/v1/basket/{username}", timeout);
54+
.GetAsync($"api/v1/basket/customers/{username}", timeout);
5555

5656
// Assert
5757
result.StatusCode.ShouldBe(HttpStatusCode.Forbidden);
@@ -69,7 +69,7 @@ public async Task GetBasket_Basket_NotFound_Returns_NotFound()
6969
.SetFakeBearerToken(
7070
FakePermission.GetPermissions([Policies.BasketUserBasketGetPermission],
7171
username: username))
72-
.GetAsync($"api/v1/basket/{username}", timeout);
72+
.GetAsync($"api/v1/basket/customers/{username}", timeout);
7373
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>(timeout);
7474

7575
// Assert
@@ -113,7 +113,7 @@ public async Task GetBasket_Basket_Only_Exists_In_Postgres_database_Should_Retur
113113
var result = await _client
114114
.SetFakeBearerToken(FakePermission.GetPermissions([Policies.BasketUserBasketGetPermission],
115115
username: username))
116-
.GetAsync($"api/v1/basket/{username}", timeout);
116+
.GetAsync($"api/v1/basket/customers/{username}", timeout);
117117
var response = await result.Content.ReadFromJsonAsync<GetBasketResponse>(timeout);
118118

119119
// Assert
@@ -161,7 +161,7 @@ public async Task GetBasket_Basket_Only_Exists_In_Redis_database_Should_Return_B
161161
var result = await _client
162162
.SetFakeBearerToken(FakePermission.GetPermissions([Policies.BasketUserBasketGetPermission],
163163
username: username))
164-
.GetAsync($"api/v1/basket/{username}", timeout);
164+
.GetAsync($"api/v1/basket/customers/{username}", timeout);
165165
var response = await result.Content.ReadFromJsonAsync<GetBasketResponse>(timeout);
166166

167167
// Assert

src/Services/Basket/Basket.API.IntegrationTests/Features/StoreBasket/StoreBasketTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task StoreBasket_Null_Username_Returns_BadRequest(StoreBasketReques
4545
[Policies.BasketUserBasketStorePermission],
4646
username: request.ShoppingCart.Username,
4747
roles: ["admin"]))
48-
.PostAsJsonAsync("api/v1/basket", invalidRequest, token);
48+
.PostAsJsonAsync("api/v1/basket/customers", invalidRequest, token);
4949
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>(token);
5050

5151
// Assert
@@ -69,7 +69,7 @@ public async Task StoreBasket_Null_Request_Returns_BadRequest(StoreBasketRequest
6969
[Policies.BasketUserBasketStorePermission],
7070
username: request.ShoppingCart?.Username,
7171
roles: ["admin"]))
72-
.PostAsJsonAsync("api/v1/basket", request, token);
72+
.PostAsJsonAsync("api/v1/basket/customers", request, token);
7373
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>(token);
7474

7575
// Assert
@@ -92,7 +92,7 @@ public async Task StoreBasket_Null_Items_In_Request_Returns_BadRequest(StoreBask
9292
.SetFakeBearerToken(FakePermission.GetPermissions(
9393
[Policies.BasketUserBasketStorePermission],
9494
username: request.ShoppingCart?.Username))
95-
.PostAsJsonAsync("api/v1/basket", invalidRequest);
95+
.PostAsJsonAsync("api/v1/basket/customers", invalidRequest);
9696
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>();
9797

9898
// Assert
@@ -118,7 +118,7 @@ public async Task StoreBasket_Zero_Quantity_In_Items_In_Request_Returns_BadReque
118118
.SetFakeBearerToken(FakePermission.GetPermissions(
119119
[Policies.BasketUserBasketStorePermission],
120120
username: request.ShoppingCart?.Username))
121-
.PostAsJsonAsync("api/v1/basket", invalidRequest, token);
121+
.PostAsJsonAsync("api/v1/basket/customers", invalidRequest, token);
122122
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>(token);
123123

124124
// Assert
@@ -144,7 +144,7 @@ public async Task StoreBasket_Zero_Price_In_Items_In_Request_Returns_BadRequest(
144144
.SetFakeBearerToken(FakePermission.GetPermissions(
145145
[Policies.BasketUserBasketStorePermission],
146146
username: request.ShoppingCart?.Username))
147-
.PostAsJsonAsync("api/v1/basket", invalidRequest, token);
147+
.PostAsJsonAsync("api/v1/basket/customers", invalidRequest, token);
148148
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>(token);
149149

150150
// Assert
@@ -167,7 +167,7 @@ public async Task StoreBasket_Valid_Request_Saves_Data_In_PostgresDb_And_Redis(S
167167
.SetFakeBearerToken(FakePermission.GetPermissions(
168168
[Policies.BasketUserBasketStorePermission],
169169
username: request.ShoppingCart?.Username))
170-
.PostAsJsonAsync("api/v1/basket", request, token);
170+
.PostAsJsonAsync("api/v1/basket/customers", request, token);
171171
var response = await result.Content.ReadFromJsonAsync<StoreBasketResponse>(token);
172172

173173
// Assert
@@ -208,7 +208,7 @@ public async Task StoreBasket_Valid_Request_Saves_Data_With_Valid_TotalPrice(Sto
208208
.SetFakeBearerToken(FakePermission.GetPermissions(
209209
[Policies.BasketUserBasketStorePermission],
210210
username: request.ShoppingCart?.Username))
211-
.PostAsJsonAsync("api/v1/basket", validRequest, token);
211+
.PostAsJsonAsync("api/v1/basket/customers", validRequest, token);
212212
var response = await result.Content.ReadFromJsonAsync<StoreBasketResponse>(token);
213213

214214
// Assert

src/Services/Basket/Basket.API/Authorization/UserAuthorizationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override Task HandleRequirementAsync(
4141
return Task.CompletedTask;
4242
}
4343

44-
private bool ValidateUserPermissions(
44+
private static bool ValidateUserPermissions(
4545
IReadOnlyList<Claim> claims,
4646
IReadOnlyList<string> requirements
4747
)

src/Services/Basket/Basket.API/Features/DeleteBasket/DeleteBasketEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class DeleteBasketEndpoint
1010
public static IEndpointRouteBuilder MapDeleteBasketEndpoint(
1111
this IEndpointRouteBuilder app)
1212
{
13-
app.MapDelete("/{username}", DeleteBasketAsync)
13+
app.MapDelete("/customers/{username}", DeleteBasketAsync)
1414
.WithName("DeleteBasket")
1515
.Produces<DeleteBasketResponse>()
1616
.ProducesProblem(StatusCodes.Status400BadRequest)

src/Services/Basket/Basket.API/Features/GetBasket/GetBasketEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class GetBasketEndpoint
88
{
99
public static IEndpointRouteBuilder MapGetBasketEndpoint(this IEndpointRouteBuilder app)
1010
{
11-
app.MapGet("/{username}", GetBasketAsync)
11+
app.MapGet("/customers/{username}", GetBasketAsync)
1212
.WithName("GetBasket")
1313
.Produces<GetBasketResponse>()
1414
.ProducesProblem(StatusCodes.Status400BadRequest)

src/Services/Basket/Basket.API/Features/StoreBasket/StoreBasketEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class StoreBasketEndpoint
88
{
99
public static IEndpointRouteBuilder MapStoreBasketEndpoint(this IEndpointRouteBuilder app)
1010
{
11-
app.MapPost("/", StoreBasketAsync)
11+
app.MapPost("/customers", StoreBasketAsync)
1212
.WithName("StoreBasket")
1313
.Produces<StoreBasketResponse>()
1414
.ProducesProblem(StatusCodes.Status400BadRequest)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Basket.API
4+
version: v1
5+
paths:
6+
/api/v1/basket/customers/{username}:
7+
get:
8+
tags:
9+
- Basket API
10+
summary: Get Basket by username
11+
parameters:
12+
- name: username
13+
in: path
14+
required: true
15+
schema:
16+
type: string
17+
responses:
18+
'200':
19+
description: Success
20+
content:
21+
application/json:
22+
schema:
23+
$ref: '#/components/schemas/GetBasketResponse'
24+
'400':
25+
description: Bad Request
26+
'401':
27+
description: Unauthorized
28+
'403':
29+
description: Forbidden
30+
'404':
31+
description: Not Found
32+
delete:
33+
tags:
34+
- Basket API
35+
summary: Delete Basket by username
36+
parameters:
37+
- name: username
38+
in: path
39+
required: true
40+
schema:
41+
type: string
42+
responses:
43+
'200':
44+
description: Success
45+
content:
46+
application/json:
47+
schema:
48+
$ref: '#/components/schemas/DeleteBasketResponse'
49+
'400':
50+
description: Bad Request
51+
'401':
52+
description: Unauthorized
53+
'403':
54+
description: Forbidden
55+
'404':
56+
description: Not Found
57+
/api/v1/basket/customers:
58+
post:
59+
tags:
60+
- Basket API
61+
summary: Store Basket
62+
requestBody:
63+
content:
64+
application/json:
65+
schema:
66+
$ref: '#/components/schemas/StoreBasketRequest'
67+
responses:
68+
'200':
69+
description: Success
70+
content:
71+
application/json:
72+
schema:
73+
$ref: '#/components/schemas/StoreBasketResponse'
74+
'400':
75+
description: Bad Request
76+
'401':
77+
description: Unauthorized
78+
'403':
79+
description: Forbidden
80+
'404':
81+
description: Not Found
82+
components:
83+
securitySchemes:
84+
Bearer:
85+
type: http
86+
scheme: bearer
87+
bearerFormat: JWT
88+
schemas:
89+
BasketDtoRequest:
90+
type: object
91+
properties:
92+
username:
93+
type: string
94+
items:
95+
type: array
96+
items:
97+
$ref: '#/components/schemas/BasketItem'
98+
BasketDtoResponse:
99+
type: object
100+
properties:
101+
username:
102+
type: string
103+
items:
104+
type: array
105+
items:
106+
$ref: '#/components/schemas/BasketItem'
107+
total_price:
108+
type: number
109+
format: decimal
110+
BasketItem:
111+
type: object
112+
properties:
113+
quantity:
114+
type: integer
115+
format: int32
116+
color:
117+
type: string
118+
price:
119+
type: number
120+
format: decimal
121+
product_id:
122+
type: string
123+
product_name:
124+
type: string
125+
DeleteBasketResponse:
126+
type: object
127+
properties:
128+
is_success:
129+
type: boolean
130+
GetBasketResponse:
131+
allOf:
132+
- $ref: '#/components/schemas/BasketDtoResponse'
133+
StoreBasketRequest:
134+
type: object
135+
properties:
136+
shopping_cart:
137+
$ref: '#/components/schemas/BasketDtoRequest'
138+
StoreBasketResponse:
139+
type: object
140+
properties:
141+
shopping_cart:
142+
$ref: '#/components/schemas/BasketDtoResponse'
143+
security:
144+
- Bearer: []

0 commit comments

Comments
 (0)