Skip to content

Commit

Permalink
Merge pull request #155 from UMC-WOWMARKET/feat/MyOrderManage-137
Browse files Browse the repository at this point in the history
[feat] 관리자 계정 관리, 나의 판매 등록폼 상세보기 권한 설정
  • Loading branch information
yunji118 authored Jan 9, 2024
2 parents fa36d01 + 1098e16 commit 5164018
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}


}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<AdminDto> adminList;

public AdminResponseDto(List<AdminDto> adminList){
this.adminList = adminList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<User> adminList = userRepository.findAdmin();
List<AdminDto> adminDtos = adminList.stream().map(AdminDto::new).collect(Collectors.toList());
AdminResponseDto responseDto = new AdminResponseDto(adminDtos);

return responseDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//판매 등록폼 수정하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> itemList = itemRepository.findByProject_Id(project_id);
List<MySalesItemDto> itemDtos = itemList.stream().map(MySalesItemDto::new).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User, Long> {
Expand All @@ -31,4 +33,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
void updateDemandProjectUnLike(@Param("user") User user);


@Query(nativeQuery = true, value = "SELECT * FROM user where role = 'ROLE_ADMIN'")
List<User> findAdmin();

}

0 comments on commit 5164018

Please sign in to comment.