-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 관리자 계정 조회 #80
[Feat] 관리자 계정 조회 #80
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.haedal.zzansuni.admin.controller; | ||
|
||
import lombok.Builder; | ||
import org.haedal.zzansuni.user.domain.UserModel; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class AdminRes { | ||
@Builder | ||
public record ManagerAndAdmin( | ||
Long id, | ||
String email, | ||
String name, | ||
String role, | ||
LocalDateTime createdAt | ||
) { | ||
public static ManagerAndAdmin from(UserModel.Admin managerAndAdmin) { | ||
return ManagerAndAdmin.builder() | ||
.id(managerAndAdmin.id()) | ||
.email(managerAndAdmin.email()) | ||
.name(managerAndAdmin.nickname()) | ||
.role(managerAndAdmin.role().name()) | ||
.createdAt(managerAndAdmin.createdAt()) | ||
.build(); | ||
} | ||
public static List<ManagerAndAdmin> from(List<UserModel.Admin> managerAndAdmins) { | ||
return managerAndAdmins.stream() | ||
.map(ManagerAndAdmin::from) | ||
.toList(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.haedal.zzansuni.user.domain; | ||
|
||
import lombok.Builder; | ||
import org.haedal.zzansuni.global.security.Role; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
@@ -71,5 +73,23 @@ public String toString() { | |
} | ||
} | ||
|
||
@Builder | ||
public record Admin( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유저모델에 Role 추가하고, API response에서 바꾸는거는 어떻게생각하세요?? 백오피스에서 일반유저로 로그인시, 권한확인을 내정보확인에서 하면 깔끔할거같더라고요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 UserModel.Main -> response로 매핑할때 불필요한 정보를 빼거나 하자는 거죠 ? 이건 백오피스에서 관리자 계정 조회하기 위한 response인데 이때는 role이 필요하겠죠 ? |
||
Long id, | ||
String email, | ||
String nickname, | ||
LocalDateTime createdAt, | ||
Role role | ||
) { | ||
public static Admin from(User user) { | ||
return Admin.builder() | ||
.id(user.getId()) | ||
.email(user.getEmail()) | ||
.nickname(user.getNickname()) | ||
.createdAt(user.getCreatedAt()) | ||
.role(user.getRole()) | ||
.build(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,14 @@ public class UserService { | |
private final UserReader userReader; | ||
private final UserChallengeReader userChallengeReader; | ||
|
||
@Transactional(readOnly = true) | ||
public List<UserModel.Admin> getManagerAndAdmin() { | ||
List<User> admins = userReader.getManagerAndAdmin(); | ||
return admins.stream() | ||
.map(UserModel.Admin::from) | ||
.toList(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일부로 getManagerAndAdmin으로 role로 찾지않고 특정해서 만든거 좋아보이네염! (유저의 경우 페이징이 필요하고 매니저와 admin은 필요없다고 판단하셔서 따로 만드신 의도 맞나염?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 관리자 계정만 조회하는거라 레코드가 많지는 않을것 같아서 페이징 처리 안했어유 |
||
|
||
@Transactional(readOnly = true) | ||
public UserModel.Main getUserModel(Long id) { | ||
User user = userReader.getById(id); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package org.haedal.zzansuni.user.infrastructure; | ||
|
||
import org.haedal.zzansuni.global.security.Role; | ||
import org.haedal.zzansuni.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
Optional<User> findByAuthToken(String authToken); | ||
boolean existsByEmail(String email); | ||
|
||
Optional<User> findByEmail(String email); | ||
List<User> findByRoleIn(List<Role> role); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List로 변환하는 함수라면 네이밍을 from이 아니라
fromModelAndConvertList와 같은 의도가 있는 네이밍이 좋지 않을까요?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm