-
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: search user feature and disable show user who deleted
- Loading branch information
Showing
7 changed files
with
76 additions
and
4 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
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/open3r/openmusic/domain/user/repository/UserQueryRepository.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,10 @@ | ||
package com.open3r.openmusic.domain.user.repository | ||
|
||
import com.open3r.openmusic.domain.user.domain.entity.UserEntity | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
|
||
interface UserQueryRepository { | ||
fun findAll(): List<UserEntity> | ||
fun searchUsers(keyword: String, pageable: Pageable): Page<UserEntity> | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/com/open3r/openmusic/domain/user/repository/impl/UserQueryRepositoryImpl.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,41 @@ | ||
package com.open3r.openmusic.domain.user.repository.impl | ||
|
||
import com.open3r.openmusic.domain.user.domain.entity.QUserEntity.userEntity | ||
import com.open3r.openmusic.domain.user.domain.entity.UserEntity | ||
import com.open3r.openmusic.domain.user.domain.enums.UserStatus | ||
import com.open3r.openmusic.domain.user.repository.UserQueryRepository | ||
import com.open3r.openmusic.global.util.paginate | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.PageImpl | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Repository | ||
class UserQueryRepositoryImpl( | ||
private val jpaQueryFactory: JPAQueryFactory | ||
) : UserQueryRepository { | ||
@Transactional | ||
override fun findAll(): List<UserEntity> { | ||
return jpaQueryFactory.selectFrom(userEntity) | ||
.where(userEntity.status.eq(UserStatus.ACTIVE)) | ||
.fetch() | ||
} | ||
|
||
@Transactional | ||
override fun searchUsers(keyword: String, pageable: Pageable): Page<UserEntity> { | ||
val count = jpaQueryFactory.select(userEntity.count()) | ||
.from(userEntity) | ||
.where(userEntity.status.eq(UserStatus.ACTIVE), userEntity.nickname.containsIgnoreCase(keyword)) | ||
.fetchFirst() ?: 0 | ||
|
||
val users = jpaQueryFactory.selectFrom(userEntity) | ||
.where(userEntity.status.eq(UserStatus.ACTIVE), userEntity.nickname.containsIgnoreCase(keyword)) | ||
.paginate(pageable) | ||
.orderBy(userEntity.createdAt.desc()) | ||
.fetch() | ||
|
||
return PageImpl(users, pageable, count) | ||
} | ||
} |
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