-
Notifications
You must be signed in to change notification settings - Fork 6
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
Hlib bondarev/store draft in cache #1551
Open
HlibBondarev
wants to merge
67
commits into
develop
Choose a base branch
from
HlibBondarev/store_memento_in_cache
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
…sCacheAsync(), SetValueToRedisCacheAsync() and RemoveValueFromRedisCacheAsync(); 2) Implemented IRedisCacheService in CacheService(); 3) Created IMemento, IMementoService<T> and IStorage interfaces and imolemented them in classes - Memento, MementoService<T> and Storage. 4) Created abstract controller BaseMementoController<T> with actions StoreMemento, RestoreMemento and RemoveMemento. 5) Created WorkshopMementoController inherited from BaseMementoController<T> whit T = RequiredWorkshopMemento.
1) Renamed IRedisCacheService to ICrudCacheService; 2) Renamed methods in ICrudCacheService (new names - GetValueFromCacheAsync(), SetValueToCacheAsync() and RemoveFromCacheAsync()); 3) Changed methods GetOrAddAsync<T>() (used GetValueFromCacheAsync(), SetValueToCacheAsync() in it) and RemoveAsync() (used method cache.Remove(key) instead of cache.RemoveAsync(key)).
…, areaadmin, regionadmin, techadmin')] for methods StoreMemento(), RestoreMemento() and RemoveMemento() in BaseMementoController<T>.
2) Changed logging in Storage class - added throwing InvalidOperationException(errMessage). 3) Fixed the logic of GetValueFromCacheAsync method in CacheService class.
… of BaseMementoController<T>.
… validation its properties.
…ementoController and WorkshopMementoController.
…eAsync(), SetValueToCacheAsync() and RemoveFromCacheAsync().
…ds - SetMementoValueAsync(), GetMementoValueAsync() and RemoveMementoAsync().
… class methods - RestoreMemento(), CreateMemento() and GetMementoKey().
HlibBondarev
requested review from
h4wk13,
DmyMi,
MrVenik,
VadymLevkovskyi and
OleksSavchenko
August 27, 2024 05:21
VadymLevkovskyi
requested changes
Aug 27, 2024
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.
Naming, logic, design - please see other comments. All tests weren't reviewed, as they probably will be rewritten.
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/Storage.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/Storage.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/MementoService.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/MementoService.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/MementoService.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.BusinessLogic/Services/Memento/Storage.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi/Controllers/V1/BaseMementoController.cs
Outdated
Show resolved
Hide resolved
…m method names. 2) Added validation (ModelState.IsValid) in StoreMemento action of BaseMementoController<T>. 3) Added NUnit tests to WorkshopMementoControllerTests class for method - StoreMemento().
…ception.ThrowIfNull(). Fixed unit tests in CacheServiceTests.
… appropriated service classes and tests. 2) Fixed unit tests in DraftStorageServiceTests.
2) Renamed WorkshopMementoController to WorkshopDraftStorageController. 3) Renamed WorkshopMementoControllerTests to WorkshopDraftStorageControllerTests.
…d var returnValue of T type.
…ing exception when valueToRemove == null. 2) Changed RestoreAsync() method of CacheService class - RestoreAsync returned Task<T> instead of Task<T?>.
…f the OutOfSchool.BusinessLogic project. 2) Renamed the appropriate Using directives.
2) Removed dependency injection (WorkshopConverter class) from Startup class. 3) Deleted IncompletedWorkshops folder with dtos - WorkshopWithRequiredPropertiesDto, WorkshopWithDescriptionDto, WorkshopWithContactsDto and WorkshopWithTeachersDto. 4) Restored WorkshopBaseDto code from develop branch. 5) Changed WorkshopDraftStorageController code - used IDraftStorageService<WorkshopBaseDto> argument. 6) Changed unit tests in DraftStorageServiceTests and WorkshopDraftStorageControllerTests classes.
OutOfSchool/OutOfSchool.WebApi.Tests/Redis/CacheServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Redis/CacheServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Redis/CacheServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Redis/CacheServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Services/DraftStorage/DraftStorageServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Services/DraftStorage/DraftStorageServiceTests.cs
Outdated
Show resolved
Hide resolved
OutOfSchool/OutOfSchool.WebApi.Tests/Services/DraftStorage/DraftStorageServiceTests.cs
Outdated
Show resolved
Hide resolved
1) Used Bogus random string for generating key and value. 2) Changed It.IsAny<> to specific known values. 3) Used VerifyAll() method for tests.
…trollerTests classes: 1) Used Bogus random string for generating key and cacheKey. 2) Used Bogus.Facker for creating Workshop draft with random properties. 3) Changed It.IsAny<> to specific known values. 4) Used VerifyAll() method for tests.
…of Verify() for tests.
HlibBondarev
changed the title
Hlib bondarev/store memento in cache
Hlib bondarev/store draft in cache
Sep 22, 2024
Quality Gate passedIssues Measures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Roles: provider, ministryadmin, areaadmin, regionadmin, techadmin.
Story: As a User with the above roles, I want to be able to save the field values before saving the Workshop (Provider, etc.) in the DB. So that if the Workshop (Provider, etc.) creation is terminated, I can restore the values of previously filled fields.
Solution: Created DraftStorageService. It captures and exports the state of an object (entity) outside of it so that the state of the original object can be restored later. Redis was used to store intermediate values of entity fields.
1) Created IDraftStorageService interface and implemented it in StorageService class .
2) Created IReadWriteCacheService interface with methods - ReadAsync(), WriteAsync() and RemoveAsync().
3) Implemented IReadWriteCacheService interface in CacheService class.
4) Refactored CacheService class - used ReadAsync() and WriteAsync() methods in GetOrAddAsync() method.
5) Fixed RemoveAsync() method - instead of cache.RemoveAsync(key) used cache.Remove(key).
6) Created abstract generic controller DraftStorageController with actions StoreDraft, RestoreDraft and RemoveDraft.
7) Created WorkshopDraftStorageController inherited from DraftStorageController with T = WorkshopBaseDto.
8) Added tests to CacheServiceTests class for methods - ReadAsync(), WriteAsync() and RemoveAsync().
9) Created DraftStorageServiceTests class with NUnit tests for DraftStorageService class methods - RestoreAsync(), CreateAsync() and RemoveAsync().