Removed todos and added User endpoint combined with register. Id changed to guid

This commit is contained in:
Dominic Villemure
2024-04-03 23:57:01 -04:00
parent df8b42bdf1
commit 1f795c53bb
67 changed files with 1750 additions and 1895 deletions

View File

@@ -1,6 +1,8 @@
using Azure.Identity;
using Hutopy.Application.Common.Interfaces;
using Hutopy.Domain.Interfaces;
using Hutopy.Infrastructure.Data;
using Hutopy.Infrastructure.Services;
using Hutopy.Web.Services;
using Microsoft.AspNetCore.Mvc;
using NSwag;
@@ -15,6 +17,8 @@ public static class DependencyInjection
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddScoped<IUser, CurrentUser>();
services.AddScoped<IUserService, UserService>();
services.AddHttpContextAccessor();

View File

@@ -1,4 +1,6 @@
using Hutopy.Application.FutureCreators.Commands;
using Hutopy.Application.Common.Models;
using Hutopy.Application.FutureCreators.Commands;
using Hutopy.Application.FutureCreators.Queries;
namespace Hutopy.Web.Endpoints;
@@ -7,11 +9,17 @@ public class JoinUs : EndpointGroupBase
public override void Map(WebApplication app)
{
app.MapGroup(this)
.MapGet(GetFutureCreators)
.MapPost(CreateFutureCreator);
}
private static Task<int> CreateFutureCreator(ISender sender, CreateFutureCreatorCommand command)
private static Task<Guid> CreateFutureCreator(ISender sender, CreateFutureCreatorCommand command)
{
return sender.Send(command);
}
private static Task<PaginatedList<FutureCreatorListDto>> GetFutureCreators(ISender sender, [AsParameters] GetFutureCreatorListQuery query)
{
return sender.Send(query);
}
}

View File

