-
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.
[240] Add the ability to delete an account
Bug: #240 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
ca98e62
commit a2e728e
Showing
46 changed files
with
1,246 additions
and
262 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
33 changes: 33 additions & 0 deletions
33
...c/main/java/com/svalyn/studio/application/controllers/account/dto/DeleteAccountInput.java
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,33 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.svalyn.studio.application.controllers.account.dto; | ||
|
||
import com.svalyn.studio.application.controllers.dto.IInput; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Input used to delete an account. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record DeleteAccountInput(@NotNull UUID id, @NotNull String username) implements IInput { | ||
} |
64 changes: 64 additions & 0 deletions
64
...om/svalyn/studio/application/listeners/activity/ActivityCleanerOnAccountDeletedEvent.java
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,64 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.svalyn.studio.application.listeners.activity; | ||
|
||
import com.svalyn.studio.domain.account.events.AccountDeletedEvent; | ||
import com.svalyn.studio.domain.activity.repositories.IActivityEntryRepository; | ||
import com.svalyn.studio.domain.activity.repositories.IOrganizationActivityEntryRepository; | ||
import com.svalyn.studio.domain.activity.repositories.IProjectActivityEntryRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Used to delete account activities. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class ActivityCleanerOnAccountDeletedEvent { | ||
|
||
private final IActivityEntryRepository activityEntryRepository; | ||
|
||
private final IOrganizationActivityEntryRepository organizationActivityEntryRepository; | ||
|
||
private final IProjectActivityEntryRepository projectActivityEntryRepository; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(ActivityCleanerOnAccountDeletedEvent.class); | ||
|
||
public ActivityCleanerOnAccountDeletedEvent(IActivityEntryRepository activityEntryRepository, IOrganizationActivityEntryRepository organizationActivityEntryRepository, IProjectActivityEntryRepository projectActivityEntryRepository) { | ||
this.activityEntryRepository = Objects.requireNonNull(activityEntryRepository); | ||
this.organizationActivityEntryRepository = Objects.requireNonNull(organizationActivityEntryRepository); | ||
this.projectActivityEntryRepository = Objects.requireNonNull(projectActivityEntryRepository); | ||
} | ||
|
||
@Transactional | ||
@TransactionalEventListener | ||
public void onAccountDeletedEvent(AccountDeletedEvent event) { | ||
logger.info(event.toString()); | ||
this.organizationActivityEntryRepository.deleteAllByUserId(event.account().getId()); | ||
this.projectActivityEntryRepository.deleteAllByUserId(event.account().getId()); | ||
this.activityEntryRepository.deleteAllByUserId(event.account().getId()); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...n/studio/application/listeners/organization/OrganizationCleanerOnAccountDeletedEvent.java
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,56 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.svalyn.studio.application.listeners.organization; | ||
|
||
import com.svalyn.studio.domain.account.events.AccountDeletedEvent; | ||
import com.svalyn.studio.domain.organization.Organization; | ||
import com.svalyn.studio.domain.organization.repositories.IOrganizationRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Used to delete the organizations owned by an account. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class OrganizationCleanerOnAccountDeletedEvent { | ||
private final IOrganizationRepository organizationRepository; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(OrganizationCleanerOnAccountDeletedEvent.class); | ||
|
||
public OrganizationCleanerOnAccountDeletedEvent(IOrganizationRepository organizationRepository) { | ||
this.organizationRepository = Objects.requireNonNull(organizationRepository); | ||
} | ||
|
||
@Transactional | ||
@TransactionalEventListener | ||
public void onAccountDeletedEvent(AccountDeletedEvent event) { | ||
logger.info(event.toString()); | ||
var organizations = this.organizationRepository.findAllOwnedBy(event.account().getId()); | ||
organizations.forEach(Organization::dispose); | ||
this.organizationRepository.deleteAll(organizations); | ||
} | ||
} |
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
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
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
39 changes: 39 additions & 0 deletions
39
...dio-domain/src/main/java/com/svalyn/studio/domain/account/events/AccountDeletedEvent.java
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,39 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.svalyn.studio.domain.account.events; | ||
|
||
import com.svalyn.studio.domain.Profile; | ||
import com.svalyn.studio.domain.account.Account; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Event fired when an account is deleted. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record AccountDeletedEvent( | ||
@NotNull UUID id, | ||
@NotNull Instant createdOn, | ||
@NotNull Profile createdBy, | ||
@NotNull Account account) implements IAccountEvent { | ||
} |
Oops, something went wrong.