-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from GSM-MSG/115-accepted-user-list-api-not-f…
…untion 회원가입 수락 유저 리스트 api
- Loading branch information
Showing
5 changed files
with
47 additions
and
78 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
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
59 changes: 16 additions & 43 deletions
59
src/main/kotlin/com/msg/gauth/domain/user/services/AcceptedUserService.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 |
---|---|---|
@@ -1,60 +1,33 @@ | ||
package com.msg.gauth.domain.user.services | ||
|
||
import com.msg.gauth.domain.user.User | ||
import com.msg.gauth.domain.user.enums.UserRole | ||
import com.msg.gauth.domain.user.enums.UserState | ||
import com.msg.gauth.domain.user.presentation.dto.response.SingleAcceptedUserResDto | ||
import com.msg.gauth.domain.user.repository.UserRepository | ||
import com.msg.gauth.domain.user.specification.UserSpecification | ||
import com.msg.gauth.global.annotation.service.ReadOnlyService | ||
import org.springframework.data.jpa.domain.Specification | ||
import javax.persistence.criteria.CriteriaBuilder | ||
import javax.persistence.criteria.CriteriaQuery | ||
import javax.persistence.criteria.Root | ||
import org.springframework.data.domain.Pageable | ||
|
||
@ReadOnlyService | ||
class AcceptedUserService( | ||
private val userRepository: UserRepository, | ||
) { | ||
fun execute(grade: Int, classNum: Int, keyword: String): List<SingleAcceptedUserResDto> { | ||
fun execute(grade: Int, classNum: Int, name: String, pageable: Pageable): List<SingleAcceptedUserResDto> { | ||
val userList: List<User> | ||
= when { | ||
grade == 0 && classNum == 0 && name == "" -> userRepository.findAllByStateOrderByGrade(UserState.CREATED, pageable) | ||
|
||
val users: List<User> | ||
= if(grade == 0 && classNum == 0 && keyword == "0") | ||
listAcceptedUser() | ||
else { | ||
searchUser(grade, classNum, keyword) | ||
} | ||
|
||
|
||
return users.filter { user -> user.roles.equals(UserRole.ROLE_STUDENT) && user.state == UserState.CREATED } | ||
.map { user -> | ||
SingleAcceptedUserResDto( | ||
user.id, | ||
user.name!!, | ||
user.email, | ||
user.grade!!, | ||
user.classNum!!, | ||
user.num!!, | ||
user.profileUrl | ||
) | ||
} | ||
|
||
} | ||
grade == 0 && classNum == 0 -> userRepository.findAllByStateAndNameContainingOrderByGrade(UserState.CREATED, name, pageable) | ||
classNum == 0 && name == "" -> userRepository.findAllByStateAndGradeOrderByGrade(UserState.CREATED, classNum, pageable) | ||
grade == 0 && name == ""-> userRepository.findAllByStateAndClassNumOrderByGrade(UserState.CREATED, grade, pageable) | ||
|
||
private fun listAcceptedUser(): List<User> = | ||
userRepository.findAllByState(UserState.CREATED) | ||
grade == 0 -> userRepository.findAllByStateAndClassNumAndNameContainingOrderByGrade(UserState.CREATED, classNum, name, pageable) | ||
classNum == 0 -> userRepository.findAllByStateAndGradeAndNameContainingOrderByGrade(UserState.CREATED, grade, name, pageable) | ||
name == "" -> userRepository.findAllByStateAndGradeAndClassNumOrderByGrade(UserState.CREATED, grade, classNum, pageable) | ||
|
||
private fun searchUser(grade: Int, classNum: Int, keyword: String): List<User> { | ||
val spec: Specification<User> = | ||
Specification { _: Root<User>?, _: CriteriaQuery<*>?, _: CriteriaBuilder? -> null } | ||
|
||
if(grade != 0) | ||
spec.and(UserSpecification.equalGrade(grade)) | ||
if(classNum != 0) | ||
spec.and(UserSpecification.equalClassNum(classNum)) | ||
if(keyword != "0") | ||
spec.and(UserSpecification.containKeyword(keyword)) | ||
|
||
return userRepository.findAll(spec) | ||
else -> userRepository.findAllByStateAndGradeAndClassNumAndNameContainingOrderByGrade(UserState.CREATED, grade, classNum, name, pageable) | ||
} | ||
return userList.map { | ||
SingleAcceptedUserResDto(it) | ||
} | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
src/main/kotlin/com/msg/gauth/domain/user/specification/UserSpecification.kt
This file was deleted.
Oops, something went wrong.