@@ -1,52 +0,0 @@
using Hutopy.Application.Common.Models;
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
using Hutopy.Application.TodoItems.Commands.DeleteTodoItem;
using Hutopy.Application.TodoItems.Commands.UpdateTodoItem;
using Hutopy.Application.TodoItems.Commands.UpdateTodoItemDetail;
using Hutopy.Application.TodoItems.Queries.GetTodoItemsWithPagination;
namespace Hutopy.Web.Endpoints;
public class TodoItems : EndpointGroupBase
{
public override void Map(WebApplication app)
{
app.MapGroup(this)
.RequireAuthorization()
.MapGet(GetTodoItemsWithPagination)
.MapPost(CreateTodoItem)
.MapPut(UpdateTodoItem, "{id}")
.MapPut(UpdateTodoItemDetail, "UpdateDetail/{id}")
.MapDelete(DeleteTodoItem, "{id}");
}
private static Task<PaginatedList<TodoItemBriefDto>> GetTodoItemsWithPagination(ISender sender, [AsParameters] GetTodoItemsWithPaginationQuery query)
{
return sender.Send(query);
}
private static Task<int> CreateTodoItem(ISender sender, CreateTodoItemCommand command)
{
return sender.Send(command);
}
private static async Task<IResult> UpdateTodoItem(ISender sender, int id, UpdateTodoItemCommand command)
{
if (id != command.Id) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
private static async Task<IResult> UpdateTodoItemDetail(ISender sender, int id, UpdateTodoItemDetailCommand command)
{
if (id != command.Id) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
private static async Task<IResult> DeleteTodoItem(ISender sender, int id)
{
await sender.Send(new DeleteTodoItemCommand(id));
return Results.NoContent();
}
}

View File

@@ -1,42 +0,0 @@
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Application.TodoLists.Commands.DeleteTodoList;
using Hutopy.Application.TodoLists.Commands.UpdateTodoList;
using Hutopy.Application.TodoLists.Queries.GetTodos;
namespace Hutopy.Web.Endpoints;
public class TodoLists : EndpointGroupBase
{
public override void Map(WebApplication app)
{
app.MapGroup(this)
.RequireAuthorization()
.MapGet(GetTodoLists)
.MapPost(CreateTodoList)
.MapPut(UpdateTodoList, "{id}")
.MapDelete(DeleteTodoList, "{id}");
}
private static Task<TodosVm> GetTodoLists(ISender sender)
{
return sender.Send(new GetTodosQuery());
}
private static Task<int> CreateTodoList(ISender sender, CreateTodoListCommand command)
{
return sender.Send(command);
}
private static async Task<IResult> UpdateTodoList(ISender sender, int id, UpdateTodoListCommand command)
{
if (id != command.Id) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
private static async Task<IResult> DeleteTodoList(ISender sender, int id)
{
await sender.Send(new DeleteTodoListCommand(id));
return Results.NoContent();
}
}

View File

@@ -1,4 +1,6 @@
using Hutopy.Infrastructure.Identity;
using Hutopy.Application.Users.Commands;
using Hutopy.Domain.Interfaces;
using Hutopy.Infrastructure.Identity;
namespace Hutopy.Web.Endpoints;
@@ -7,6 +9,13 @@ public class Users : EndpointGroupBase
public override void Map(WebApplication app)
{
app.MapGroup(this)
.MapPost(CreateUser)
.MapIdentityApi<ApplicationUser>();
}
public async Task<Guid> CreateUser(ISender sender, CreateUserCommand command, IUserService userService)
{
await userService.CreateUserAsync(command.EmailAddress, command.UserName, command.Password);
return await sender.Send(command);
}
}

View File

@@ -1,6 +1,8 @@
using Hutopy.Application;
using Hutopy.Domain.Interfaces;
using Hutopy.Infrastructure;
using Hutopy.Infrastructure.Data;
using Hutopy.Infrastructure.Services;
using Hutopy.Web;
var builder = WebApplication.CreateBuilder(args);
@@ -22,6 +24,7 @@ builder.Services.AddApplicationServices();
builder.Services.AddInfrastructureServices(builder.Configuration);
builder.Services.AddWebServices();
builder.Services.AddScoped<IUserService, UserService>();
var app = builder.Build();

View File

@@ -7,6 +7,46 @@
},
"paths": {
"/api/JoinUs": {
"get": {
"tags": [
"JoinUs"
],
"operationId": "GetFutureCreators",
"parameters": [
{
"name": "PageNumber",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
},
{
"name": "PageSize",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 2
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaginatedListOfFutureCreatorListDto"
}
}
}
}
}
},
"post": {
"tags": [
"JoinUs"
@@ -30,8 +70,8 @@
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
"type": "string",
"format": "guid"
}
}
}
@@ -71,73 +111,18 @@
}
}
},
"/api/TodoItems": {
"get": {
"tags": [
"TodoItems"
],
"operationId": "GetTodoItemsWithPagination",
"parameters": [
{
"name": "ListId",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
},
{
"name": "PageNumber",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 2
},
{
"name": "PageSize",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 3
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaginatedListOfTodoItemBriefDto"
}
}
}
}
},
"security": [
{
"JWT": []
}
]
},
"/api/Users": {
"post": {
"tags": [
"TodoItems"
"Users"
],
"operationId": "CreateTodoItem",
"operationId": "CreateUser",
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateTodoItemCommand"
"$ref": "#/components/schemas/CreateUserCommand"
}
}
},
@@ -150,261 +135,13 @@
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
"type": "string",
"format": "guid"
}
}
}
}
},
"security": [
{
"JWT": []
}
]
}
},
"/api/TodoItems/{id}": {
"put": {
"tags": [
"TodoItems"
],
"operationId": "UpdateTodoItem",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateTodoItemCommand"
}
}
},
"required": true,
"x-position": 2
},
"responses": {
"200": {
"description": ""
}
},
"security": [
{
"JWT": []
}
]
},
"delete": {
"tags": [
"TodoItems"
],
"operationId": "DeleteTodoItem",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"responses": {
"200": {
"description": ""
}
},
"security": [
{
"JWT": []
}
]
}
},
"/api/TodoItems/UpdateDetail/{id}": {
"put": {
"tags": [
"TodoItems"
],
"operationId": "UpdateTodoItemDetail",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateTodoItemDetailCommand"
}
}
},
"required": true,
"x-position": 2
},
"responses": {
"200": {
"description": ""
}
},
"security": [
{
"JWT": []
}
]
}
},
"/api/TodoLists": {
"get": {
"tags": [
"TodoLists"
],
"operationId": "GetTodoLists",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TodosVm"
}
}
}
}
},
"security": [
{
"JWT": []
}
]
},
"post": {
"tags": [
"TodoLists"
],
"operationId": "CreateTodoList",
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateTodoListCommand"
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
}
}
}
}
},
"security": [
{
"JWT": []
}
]
}
},
"/api/TodoLists/{id}": {
"put": {
"tags": [
"TodoLists"
],
"operationId": "UpdateTodoList",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateTodoListCommand"
}
}
},
"required": true,
"x-position": 2
},
"responses": {
"200": {
"description": ""
}
},
"security": [
{
"JWT": []
}
]
},
"delete": {
"tags": [
"TodoLists"
],
"operationId": "DeleteTodoList",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"responses": {
"200": {
"description": ""
}
},
"security": [
{
"JWT": []
}
]
}
}
},
"/api/Users/register": {
@@ -822,6 +559,52 @@
},
"components": {
"schemas": {
"PaginatedListOfFutureCreatorListDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/FutureCreatorListDto"
}
},
"pageNumber": {
"type": "integer",
"format": "int32"
},
"totalPages": {
"type": "integer",
"format": "int32"
},
"totalCount": {
"type": "integer",
"format": "int32"
},
"hasPreviousPage": {
"type": "boolean"
},
"hasNextPage": {
"type": "boolean"
}
}
},
"FutureCreatorListDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"format": "guid"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
}
},
"CreateFutureCreatorCommand": {
"type": "object",
"additionalProperties": false,
@@ -848,6 +631,7 @@
},
"CreateSessionCheckoutCommand": {
"type": "object",
"x-abstract": true,
"additionalProperties": false,
"properties": {
"price": {
@@ -859,231 +643,24 @@
}
}
},
"PaginatedListOfTodoItemBriefDto": {
"CreateUserCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TodoItemBriefDto"
}
"firstName": {
"type": "string"
},
"pageNumber": {
"type": "integer",
"format": "int32"
"lastName": {
"type": "string"
},
"totalPages": {
"type": "integer",
"format": "int32"
"emailAddress": {
"type": "string"
},
"totalCount": {
"type": "integer",
"format": "int32"
"userName": {
"type": "string"
},
"hasPreviousPage": {
"type": "boolean"
},
"hasNextPage": {
"type": "boolean"
}
}
},
"TodoItemBriefDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"listId": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
},
"done": {
"type": "boolean"
}
}
},
"CreateTodoItemCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"listId": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
}
}
},
"UpdateTodoItemCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
},
"done": {
"type": "boolean"
}
}
},
"UpdateTodoItemDetailCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"listId": {
"type": "integer",
"format": "int32"
},
"priority": {
"$ref": "#/components/schemas/PriorityLevel"
},
"note": {
"type": "string",
"nullable": true
}
}
},
"PriorityLevel": {
"type": "integer",
"description": "",
"x-enumNames": [
"None",
"Low",
"Medium",
"High"
],
"enum": [
0,
1,
2,
3
]
},
"TodosVm": {
"type": "object",
"additionalProperties": false,
"properties": {
"priorityLevels": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LookupDto"
}
},
"lists": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TodoListDto"
}
}
}
},
"LookupDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
}
}
},
"TodoListDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
},
"colour": {
"type": "string",
"nullable": true
},
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TodoItemDto"
}
}
}
},
"TodoItemDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"listId": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
},
"done": {
"type": "boolean"
},
"priority": {
"type": "integer",
"format": "int32"
},
"note": {
"type": "string",
"nullable": true
}
}
},
"CreateTodoListCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"title": {
"type": "string",
"nullable": true
}
}
},
"UpdateTodoListCommand": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"title": {
"type": "string",
"nullable": true
"password": {
"type": "string"
}
}
},