-
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.
* feat: 그룹 태그 기능 추가 * refactor: 그룹 태그 기능 추가 코드 리뷰 반영
- Loading branch information
1 parent
f47b99b
commit 329aa29
Showing
41 changed files
with
363 additions
and
59 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
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/hero/alignlab/config/database/QueryDslConfig.kt
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,16 @@ | ||
package com.hero.alignlab.config.database | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class QueryDslConfig { | ||
@PersistenceContext(name = "heroEntityManager") | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Bean | ||
fun jpaQueryFactory(): JPAQueryFactory = JPAQueryFactory(entityManager) | ||
} |
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
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/hero/alignlab/domain/group/application/GroupTagService.kt
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,62 @@ | ||
package com.hero.alignlab.domain.group.application | ||
|
||
import com.hero.alignlab.domain.group.domain.GroupTag | ||
import com.hero.alignlab.domain.group.domain.GroupTagMap | ||
import com.hero.alignlab.domain.group.infrastructure.GroupTagMapRepository | ||
import com.hero.alignlab.domain.group.infrastructure.GroupTagRepository | ||
import com.hero.alignlab.domain.group.model.request.CreateGroupTagRequest | ||
import com.hero.alignlab.exception.ErrorCode | ||
import com.hero.alignlab.exception.InvalidRequestException | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class GroupTagService( | ||
private val groupTagRepository: GroupTagRepository, | ||
private val groupTagMapRepository: GroupTagMapRepository, | ||
) { | ||
@Transactional | ||
fun saveSync(request: CreateGroupTagRequest): List<GroupTag> { | ||
val existsTags = groupTagRepository.findAllByNameIn(request.tagNames) | ||
val existsTagNames = existsTags.map { tag -> tag.name } | ||
|
||
val needToCreateTags = request.tagNames | ||
.filterNot { tagName -> existsTagNames.contains(tagName) } | ||
.map { tagName -> GroupTag(name = tagName) } | ||
|
||
val createdTags = groupTagRepository.saveAll(needToCreateTags) | ||
|
||
(createdTags + existsTags) | ||
.map { tag -> GroupTagMap(groupId = request.groupId, tagId = tag.id) } | ||
.run { groupTagMapRepository.saveAll(this) } | ||
|
||
return (createdTags + existsTags) | ||
} | ||
|
||
@Transactional | ||
fun deleteGroupTagMapSyncByGroupId(groupId: Long) { | ||
/** | ||
* 왜, QueryDSL로 삭제를 했는지 | ||
* https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/event/internal/AbstractFlushingEventListener.html | ||
*/ | ||
groupTagRepository.deleteGroupTagMapByGroupId(groupId) | ||
} | ||
|
||
suspend fun findByGroupId(groupId: Long): List<GroupTag> { | ||
return withContext(Dispatchers.IO) { | ||
groupTagRepository.findByGroupId(groupId) | ||
} | ||
} | ||
|
||
fun validateGroupTag(tagNames: List<String>) { | ||
if (tagNames.size > 3) { | ||
throw InvalidRequestException(ErrorCode.OVER_COUNT_GROUP_TAG_ERROR) | ||
} | ||
|
||
if (tagNames.size != tagNames.distinct().size) { | ||
throw InvalidRequestException(ErrorCode.DUPLICATE_GROUP_TAG_NAME_ERROR) | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/hero/alignlab/domain/group/domain/GroupTag.kt
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,15 @@ | ||
package com.hero.alignlab.domain.group.domain | ||
|
||
import com.hero.alignlab.domain.common.domain.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "`group_tag`") | ||
data class GroupTag( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0L, | ||
|
||
@Column(name = "name") | ||
var name: String, | ||
) : BaseEntity() |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/hero/alignlab/domain/group/domain/GroupTagMap.kt
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,18 @@ | ||
package com.hero.alignlab.domain.group.domain | ||
|
||
import com.hero.alignlab.domain.common.domain.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "`group_tag_map`") | ||
data class GroupTagMap ( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0L, | ||
|
||
@Column(name = "group_id") | ||
val groupId: Long, | ||
|
||
@Column(name = "tag_id") | ||
val tagId: Long | ||
) : BaseEntity() |
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
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepository.kt
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,9 @@ | ||
package com.hero.alignlab.domain.group.infrastructure | ||
|
||
import com.hero.alignlab.domain.group.domain.Group | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
|
||
interface GroupQRepository { | ||
fun findByTagNameAndPage(tagName: String?, pageable: Pageable): Page<Group> | ||
} |
Oops, something went wrong.