Skip to content

Commit

Permalink
fix(security): add securityservice as dependency to ICrudService to a…
Browse files Browse the repository at this point in the history
…uto update updatedBy on save
  • Loading branch information
Amar97 committed Mar 28, 2024
1 parent 1540e4d commit 2c41be0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = nl.asrr
version = 0.0.21
version = 0.0.22
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface ICrudEntity {
val id: String
val created: ZonedDateTime
val createdBy: String
val updated: ZonedDateTime
val updatedBy: String
var updated: ZonedDateTime
var updatedBy: String
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright 2017-2022 ASRR B.V. */
package nl.asrr.core.generics.service

import nl.asrr.core.auth.service.ISecurityService
import nl.asrr.core.exceptions.NotFoundException
import nl.asrr.core.generics.model.ICrudEntity
import nl.asrr.core.generics.model.IEntitySearch
Expand All @@ -18,16 +19,20 @@ import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
import org.springframework.data.mongodb.core.query.TextCriteria
import org.springframework.data.mongodb.core.query.UntypedExampleMatcher
import java.time.ZonedDateTime

/**
* Generic service for CRUD operations
*/
abstract class ICrudService<T : ICrudEntity>(
open val repository: ICrudRepository<T>,
open val mongoTemplate: MongoTemplate
open val mongoTemplate: MongoTemplate,
open val securityService: ISecurityService
) {

open fun save(entity: T): T {
entity.updated = ZonedDateTime.now()
entity.updatedBy = securityService.getUserId()
return repository.save(entity)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright 2017-2022 ASRR B.V. */
package nl.asrr.core.generics.service

import nl.asrr.core.auth.service.ISecurityService
import nl.asrr.core.generics.model.ITenantCrudEntity
import nl.asrr.core.generics.repository.ITenantCrudRepository
import org.springframework.data.domain.Page
Expand All @@ -10,8 +11,9 @@ import org.springframework.data.mongodb.core.query.TextCriteria

abstract class ITenantCrudService<T : ITenantCrudEntity>(
override val repository: ITenantCrudRepository<T>,
override val mongoTemplate: MongoTemplate
) : ICrudService<T>(repository, mongoTemplate) {
override val mongoTemplate: MongoTemplate,
override val securityService: ISecurityService
) : ICrudService<T>(repository, mongoTemplate, securityService) {

fun findAllByTenantId(tenantId: String): List<T> {
return repository.findAllByTenantId(tenantId)
Expand Down

0 comments on commit 2c41be0

Please sign in to comment.