Skip to content

Commit 06aebef

Browse files
committed
feat admin project user
1 parent 2b6abed commit 06aebef

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

src/main/java/NextLevel/demo/admin/project/AdminProjectController.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package NextLevel.demo.admin.project;
22

33
import NextLevel.demo.common.SuccessResponse;
4+
import NextLevel.demo.project.ProjectStatus;
45
import NextLevel.demo.project.project.service.ProjectDeleteService;
56
import NextLevel.demo.util.jwt.JWTUtil;
7+
import com.fasterxml.jackson.annotation.JsonCreator;
68
import lombok.RequiredArgsConstructor;
79
import org.springframework.http.ResponseEntity;
810
import org.springframework.stereotype.Controller;
911
import org.springframework.web.bind.annotation.DeleteMapping;
1012
import org.springframework.web.bind.annotation.PathVariable;
13+
import org.springframework.web.bind.annotation.PostMapping;
1114
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RequestParam;
1216

1317
@Controller
1418
@RequiredArgsConstructor
@@ -22,8 +26,10 @@ public ResponseEntity getProjectList() {
2226
return null;
2327
}
2428

25-
public ResponseEntity updateProjectStatus() {
26-
return null;
29+
@PostMapping("/status/{projectId}")
30+
public ResponseEntity updateProjectStatus(@RequestParam("status") ProjectStatus status, @PathVariable("projectId") Long projectId) {
31+
adminProjectService.updateProjectStatus(projectId, status);
32+
return ResponseEntity.ok().body(new SuccessResponse("success", null));
2733
}
2834

2935
public ResponseEntity updateProject() {
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package NextLevel.demo.admin.user;
22

33
import NextLevel.demo.common.SuccessResponse;
4+
import NextLevel.demo.user.dto.user.request.RequestUpdateUserInfoDto;
5+
import NextLevel.demo.util.jwt.JWTUtil;
6+
import jakarta.validation.Valid;
47
import lombok.RequiredArgsConstructor;
58
import org.springframework.data.domain.Pageable;
69
import org.springframework.http.ResponseEntity;
710
import org.springframework.stereotype.Controller;
11+
import org.springframework.web.bind.annotation.DeleteMapping;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.PutMapping;
15+
import org.springframework.web.bind.annotation.RequestBody;
816
import org.springframework.web.bind.annotation.RequestMapping;
917

1018
@Controller
1119
@RequiredArgsConstructor
12-
@RequestMapping("/admin")
20+
@RequestMapping("/admin/user")
1321
public class AdminUserController {
1422

1523
private final AdminUserService adminUserService;
1624

25+
@GetMapping("/list")
1726
public ResponseEntity getUserList(Pageable pageable) {
1827
return ResponseEntity.ok().body(new SuccessResponse("success", adminUserService.getUserList(pageable)));
1928
}
@@ -22,12 +31,16 @@ public ResponseEntity stopUser() {
2231
return null;
2332
}
2433

25-
public ResponseEntity updateUser() {
26-
return null;
34+
@PutMapping("/update")
35+
public ResponseEntity updateUser(@RequestBody @Valid RequestUpdateUserInfoDto dto) {
36+
adminUserService.updateUser(dto);
37+
return ResponseEntity.ok().body(new SuccessResponse("success", null));
2738
}
2839

29-
public ResponseEntity removeUser() {
30-
return null;
40+
@DeleteMapping("/{userId}")
41+
public ResponseEntity removeUser(@PathVariable("userId") Long userId) {
42+
adminUserService.removeUser(userId);
43+
return ResponseEntity.ok().body(new SuccessResponse("success", null));
3144
}
3245

3346
}

src/main/java/NextLevel/demo/admin/user/AdminUserService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import NextLevel.demo.user.dto.user.response.ResponseUserInfoDetailDto;
77
import NextLevel.demo.user.entity.UserEntity;
88
import NextLevel.demo.user.repository.UserRepository;
9+
import NextLevel.demo.user.service.UserDeleteService;
910
import NextLevel.demo.user.service.UserService;
1011
import NextLevel.demo.user.service.UserValidateService;
1112
import lombok.RequiredArgsConstructor;
@@ -22,6 +23,7 @@ public class AdminUserService {
2223
private final UserValidateService userValidateService;
2324
private final UserService userService;
2425
private final UserRepository userRepository;
26+
private final UserDeleteService userDeleteService;
2527

2628
public List<ResponseUserInfoDetailDto> getUserList(Pageable pageable) {
2729
return userRepository.findAll(pageable).stream().map(ResponseUserInfoDetailDto::of).toList();
@@ -33,16 +35,21 @@ public void stopUser() {
3335

3436
@Transactional
3537
public void updateUser(RequestUpdateUserInfoDto dto) {
36-
UserEntity oldUser = userValidateService.getUserInfoWithAccessToken(dto.getId());
38+
UserEntity oldUser = userValidateService.findUserWithUserId(dto.getId());
39+
40+
if(dto.getName().equals("point")) {
41+
oldUser.updatePoint(Integer.parseInt(dto.getValue()));
42+
return;
43+
}
3744

3845
if(dto.getName().equals("nickName") && !userValidateService.checkNickNameIsNotExist(dto.getValue()))
3946
throw new CustomException(ErrorCode.ALREADY_EXISTS_NICKNAME);
4047

4148
oldUser.updateUserInfo(dto.getName(), dto.getValue());
4249
}
4350

44-
public void removeUser() {
45-
// userService. ; // delete 어디감?
51+
public void removeUser(Long targetId) {
52+
userDeleteService.deleteUser(targetId, null);
4653
}
4754

4855
}

src/main/java/NextLevel/demo/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum ErrorCode {
1010
NOT_AUTHOR(HttpStatus.BAD_REQUEST, "00001","작성자가 아닙니다"),
1111
ACCESS_TOKEN_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "00002", "access, refresh token을 다시 발급해 주세요"),
1212
NOT_FOUND(HttpStatus.NOT_FOUND, "00003", "not found %s"),
13+
NOT_ADMIN(HttpStatus.UNAUTHORIZED, "10001", "not admin"),
1314

1415
//register
1516
ALREADY_EXISTS_EMAIL(HttpStatus.BAD_REQUEST, "01001","email already exists"),

src/main/java/NextLevel/demo/user/entity/UserEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public UserEntity(Long id, String name,String nickName, int point, String addres
100100
}
101101

102102
public void checkRole() {
103+
if(role.equals(UserRole.ADMIN.name()))
104+
return;
105+
103106
if(name != null && !name.isEmpty() &&
104107
nickName != null && !nickName.isEmpty() &&
105108
address != null && !address.isEmpty() &&

src/main/java/NextLevel/demo/user/service/UserService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public UserEntity updateUserInfo(RequestUpdateUserInfoDto dto, HttpServletReques
5151
if(dto.getName().equals("nickName") && !userValidateService.checkNickNameIsNotExist(dto.getValue()))
5252
throw new CustomException(ErrorCode.ALREADY_EXISTS_NICKNAME);
5353

54+
if(dto.getName().equals("role"))
55+
throw new CustomException(ErrorCode.CAN_NOT_INVOKE, "role");
56+
5457
oldUser.updateUserInfo(dto.getName(), dto.getValue());
5558

5659
// userRepository.save(oldUser);

0 commit comments

Comments
 (0)