-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add get endpoint & fix ApplicationDto
- Loading branch information
1 parent
7f73ea0
commit 7c89c30
Showing
10 changed files
with
107 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Application.Dto; | ||
|
||
public record ApplicationDto(Guid Id, Guid Author, string? Activity, string? Name, string? Description, string? Outline); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Application/Application.Contracts/Applications/GetApplication.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Application.Dto; | ||
using MediatR; | ||
|
||
namespace Application.Contracts.Applications; | ||
|
||
public static class GetApplication | ||
{ | ||
public record struct Command(Guid Id) : IRequest<Response>; | ||
|
||
public abstract record Response; | ||
|
||
public sealed record Success(ApplicationDto Application) : Response; | ||
|
||
public sealed record Failed(string Error) : Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Application/Application/Applications/GetApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Application.Abstractions.DataAccess; | ||
using Application.Mapping; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Application.Applications; | ||
using static Application.Contracts.Applications.GetApplication; | ||
|
||
public class GetApplicationHandler : IRequestHandler<Command, Response> | ||
{ | ||
private readonly IDatabaseContext _databaseContext; | ||
|
||
public GetApplicationHandler(IDatabaseContext databaseContext) | ||
{ | ||
_databaseContext = databaseContext; | ||
} | ||
|
||
public async Task<Response> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var unsubmittedApplication = await _databaseContext.UnsubmittedApplications | ||
.Include(a => a.Activity) | ||
.Where(a => a.Id == request.Id) | ||
.FirstOrDefaultAsync(cancellationToken); | ||
|
||
if (unsubmittedApplication is not null) | ||
{ | ||
return new Success(unsubmittedApplication.AsDto()); | ||
} | ||
|
||
var submittedApplication = await _databaseContext.SubmittedApplications | ||
.Include(a => a.Activity) | ||
.Where(a => a.Id == request.Id) | ||
.FirstOrDefaultAsync(cancellationToken); | ||
|
||
if (submittedApplication is not null) | ||
{ | ||
return new Success(submittedApplication.AsDto()); | ||
} | ||
|
||
return new Failed("No application with such id"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Application.Dto; | ||
using Domain.Applications; | ||
|
||
namespace Application.Mapping; | ||
|
||
public static class ApplicationDtoMapper | ||
{ | ||
public static ApplicationDto AsDto(this UnsubmittedApplication application) | ||
=> new ApplicationDto(application.Id, | ||
application.UserId, | ||
application.Activity?.Name, | ||
application.Name, | ||
application.Description, | ||
application.Plan); | ||
|
||
public static ApplicationDto AsDto(this SubmittedApplication application) | ||
=> new ApplicationDto(application.Id, | ||
application.UserId, | ||
application.Activity.Name, | ||
application.Name, | ||
application.Description, | ||
application.Plan); | ||
} |
15 changes: 0 additions & 15 deletions
15
Application/Application/Mapping/UnsubmittedApplicationDtoMapper.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters