From cb7108bcea1f25f6e531720b4dfc59a220e25601 Mon Sep 17 00:00:00 2001 From: Shashank Verma Date: Wed, 1 Nov 2023 14:33:08 +0530 Subject: [PATCH] repository: Delete by attribute instead of object Signed-off-by: Shashank Verma --- .../mnnit/moticlubs/repository/AdminRepository.kt | 14 +++++++++++++- .../mnnit/moticlubs/repository/MemberRepository.kt | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt index eee0482..c3c6abc 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/AdminRepository.kt @@ -58,5 +58,17 @@ class AdminRepository( ) @Transactional - fun delete(admin: Admin): Mono = db.delete(admin).then() + fun delete(admin: Admin): Mono = db + .delete( + Query.query( + Criteria + .where(Admin::cid.name) + .`is`(admin.cid) + .and( + Criteria.where(Admin::uid.name).`is`(admin.uid), + ), + ), + Admin::class.java, + ) + .then() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt b/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt index 6473fae..12924dc 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/repository/MemberRepository.kt @@ -40,7 +40,19 @@ class MemberRepository( @Transactional fun delete(member: Member): Mono = exists(member) - .flatMap { if (it) db.delete(member) else Mono.just(member) } + .flatMap { + if (it) { + db.delete( + Query.query( + Criteria.where(Member::uid.name).`is`(member.uid) + .and(Criteria.where(Member::chid.name).`is`(member.chid)), + ), + Member::class.java, + ) + } else { + Mono.just(member) + } + } .then() @Transactional