@@ -4,47 +4,55 @@ import com.querydsl.jpa.impl.JPAQueryFactory
4
4
import io.github.v1servicenotification.category.Category
5
5
import io.github.v1servicenotification.detail.spi.PostDetailSettingRepositorySpi
6
6
import io.github.v1servicenotification.domain.category.domain.QCategoryEntity.categoryEntity
7
+ import io.github.v1servicenotification.domain.category.domain.repository.CategoryRepository
7
8
import io.github.v1servicenotification.domain.category.mapper.CategoryMapper
8
9
import io.github.v1servicenotification.domain.setting.domain.QSettingEntity.settingEntity
9
- import io.github.v1servicenotification.domain.setting.domain.SettingEntity
10
10
import io.github.v1servicenotification.domain.setting.domain.SettingId
11
- import io.github.v1servicenotification.domain.setting.mapper.SettingMapper
12
- import io.github.v1servicenotification.setting.Setting
13
11
import io.github.v1servicenotification.setting.spi.SettingRepositorySpi
14
12
import org.springframework.stereotype.Repository
15
13
import java.util.UUID
14
+ import javax.transaction.Transactional
16
15
17
16
@Repository
18
17
class CustomSettingRepositoryImpl (
19
18
private val settingRepository : SettingRepository ,
20
- private val settingMapper : SettingMapper ,
21
19
private val categoryMapper : CategoryMapper ,
22
- private val jpaQueryFactory : JPAQueryFactory
20
+ private val jpaQueryFactory : JPAQueryFactory ,
21
+ private val categoryRepository : CategoryRepository ,
23
22
) : SettingRepositorySpi, PostDetailSettingRepositorySpi {
24
- override fun saveSetting (category : Category , userId : UUID , isActivated : Boolean ): Setting {
25
- return settingMapper.settingEntityToDomain(
26
- settingRepository.save(
27
- SettingEntity (
28
- settingId = getSettingId(category, userId),
29
- isActivated = isActivated
23
+
24
+ @Transactional
25
+ override fun updateAllSetting (categoryIds : List <UUID >, userId : UUID , isActivated : Boolean ) {
26
+ categoryIds.forEach {
27
+ jpaQueryFactory
28
+ .update(settingEntity)
29
+ .set(settingEntity.isActivated, isActivated)
30
+ .where(
31
+ settingEntity.settingId.categoryEntity.id.eq(it)
32
+ .and (settingEntity.settingId.userId.eq(userId))
30
33
)
31
- )
32
- )
34
+ .execute( )
35
+ }
33
36
}
34
37
35
- override fun updateSetting (category : Category , userId : UUID , isActivated : Boolean ): Setting {
36
- return settingMapper.settingEntityToDomain(
37
- settingRepository.save(
38
- SettingEntity (
39
- settingId = getSettingId(category, userId),
40
- isActivated = isActivated
41
- )
38
+ override fun settingExist (categoryIds : List <UUID >, userId : UUID ): Boolean {
39
+ return getSettingIdList(categoryIds, userId).map { settingId ->
40
+ settingRepository.existsById(settingId)
41
+ }.all { it }
42
+ }
43
+
44
+ private fun getSettingIdList (categoryIds : List <UUID >, userId : UUID ): List <SettingId > {
45
+ return getCategoryById(categoryIds).map { category ->
46
+ SettingId (
47
+ userId = userId,
48
+ categoryEntity = categoryMapper.categoryDomainToEntity(category)
42
49
)
43
- )
50
+ }
44
51
}
45
52
46
- override fun settingExist (category : Category , userId : UUID ): Boolean {
47
- return settingRepository.existsById(getSettingId(category, userId))
53
+ private fun getCategoryById (categoryId : List <UUID >): List <Category > {
54
+ return categoryRepository.findAllById(categoryId)
55
+ .map { categoryMapper.categoryEntityToDomain(it) }
48
56
}
49
57
50
58
override fun queryActivatedCategory (userId : UUID ): List <Category > {
@@ -66,13 +74,6 @@ class CustomSettingRepositoryImpl(
66
74
}
67
75
}
68
76
69
- private fun getSettingId (category : Category , userId : UUID ): SettingId {
70
- return SettingId (
71
- userId = userId,
72
- categoryEntity = categoryMapper.categoryDomainToEntity(category)
73
- )
74
- }
75
-
76
77
override fun findAllUserIdByTopicAndIsActivated (topic : String , isActivated : Boolean ): List <UUID > {
77
78
return jpaQueryFactory
78
79
.select(settingEntity.settingId.userId)
0 commit comments