generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/issue 833 timeline context #1394
Merged
vasylashka
merged 34 commits into
release/1.0.0
from
feature/issue-833-timeline-context
May 12, 2024
Merged
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
79291a4
add: update endpoint for historicalContext
BapBap7 deb1821
add: getById endpoint for historicalContext
BapBap7 222e2d7
add: delete endpoint for historicalContext, todo: create
BapBap7 158c237
add: create for historicaContext + validation for unique context.
BapBap7 6fe64ec
Update Delete tag
VladyslavPavlysko 9b838d7
sort tags
VladyslavPavlysko 675dd6b
Merge branch 'develop' of https://github.com/ita-social-projects/Stre…
VladyslavPavlysko 561abe6
change sort order
VladyslavPavlysko 864cf15
Merge branch 'develop' of https://github.com/ita-social-projects/Stre…
VladyslavPavlysko c3042f3
add: validation for unique update
BapBap7 8cf70f1
add: sorting
BapBap7 871ae2d
Handler changes
VladyslavPavlysko bb0b55f
Integration tests for tags
VladyslavPavlysko f24d0f4
Unit tests for tags
VladyslavPavlysko de76ab7
add: unit test create, getById for historicalContext
BapBap7 2bb6bae
add: merged with release branch
BapBap7 fa83349
fix: getAllHistoricalContextTest.cs
BapBap7 c7bced2
add: test for delete
BapBap7 8aef160
add: update unit test
BapBap7 468732c
integrational tests, 2 not working
BapBap7 ab85693
add: getByTitle, unit test. fix: integrationalTests
BapBap7 5373fd7
returned appsettings string
BapBap7 653b1f2
Merge branch 'release/1.0.0' into tag-delete-update-requests
Lazy-Lenny 5ff855f
add: nonsense change that might help
BapBap7 a7bd728
Merge branch 'release/1.0.0' into feature/issue-833-timeline-context
BapBap7 25f8529
merged with release, should fix problems
BapBap7 44db69a
returned connectionString
BapBap7 51c2087
Merge branch 'release/1.0.0' of https://github.com/ita-social-project…
VladyslavPavlysko e6a5ce8
Merge branch 'tag-delete-update-requests' of https://github.com/ita-s…
VladyslavPavlysko 4c28b42
default string
VladyslavPavlysko 3f343d5
Merge branch 'release/1.0.0' of https://github.com/ita-social-project…
VladyslavPavlysko bd9116c
fix tag tests
VladyslavPavlysko fb7ae54
Merge branch 'release/1.0.0' into feature/issue-833-timeline-context
vasylashka 3be0093
removed unnecessary coma that caused problems with launching local pr…
BapBap7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Create/CreateHistoricalContextCommand.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,9 @@ | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Create | ||
{ | ||
public record CreateHistoricalContextCommand(HistoricalContextDTO context) | ||
: IRequest<Result<HistoricalContextDTO>>; | ||
} |
49 changes: 49 additions & 0 deletions
49
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Create/CreateHistoricalContextHandler.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,49 @@ | ||
using AutoMapper; | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
using Streetcode.BLL.Interfaces.Logging; | ||
using Streetcode.DAL.Repositories.Interfaces.Base; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Create | ||
{ | ||
public class CreateHistoricalContextHandler : IRequestHandler<CreateHistoricalContextCommand, Result<HistoricalContextDTO>> | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IRepositoryWrapper _repositoryWrapper; | ||
private readonly ILoggerService _logger; | ||
|
||
public CreateHistoricalContextHandler(IMapper mapper, IRepositoryWrapper repositoryWrapper, ILoggerService logger) | ||
{ | ||
_mapper = mapper; | ||
_repositoryWrapper = repositoryWrapper; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<Result<HistoricalContextDTO>> Handle(CreateHistoricalContextCommand request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
/* read comment at Streetcode.BLL.MediatR.Timeline.HistoricalContext.Update line 29 */ | ||
var context = _mapper.Map<DAL.Entities.Timeline.HistoricalContext>(request.context); | ||
var checkIfContextExists = await _repositoryWrapper.HistoricalContextRepository.GetFirstOrDefaultAsync(j => j.Title == request.context.Title); | ||
|
||
if (checkIfContextExists is not null) | ||
{ | ||
string exceptionMessege = $"Context with title '{request.context.Title}' is already exists."; | ||
_logger.LogError(request, exceptionMessege); | ||
return Result.Fail(exceptionMessege); | ||
} | ||
|
||
var createdContext = await _repositoryWrapper.HistoricalContextRepository.CreateAsync(context); | ||
await _repositoryWrapper.SaveChangesAsync(); | ||
return Result.Ok(_mapper.Map<HistoricalContextDTO>(createdContext)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(request, ex.Message); | ||
return Result.Fail(ex.Message); | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Delete/DeleteHistoricalContextCommand.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,8 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Delete | ||
{ | ||
public record DeleteHistoricalContextCommand(int contextId) | ||
: IRequest<Result<int>>; | ||
} |
43 changes: 43 additions & 0 deletions
43
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Delete/DeleteHistoricalContextHandler.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,43 @@ | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.Interfaces.Logging; | ||
using Streetcode.DAL.Repositories.Interfaces.Base; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Delete | ||
{ | ||
public class DeleteHistoricalContextHandler : IRequestHandler<DeleteHistoricalContextCommand, Result<int>> | ||
{ | ||
private readonly IRepositoryWrapper _repositoryWrapper; | ||
private readonly ILoggerService _logger; | ||
|
||
public DeleteHistoricalContextHandler(IRepositoryWrapper repository, ILoggerService logger) | ||
{ | ||
_repositoryWrapper = repository; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<Result<int>> Handle(DeleteHistoricalContextCommand request, CancellationToken cancellationToken) | ||
{ | ||
var contextToDelete = | ||
await _repositoryWrapper.HistoricalContextRepository.GetFirstOrDefaultAsync(x => x.Id == request.contextId); | ||
if (contextToDelete is null) | ||
{ | ||
string exMessage = $"No context found by entered Id - {request.contextId}"; | ||
_logger.LogError(request, exMessage); | ||
return Result.Fail(exMessage); | ||
} | ||
|
||
try | ||
{ | ||
_repositoryWrapper.HistoricalContextRepository.Delete(contextToDelete); | ||
await _repositoryWrapper.SaveChangesAsync(); | ||
return Result.Ok(request.contextId); | ||
} | ||
catch(Exception ex) | ||
{ | ||
_logger.LogError(request, ex.Message); | ||
return Result.Fail(ex.Message); | ||
} | ||
} | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
...eetcode.BLL/MediatR/Timeline/HistoricalContext/GetById/GetHistoricalContextByIdHandler.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,46 @@ | ||
using AutoMapper; | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
using Streetcode.BLL.Interfaces.Logging; | ||
using Streetcode.DAL.Repositories.Interfaces.Base; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.GetById | ||
{ | ||
public class GetHistoricalContextByIdHandler : IRequestHandler<GetHistoricalContextByIdQuery, Result<HistoricalContextDTO>> | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IRepositoryWrapper _repository; | ||
private readonly ILoggerService _loggerService; | ||
|
||
public GetHistoricalContextByIdHandler(IMapper mapper, IRepositoryWrapper repository, ILoggerService loggerService) | ||
{ | ||
_mapper = mapper; | ||
_repository = repository; | ||
_loggerService = loggerService; | ||
} | ||
|
||
public async Task<Result<HistoricalContextDTO>> Handle(GetHistoricalContextByIdQuery request, CancellationToken cancellationToken) | ||
{ | ||
var context = await _repository.HistoricalContextRepository.GetFirstOrDefaultAsync(j => j.Id == request.contextId); | ||
|
||
if (context is null) | ||
{ | ||
string exceptionMessege = $"No context found by entered Id - {request.contextId}"; | ||
_loggerService.LogError(request, exceptionMessege); | ||
return Result.Fail(exceptionMessege); | ||
} | ||
|
||
try | ||
{ | ||
var contextDto = _mapper.Map<HistoricalContextDTO>(context); | ||
return Result.Ok(contextDto); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_loggerService.LogError(request, ex.Message); | ||
return Result.Fail(ex.Message); | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...treetcode.BLL/MediatR/Timeline/HistoricalContext/GetById/GetHistoricalContextByIdQuery.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,8 @@ | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.GetById; | ||
|
||
public record GetHistoricalContextByIdQuery(int contextId) | ||
: IRequest<Result<HistoricalContextDTO>>; |
46 changes: 46 additions & 0 deletions
46
...e.BLL/MediatR/Timeline/HistoricalContext/GetByTitle/GetHistoricalContextByTitleHandler.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,46 @@ | ||
using AutoMapper; | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
using Streetcode.BLL.Interfaces.Logging; | ||
using Streetcode.BLL.MediatR.Timeline.HistoricalContext.GetById; | ||
using Streetcode.DAL.Repositories.Interfaces.Base; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.GetByTitle; | ||
|
||
public class GetHistoricalContextByTitleHandler : IRequestHandler<GetHistoricalContextByTitleQuery, Result<HistoricalContextDTO>> | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IRepositoryWrapper _repository; | ||
private readonly ILoggerService _loggerService; | ||
|
||
public GetHistoricalContextByTitleHandler(IMapper mapper, IRepositoryWrapper repository, ILoggerService loggerService) | ||
{ | ||
_mapper = mapper; | ||
_repository = repository; | ||
_loggerService = loggerService; | ||
} | ||
|
||
public async Task<Result<HistoricalContextDTO>> Handle(GetHistoricalContextByTitleQuery request, CancellationToken cancellationToken) | ||
{ | ||
var context = await _repository.HistoricalContextRepository.GetFirstOrDefaultAsync(j => j.Title == request.title); | ||
|
||
if (context is null) | ||
{ | ||
string exceptionMessege = $"No context found by title - {request.title}"; | ||
_loggerService.LogError(request, exceptionMessege); | ||
return Result.Fail(exceptionMessege); | ||
} | ||
|
||
try | ||
{ | ||
var contextDto = _mapper.Map<HistoricalContextDTO>(context); | ||
return Result.Ok(contextDto); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_loggerService.LogError(request, ex.Message); | ||
return Result.Fail(ex.Message); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ode.BLL/MediatR/Timeline/HistoricalContext/GetByTitle/GetHistoricalContextByTitleQuery.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,8 @@ | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.GetByTitle; | ||
|
||
public record GetHistoricalContextByTitleQuery(string title) | ||
: IRequest<Result<HistoricalContextDTO>>; |
8 changes: 8 additions & 0 deletions
8
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Update/UpdateHistoricalContextCommand.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,8 @@ | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Update | ||
{ | ||
public record UpdateHistoricalContextCommand(HistoricalContextDTO HistoricalContext) : IRequest<Result<HistoricalContextDTO>>; | ||
} |
65 changes: 65 additions & 0 deletions
65
...treetcode.BLL/MediatR/Timeline/HistoricalContext/Update/UpdateHistoricalContextHandler.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,65 @@ | ||
using AutoMapper; | ||
using FluentResults; | ||
using MediatR; | ||
using Streetcode.BLL.DTO.Timeline; | ||
using Streetcode.BLL.Interfaces.Logging; | ||
using Streetcode.DAL.Repositories.Interfaces.Base; | ||
|
||
namespace Streetcode.BLL.MediatR.Timeline.HistoricalContext.Update | ||
{ | ||
public class | ||
UpdateHistoricalContextHandler : IRequestHandler<UpdateHistoricalContextCommand, Result<HistoricalContextDTO>> | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IRepositoryWrapper _repositoryWrapper; | ||
private readonly ILoggerService _logger; | ||
|
||
public UpdateHistoricalContextHandler(IRepositoryWrapper repository, IMapper mapper, ILoggerService logger) | ||
{ | ||
_repositoryWrapper = repository; | ||
_mapper = mapper; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<Result<HistoricalContextDTO>> Handle( | ||
UpdateHistoricalContextCommand request, | ||
CancellationToken cancellationToken) | ||
{ | ||
var historicalContext = | ||
await _repositoryWrapper.HistoricalContextRepository.GetFirstOrDefaultAsync(x => | ||
x.Id == request.HistoricalContext.Id); | ||
if (historicalContext is null) | ||
{ | ||
string exMessage = $"No context found by entered Id - {request.HistoricalContext.Id}"; | ||
_logger.LogError(request, exMessage); | ||
return Result.Fail(exMessage); | ||
} | ||
|
||
var historicalContextRepeat = await _repositoryWrapper.HistoricalContextRepository.GetFirstOrDefaultAsync( | ||
x => | ||
x.Title == request.HistoricalContext.Title); | ||
|
||
if (historicalContextRepeat is not null) | ||
{ | ||
string exMessage = $"There is already a context with title - {request.HistoricalContext.Title}"; | ||
_logger.LogError(request, exMessage); | ||
return Result.Fail(exMessage); | ||
} | ||
|
||
try | ||
{ | ||
/* have some shitty code right here, if you delete the DAL.Entities.Timeline. part it will show error | ||
even if you have using Streetcode.DAL.Entities.Timeline; so sad :( */ | ||
var contextToUpdate = _mapper.Map<DAL.Entities.Timeline.HistoricalContext>(request.HistoricalContext); | ||
_repositoryWrapper.HistoricalContextRepository.Update(contextToUpdate); | ||
await _repositoryWrapper.SaveChangesAsync(); | ||
return Result.Ok(_mapper.Map<HistoricalContextDTO>(contextToUpdate)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(request, ex.Message); | ||
return Result.Fail(ex.Message); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U need to change this back to:
"DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true"