Skip to content
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
wants to merge 67 commits into
base: develop
Choose a base branch
from

Conversation

HlibBondarev
Copy link
Contributor

@HlibBondarev HlibBondarev commented Aug 27, 2024

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().

…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.
…ementoController and WorkshopMementoController.
…eAsync(), SetValueToCacheAsync() and RemoveFromCacheAsync().
…ds - SetMementoValueAsync(), GetMementoValueAsync() and RemoveMementoAsync().
… class methods - RestoreMemento(), CreateMemento() and GetMementoKey().
Copy link
Contributor

@VadymLevkovskyi VadymLevkovskyi left a 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.Redis/CacheService.cs Outdated Show resolved Hide resolved
OutOfSchool/OutOfSchool.Redis/CacheService.cs Outdated Show resolved Hide resolved
OutOfSchool/OutOfSchool.Redis/CacheService.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.
…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.
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.
@HlibBondarev HlibBondarev changed the title Hlib bondarev/store memento in cache Hlib bondarev/store draft in cache Sep 22, 2024
Copy link

sonarcloud bot commented Oct 11, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants