-
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.
[feat] 관리자 페이지 회원 관리
- Loading branch information
Showing
8 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/wowmarket/wow_server/admin/userManage/controller/UserManageController.java
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,34 @@ | ||
package wowmarket.wow_server.admin.userManage.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wowmarket.wow_server.admin.userManage.dto.UserManageDto; | ||
import wowmarket.wow_server.admin.userManage.dto.UserSearchCond; | ||
import wowmarket.wow_server.admin.userManage.service.UserManageService; | ||
import wowmarket.wow_server.domain.User; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin") | ||
public class UserManageController { | ||
private final UserManageService userManageService; | ||
|
||
@GetMapping("/manage/user") | ||
public List<UserManageDto> getUserList(UserSearchCond cond, @AuthenticationPrincipal User user){ | ||
return userManageService.getUserList(cond, user); | ||
} | ||
|
||
@PutMapping("/restrict/user") | ||
public ResponseEntity deleteUser(String email, @AuthenticationPrincipal User user){ | ||
userManageService.deleteUser(email, user); | ||
return new ResponseEntity(HttpStatus.OK); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/wowmarket/wow_server/admin/userManage/dto/UserManageDto.java
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,27 @@ | ||
package wowmarket.wow_server.admin.userManage.dto; | ||
|
||
|
||
import lombok.Getter; | ||
import wowmarket.wow_server.domain.User; | ||
|
||
@Getter | ||
public class UserManageDto { | ||
private String email; | ||
private String name; | ||
private String univ; | ||
|
||
private UserManageDto(String email, String name, String univ){ | ||
this.email = email; | ||
this.name = name; | ||
this.univ = univ; | ||
} | ||
|
||
|
||
public static UserManageDto from(User user){ | ||
UserManageDto userManageDto = new UserManageDto( | ||
user.getEmail(), | ||
user.getName(), | ||
user.getUniv()); | ||
return userManageDto; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/wowmarket/wow_server/admin/userManage/dto/UserSearchCond.java
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,11 @@ | ||
package wowmarket.wow_server.admin.userManage.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class UserSearchCond { | ||
private String email; | ||
private String name; | ||
private String univ; | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/wowmarket/wow_server/admin/userManage/service/UserManageService.java
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,69 @@ | ||
package wowmarket.wow_server.admin.userManage.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import wowmarket.wow_server.admin.userManage.dto.UserManageDto; | ||
import wowmarket.wow_server.admin.userManage.dto.UserSearchCond; | ||
import wowmarket.wow_server.domain.DemandProject; | ||
import wowmarket.wow_server.domain.Project; | ||
import wowmarket.wow_server.domain.User; | ||
import wowmarket.wow_server.repository.DemandProjectRepository; | ||
import wowmarket.wow_server.repository.ProjectRepository; | ||
import wowmarket.wow_server.repository.UserRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserManageService { | ||
private final UserRepository userRepository; | ||
private final ProjectRepository projectRepository; | ||
private final DemandProjectRepository demandProjectRepository; | ||
|
||
public List<UserManageDto> getUserList(UserSearchCond cond, User admin){ | ||
// 관리자만 조회 가능 | ||
if (!admin.getRole().toString().equals("ROLE_ADMIN")){ | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
// 동적 쿼리로 조건 따라 유저 검색 | ||
List<User> userList = userRepository.getUserList(cond.getEmail(), cond.getName(), cond.getUniv()); | ||
|
||
// Dto로 필요 데이터만 담아 리턴 | ||
return userList.stream() | ||
.map(UserManageDto::from) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public void deleteUser(String email, User admin) { | ||
// 관리자만 삭제 가능 | ||
if (!admin.getRole().toString().equals("ROLE_ADMIN")){ | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
// 유저 isDel 변경 | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST)); | ||
user.setDel(true); | ||
userRepository.save(user); | ||
|
||
// 유저 아이디가 일치하는 프로젝트 isDel 변경 | ||
Long userId = user.getId(); | ||
List<Project> projects = projectRepository.findByUser_Id(userId); | ||
projects.forEach(project -> { | ||
project.setDel(true); | ||
projectRepository.save(project); | ||
}); | ||
|
||
List<DemandProject> demandProjects = demandProjectRepository.findByUser_Id(userId); | ||
demandProjects.forEach(demandProject -> { | ||
demandProject.setDel(true); | ||
demandProjectRepository.save(demandProject); | ||
}); | ||
|
||
} | ||
} |
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