From 8e83b0467c65acea15664ae56b30b05acf4b72c5 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Mon, 8 Jan 2024 19:09:36 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[feat]=20=EC=88=98=EC=9A=94=EC=A1=B0?= =?UTF-8?q?=EC=82=AC=20=EB=93=B1=EB=A1=9D=ED=8F=BC=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wow_server/domain/DemandItem.java | 8 +++++ .../wow_server/domain/DemandProject.java | 16 +++++++++ .../controller/MyDemandProjectController.java | 5 +++ .../dto/MyDemandProjectModifyRequestDto.java | 25 ++++++++++++++ .../service/MyDemandProjectService.java | 33 ++++++++++++++----- .../service/MySalesProjectService.java | 2 +- 6 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/dto/MyDemandProjectModifyRequestDto.java diff --git a/src/main/java/wowmarket/wow_server/domain/DemandItem.java b/src/main/java/wowmarket/wow_server/domain/DemandItem.java index eb7c5f4..1139e25 100644 --- a/src/main/java/wowmarket/wow_server/domain/DemandItem.java +++ b/src/main/java/wowmarket/wow_server/domain/DemandItem.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.ColumnDefault; +import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandItemDto; @AllArgsConstructor @NoArgsConstructor @@ -34,4 +35,11 @@ public class DemandItem extends BaseEntity{ public void setDemandProject(DemandProject demandProject){ this.demandProject=demandProject; } + + public void modify(MyDemandItemDto itemDto){ + this.name = itemDto.getName(); + this.price = itemDto.getPrice(); + this.goal = itemDto.getGoal(); + this.limits = itemDto.getLimits(); + } } diff --git a/src/main/java/wowmarket/wow_server/domain/DemandProject.java b/src/main/java/wowmarket/wow_server/domain/DemandProject.java index 920eb9b..6d23569 100644 --- a/src/main/java/wowmarket/wow_server/domain/DemandProject.java +++ b/src/main/java/wowmarket/wow_server/domain/DemandProject.java @@ -2,6 +2,7 @@ import jakarta.persistence.*; import lombok.*; +import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandProjectModifyRequestDto; import java.time.LocalDate; import java.time.LocalDateTime; @@ -62,4 +63,19 @@ public void setCategory(Category category){ this.category = category; } + public void modify(MyDemandProjectModifyRequestDto requestDto, Category category){ + this.projectName = requestDto.getProjectName(); + this.description = requestDto.getDescription(); + this.sellerName = requestDto.getSellerName(); + this.phoneNumber = requestDto.getSellerPhoneNumber(); + this.email = requestDto.getSellerEmail(); + this.sellerEtc = requestDto.getSellerEtc(); + this.thumbnail = requestDto.getThumbnail(); + this.image1 = requestDto.getImage1(); + this.image2 = requestDto.getImage2(); + this.image3 = requestDto.getImage3(); + this.startDate = requestDto.getStartDate(); + this.endDate = requestDto.getEndDate(); + this.category = category; + } } diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/controller/MyDemandProjectController.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/controller/MyDemandProjectController.java index 1b3cb91..42cc3d2 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/controller/MyDemandProjectController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/controller/MyDemandProjectController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import wowmarket.wow_server.domain.User; import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandDetailResponseDto; +import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandProjectModifyRequestDto; import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandResponseDto; import wowmarket.wow_server.mypage.myproject.MyDemandProject.service.MyDemandProjectService; @@ -37,5 +38,9 @@ public MyDemandDetailResponseDto getMyDemandDetailForm(@PathVariable Long demand } + @PutMapping("/{demand_project_id}/modify") + public ResponseEntity modifyMyDemandProject(@PathVariable Long demand_project_id, @RequestBody MyDemandProjectModifyRequestDto requestDto, @AuthenticationPrincipal User user){ + return myDemandProjectService.modifyMyDemandProject(demand_project_id, requestDto, user); + } } diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/dto/MyDemandProjectModifyRequestDto.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/dto/MyDemandProjectModifyRequestDto.java new file mode 100644 index 0000000..151f387 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/dto/MyDemandProjectModifyRequestDto.java @@ -0,0 +1,25 @@ +package wowmarket.wow_server.mypage.myproject.MyDemandProject.dto; + +import lombok.Getter; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +public class MyDemandProjectModifyRequestDto { + private String projectName; + private String description; + private String sellerName; + private String sellerPhoneNumber; + private String sellerEmail; + private String sellerEtc; + private String thumbnail; + private Long categoryId; + private String image1; + private String image2; + private String image3; + private List itemList; + private LocalDateTime startDate; + private LocalDateTime endDate; + +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/service/MyDemandProjectService.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/service/MyDemandProjectService.java index d5bfaf7..b0aa387 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/service/MyDemandProjectService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MyDemandProject/service/MyDemandProjectService.java @@ -8,14 +8,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.server.ResponseStatusException; -import wowmarket.wow_server.domain.DemandItem; -import wowmarket.wow_server.domain.DemandProject; -import wowmarket.wow_server.domain.User; +import wowmarket.wow_server.domain.*; import wowmarket.wow_server.global.jwt.SecurityUtil; -import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandDetailResponseDto; -import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandDto; -import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandItemDto; -import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.MyDemandResponseDto; +import wowmarket.wow_server.mypage.myproject.MyDemandProject.dto.*; +import wowmarket.wow_server.repository.CategoryRepository; import wowmarket.wow_server.repository.DemandItemRepository; import wowmarket.wow_server.repository.DemandProjectRepository; import wowmarket.wow_server.repository.UserRepository; @@ -28,7 +24,7 @@ public class MyDemandProjectService { private final DemandProjectRepository demandProjectRepository; private final DemandItemRepository demandItemRepository; - private final UserRepository userRepository; + private final CategoryRepository categoryRepository; @Transactional(readOnly = true) public MyDemandResponseDto findAllMyDemandForm(Pageable pageable, User user){ @@ -60,4 +56,25 @@ public MyDemandDetailResponseDto findMyDemandFormDetail(Long demand_project_id, return responseDto; } + @Transactional + public ResponseEntity modifyMyDemandProject(Long projectId, MyDemandProjectModifyRequestDto requestDto, User user){ + DemandProject demandProject = demandProjectRepository.findById(projectId).orElseThrow(() -> new IllegalArgumentException("해당 demand project id가 없습니다.")); + if (user == null || user.getId() != demandProject.getUser().getId()){ + throw new ResponseStatusException(HttpStatus.BAD_REQUEST); + } + Category category = categoryRepository.findById(requestDto.getCategoryId()).orElseThrow(() -> new IllegalArgumentException("해당 category id가 없습니다.")); + demandProject.modify(requestDto, category); + + for(int i=0;inew IllegalArgumentException("해당 project id가 없습니다.")); + Project project = projectRepository.findById(projectId).orElseThrow(()->new IllegalArgumentException("해당 sales project id가 없습니다.")); if (user == null || project.getUser().getId() != user.getId()){ throw new ResponseStatusException(HttpStatus.BAD_REQUEST); } From 6b548049f70b8874a213f8f580530dcd496b4fc0 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Mon, 8 Jan 2024 19:19:06 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=EB=B0=B0=EC=86=A1=20=EB=B0=A9?= =?UTF-8?q?=EB=B2=95=20=EC=9D=B4=EB=A6=84=20=EB=B0=8F=20=EC=88=98=EB=A0=B9?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EC=B6=94=EA=B0=80=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/MySalesDetailResponseDto.java | 2 ++ .../dto/MySalesProjectModifyRequestDto.java | 26 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesDetailResponseDto.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesDetailResponseDto.java index 061f3d7..92503fe 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesDetailResponseDto.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesDetailResponseDto.java @@ -23,6 +23,7 @@ public class MySalesDetailResponseDto { private LocalDateTime startDate; private LocalDateTime endDate; private String receiveType; + private String receiveAddress; private String sellerBank; private String sellerAccount; private String sellerAccountName; @@ -46,6 +47,7 @@ public MySalesDetailResponseDto(Project project, List itemDtos){ this.startDate = project.getStartDate(); this.endDate = project.getEndDate(); this.receiveType = project.getReceive_type().toString(); + this.receiveAddress = project.getReceive_address(); this.sellerBank = project.getBank(); this.sellerAccount = project.getAccount(); this.sellerAccountName = project.getAccount_holder_name(); diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java index fd66f50..7acfb07 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java @@ -33,30 +33,4 @@ public class MySalesProjectModifyRequestDto { private String sellerEmail; private String sellerEtc; - @Builder - public MySalesProjectModifyRequestDto(String projectName, String description, String sellerName, String phoneNumber, String email, String sellerEtc, - Long categoryId, String thumbnail, String image1, String image2, String image3, LocalDateTime startDate, - LocalDateTime endDate, Long receiveType, String receiveAddress, Long deliveryFee, String bank, String account, - String accountHolderName, List itemList){ - this.projectName = projectName; - this.description = description; - this.sellerName = sellerName; - this.sellerPhoneNumber = phoneNumber; - this.sellerEmail = email; - this.sellerEtc = sellerEtc; - this.categoryId = categoryId; - this.thumbnail = thumbnail; - this.image1 = image1; - this.image2 = image2; - this.image3 = image3; - this.startDate = startDate; - this.endDate = endDate; - this.receiveType = receiveType; - this.receiveAddress = receiveAddress; - this.deliveryFee = deliveryFee; - this.sellerBank = bank; - this.sellerAccount = account; - this.sellerAccountName = accountHolderName; - this.itemList = itemList; - } } From aa050b70860ab1a1857453837d9220f4159360a7 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Mon, 8 Jan 2024 22:47:43 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[feat]=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EA=B6=8C=ED=95=9C=20=EB=B3=80=EA=B2=BD=20#154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminAccountManagementController.java | 27 +++++++++++++++++ .../dto/ChangeRoleRequestDto.java | 8 +++++ .../AdminAccountManagementService.java | 30 +++++++++++++++++++ .../wowmarket/wow_server/domain/Role.java | 3 ++ .../wowmarket/wow_server/domain/User.java | 5 ++++ 5 files changed, 73 insertions(+) create mode 100644 src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java create mode 100644 src/main/java/wowmarket/wow_server/admin/adminAccount/dto/ChangeRoleRequestDto.java create mode 100644 src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.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 new file mode 100644 index 0000000..4b89566 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java @@ -0,0 +1,27 @@ +package wowmarket.wow_server.admin.adminAccount.controller; + +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 wowmarket.wow_server.admin.adminAccount.dto.ChangeRoleRequestDto; +import wowmarket.wow_server.admin.adminAccount.service.AdminAccountManagementService; +import wowmarket.wow_server.domain.User; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/admin") +public class AdminAccountManagementController { + private final AdminAccountManagementService adminAccountManagementService; + + @PutMapping("/role/admin") + public ResponseEntity giveAdminRole(@RequestBody ChangeRoleRequestDto requestDto, @AuthenticationPrincipal User user){ + return adminAccountManagementService.giveAdminRole(requestDto, user); + } + + + +} diff --git a/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/ChangeRoleRequestDto.java b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/ChangeRoleRequestDto.java new file mode 100644 index 0000000..eda364f --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/dto/ChangeRoleRequestDto.java @@ -0,0 +1,8 @@ +package wowmarket.wow_server.admin.adminAccount.dto; + +import lombok.Getter; + +@Getter +public class ChangeRoleRequestDto { + private String email; +} 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 new file mode 100644 index 0000000..b075767 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java @@ -0,0 +1,30 @@ +package wowmarket.wow_server.admin.adminAccount.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +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; + +@Service +@RequiredArgsConstructor +public class AdminAccountManagementService { + private final UserRepository userRepository; + + @Transactional + public ResponseEntity giveAdminRole(ChangeRoleRequestDto requestDto, User user){ +// if (!user.getRole().equals("ROLE_ADMIN")){ +// throw new ResponseStatusException(HttpStatus.BAD_REQUEST); +// } 관리자만 변경 가능하도록 (그 전에 admin페이지는 관리자만 접근 가능하도록 설정 필요) + User reqUser = userRepository.findByEmail(requestDto.getEmail()).orElseThrow(()->new IllegalArgumentException("존재하지 않는 email 입니다.")); + Role roleAdmin = Role.ROLE_ADMIN; + reqUser.updateUserRole(roleAdmin); + userRepository.save(reqUser); + + return new ResponseEntity(HttpStatus.OK); + } +} diff --git a/src/main/java/wowmarket/wow_server/domain/Role.java b/src/main/java/wowmarket/wow_server/domain/Role.java index fd8c1c3..64241d0 100644 --- a/src/main/java/wowmarket/wow_server/domain/Role.java +++ b/src/main/java/wowmarket/wow_server/domain/Role.java @@ -1,5 +1,8 @@ package wowmarket.wow_server.domain; +import lombok.Builder; + public enum Role { ROLE_USER, ROLE_ADMIN; + } diff --git a/src/main/java/wowmarket/wow_server/domain/User.java b/src/main/java/wowmarket/wow_server/domain/User.java index 01d89af..970d36f 100644 --- a/src/main/java/wowmarket/wow_server/domain/User.java +++ b/src/main/java/wowmarket/wow_server/domain/User.java @@ -57,6 +57,10 @@ public class User extends BaseEntity implements UserDetails { @Column(columnDefinition = "integer default 0", nullable = false) private int demandLike; + public void updateUserRole(Role role){ + this.role = role; + } + public void encodePassword(PasswordEncoder passwordEncoder) { this.password = passwordEncoder.encode(password); } @@ -103,6 +107,7 @@ public boolean isEnabled() { } + /////*** // //== 회원탈퇴 -> 작성한 게시물, 댓글 모두 삭제 ==// // @OneToMany(mappedBy = "writer", cascade = ALL, orphanRemoval = true) From 04c090a705a592a6c95c75d907ce31b13090b6f6 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Mon, 8 Jan 2024 22:51:19 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=EB=A1=9C=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EB=B3=80=EA=B2=BD=20#154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminAccountManagementController.java | 4 ++++ .../service/AdminAccountManagementService.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) 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 4b89566..ee364f3 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 @@ -22,6 +22,10 @@ public ResponseEntity giveAdminRole(@RequestBody ChangeRoleRequestDto requestDto return adminAccountManagementService.giveAdminRole(requestDto, user); } + @PutMapping("/role/user") + public ResponseEntity giveUserRole(@RequestBody ChangeRoleRequestDto requestDto, @AuthenticationPrincipal User user){ + return adminAccountManagementService.giveUserRole(requestDto, user); + } } 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 b075767..8f84f65 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 @@ -27,4 +27,17 @@ public ResponseEntity giveAdminRole(ChangeRoleRequestDto requestDto, User user){ return new ResponseEntity(HttpStatus.OK); } + + @Transactional + public ResponseEntity giveUserRole(ChangeRoleRequestDto requestDto, User user){ +// if (!user.getRole().equals("ROLE_ADMIN")){ +// throw new ResponseStatusException(HttpStatus.BAD_REQUEST); +// } 관리자만 변경 가능하도록 (그 전에 admin페이지는 관리자만 접근 가능하도록 설정 필요) + User reqUser = userRepository.findByEmail(requestDto.getEmail()).orElseThrow(()->new IllegalArgumentException("존재하지 않는 email 입니다.")); + Role roleUser = Role.ROLE_USER; + reqUser.updateUserRole(roleUser); + userRepository.save(reqUser); + + return new ResponseEntity(HttpStatus.OK); + } }