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..ee364f3 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/controller/AdminAccountManagementController.java @@ -0,0 +1,31 @@ +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); + } + + @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/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..8f84f65 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/admin/adminAccount/service/AdminAccountManagementService.java @@ -0,0 +1,43 @@ +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); + } + + @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); + } +} 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/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) 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;i 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; - } } 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 76782e5..03b9b59 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 @@ -62,7 +62,7 @@ public MySalesDetailResponseDto findMySalesDetail(Long project_id){ @Transactional public ResponseEntity modifyMySalesProject(Long projectId, MySalesProjectModifyRequestDto requestDto, User user){ - Project project = projectRepository.findById(projectId).orElseThrow(()->new 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); }