From 04a0d9de147b2311abf789b27f143512372154f5 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Wed, 10 Jan 2024 00:26:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=EA=B4=80=EB=A6=AC=EC=9E=90=20?= =?UTF-8?q?=EA=B3=84=EC=A0=95=20=EA=B4=80=EB=A6=AC=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20#154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminAccountManagementController.java | 11 +++++++---- .../admin/adminAccount/dto/AdminDto.java | 17 +++++++++++++++++ .../adminAccount/dto/AdminResponseDto.java | 16 ++++++++++++++++ .../service/AdminAccountManagementService.java | 17 +++++++++++++++++ .../wow_server/repository/UserRepository.java | 5 +++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminDto.java create mode 100644 src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminResponseDto.java diff --git a/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java b/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java index ee364f3..d35a25e 100644 --- a/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java @@ -3,10 +3,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import wowmarket.wow_server.admin.adminAccount.dto.AdminResponseDto; import wowmarket.wow_server.admin.adminAccount.dto.ChangeRoleRequestDto; import wowmarket.wow_server.admin.adminAccount.service.AdminAccountManagementService; import wowmarket.wow_server.domain.User; @@ -27,5 +25,10 @@ public ResponseEntity giveUserRole(@RequestBody ChangeRoleRequestDto requestDto, return adminAccountManagementService.giveUserRole(requestDto, user); } + @GetMapping("/manage") + public AdminResponseDto getAdminManagementPage(@AuthenticationPrincipal User user){ + return adminAccountManagementService.findAdmin(user); + } + } diff --git a/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminDto.java b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminDto.java new file mode 100644 index 0000000..5357340 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminDto.java @@ -0,0 +1,17 @@ +package wowmarket.wow_server.admin.adminAccount.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import wowmarket.wow_server.domain.User; + +@Getter +@NoArgsConstructor +public class AdminDto { + private String email; + private String userName; + + public AdminDto(User user){ + this.email = user.getEmail(); + this.userName = user.getName(); + } +} diff --git a/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminResponseDto.java b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminResponseDto.java new file mode 100644 index 0000000..1887972 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/AdminResponseDto.java @@ -0,0 +1,16 @@ +package wowmarket.wow_server.admin.adminAccount.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +public class AdminResponseDto { + private List adminList; + + public AdminResponseDto(List adminList){ + this.adminList = adminList; + } +} diff --git a/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java b/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java index 8f84f65..27a08bd 100644 --- a/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java @@ -5,11 +5,16 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import wowmarket.wow_server.admin.adminAccount.dto.AdminDto; +import wowmarket.wow_server.admin.adminAccount.dto.AdminResponseDto; import wowmarket.wow_server.admin.adminAccount.dto.ChangeRoleRequestDto; import wowmarket.wow_server.domain.Role; import wowmarket.wow_server.domain.User; import wowmarket.wow_server.repository.UserRepository; +import java.util.List; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class AdminAccountManagementService { @@ -40,4 +45,16 @@ public ResponseEntity giveUserRole(ChangeRoleRequestDto requestDto, User user){ return new ResponseEntity(HttpStatus.OK); } + + @Transactional(readOnly = true) + public AdminResponseDto findAdmin(User user){ + // if (!user.getRole().equals("ROLE_ADMIN")){ +// throw new ResponseStatusException(HttpStatus.BAD_REQUEST); +// } admin페이지는 관리자만 접근 가능하도록 설정 + List adminList = userRepository.findAdmin(); + List adminDtos = adminList.stream().map(AdminDto::new).collect(Collectors.toList()); + AdminResponseDto responseDto = new AdminResponseDto(adminDtos); + + return responseDto; + } } diff --git a/src/main/java/wowmarket/wow_server/repository/UserRepository.java b/src/main/java/wowmarket/wow_server/repository/UserRepository.java index dd748b4..8c23871 100644 --- a/src/main/java/wowmarket/wow_server/repository/UserRepository.java +++ b/src/main/java/wowmarket/wow_server/repository/UserRepository.java @@ -5,6 +5,8 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import wowmarket.wow_server.domain.User; + +import java.util.List; import java.util.Optional; public interface UserRepository extends JpaRepository { @@ -31,4 +33,7 @@ public interface UserRepository extends JpaRepository { void updateDemandProjectUnLike(@Param("user") User user); + @Query(nativeQuery = true, value = "SELECT * FROM user where role = 'ROLE_ADMIN'") + List findAdmin(); + } From 1098e16626c1b2cfcf965f618e56500eb61d5823 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Wed, 10 Jan 2024 00:29:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=ED=8C=90=EB=A7=A4=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=ED=8F=BC=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?#154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MySalesProject/controller/MySalesProjectController.java | 4 ++-- .../MySalesProject/service/MySalesProjectService.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java index c1c2a68..e9cd824 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java @@ -35,8 +35,8 @@ public ResponseEntity finishMySales(@PathVariable Long project_id, @Authenticati //판매 등록폼 상세보기 @GetMapping("/detail/{project_id}") - public MySalesDetailResponseDto getMySalesDetail(@PathVariable Long project_id){ - return mySalesProjectService.findMySalesDetail(project_id); + public MySalesDetailResponseDto getMySalesDetail(@PathVariable Long project_id, @AuthenticationPrincipal User user){ + return mySalesProjectService.findMySalesDetail(project_id, user); } //판매 등록폼 수정하기 diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java index 03b9b59..d2b0156 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java @@ -51,8 +51,11 @@ public ResponseEntity finishMySalesForm(Long project_id, User user){ } @Transactional(readOnly = true) - public MySalesDetailResponseDto findMySalesDetail(Long project_id){ + public MySalesDetailResponseDto findMySalesDetail(Long project_id, User user){ Project project = projectRepository.findById(project_id).get(); + if (user == null || user.getId() != project.getUser().getId()){ + throw new ResponseStatusException(HttpStatus.BAD_REQUEST); + } List itemList = itemRepository.findByProject_Id(project_id); List itemDtos = itemList.stream().map(MySalesItemDto::new).collect(Collectors.toList());