-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from UMC-WOWMARKET/feat/admin-approve
feat: 관리자 페이지 - 프로젝트&수요조사 승인 관리 #158
- Loading branch information
Showing
7 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...main/java/wowmarket/wow_server/admin/permission/controller/AdminPermissionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package wowmarket.wow_server.admin.permission.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import wowmarket.wow_server.admin.permission.dto.request.PermissionProjectsRequest; | ||
import wowmarket.wow_server.admin.permission.dto.response.ProjectListResponse; | ||
import wowmarket.wow_server.admin.permission.service.AdminPermissionService; | ||
|
||
@RestController | ||
@RequestMapping("/admin/permission") | ||
@RequiredArgsConstructor | ||
public class AdminPermissionController { | ||
private final AdminPermissionService adminPermissionService; | ||
|
||
@GetMapping("/project") | ||
public ProjectListResponse getProjectList(@RequestParam(name = "pageNo", defaultValue = "1", required = true) int pageNo) { | ||
Sort sort = Sort.by( | ||
Sort.Order.desc("permission"), | ||
Sort.Order.asc("created_time") | ||
); | ||
PageRequest pageable = PageRequest.of(pageNo - 1, 9, sort); | ||
return adminPermissionService.getProjectList(pageNo, pageable); | ||
} | ||
|
||
@PostMapping("/project") | ||
public ResponseEntity<Void> updateProjectPermission( | ||
@RequestParam(name = "permission", defaultValue = "APPROVED", required = true) String permission, | ||
@RequestBody PermissionProjectsRequest permissionProjectsRequest) { | ||
return adminPermissionService.updateProjectPermission(permission, permissionProjectsRequest); | ||
} | ||
|
||
@GetMapping("/demand") | ||
public ProjectListResponse getDemandProjectList(@RequestParam(name = "pageNo", defaultValue = "1", required = true) int pageNo) { | ||
Sort sort = Sort.by( | ||
Sort.Order.desc("permission"), | ||
Sort.Order.asc("created_time") | ||
); | ||
PageRequest pageable = PageRequest.of(pageNo - 1, 9, sort); | ||
return adminPermissionService.getDemandProjectList(pageNo, pageable); | ||
} | ||
|
||
@PostMapping("/demand") | ||
public ResponseEntity<Void> updateDemandProjectPermission( | ||
@RequestParam(name = "permission", defaultValue = "APPROVED", required = true) String permission, | ||
@RequestBody PermissionProjectsRequest permissionProjectsRequest) { | ||
return adminPermissionService.updateDemandProjectPermission(permission, permissionProjectsRequest); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ain/java/wowmarket/wow_server/admin/permission/dto/request/PermissionProjectsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package wowmarket.wow_server.admin.permission.dto.request; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PermissionProjectsRequest { | ||
private List<Long> projectIds; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/wowmarket/wow_server/admin/permission/dto/response/ProjectInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package wowmarket.wow_server.admin.permission.dto.response; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import wowmarket.wow_server.domain.DemandProject; | ||
import wowmarket.wow_server.domain.Project; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ProjectInfo { | ||
private Long projectId; | ||
private String projectName; | ||
private String projectUniv; | ||
private LocalDateTime createdTime; | ||
private String permission; | ||
|
||
public ProjectInfo(Project project) { | ||
this.projectId = project.getId(); | ||
this.projectName = project.getProjectName(); | ||
this.projectUniv = project.getUser().getUniv(); | ||
this.createdTime = project.getCreated_time(); | ||
this.permission = project.getPermission().toString(); | ||
} | ||
|
||
public ProjectInfo(DemandProject demandProject) { | ||
this.projectId = demandProject.getId(); | ||
this.projectName = demandProject.getProjectName(); | ||
this.projectUniv = demandProject.getUser().getUniv(); | ||
this.createdTime = demandProject.getCreated_time(); | ||
this.permission = demandProject.getPermission().toString(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/wowmarket/wow_server/admin/permission/dto/response/ProjectListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package wowmarket.wow_server.admin.permission.dto.response; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ProjectListResponse { | ||
private int totalPage; | ||
private int currentPage; | ||
private List<ProjectInfo> projectList; | ||
|
||
public ProjectListResponse(int totalPage, int currentPage, List<ProjectInfo> projectList) { | ||
this.totalPage = totalPage; | ||
this.currentPage = currentPage; | ||
this.projectList = projectList; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/wowmarket/wow_server/admin/permission/service/AdminPermissionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package wowmarket.wow_server.admin.permission.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import wowmarket.wow_server.admin.permission.dto.request.PermissionProjectsRequest; | ||
import wowmarket.wow_server.admin.permission.dto.response.ProjectInfo; | ||
import wowmarket.wow_server.admin.permission.dto.response.ProjectListResponse; | ||
import wowmarket.wow_server.domain.DemandProject; | ||
import wowmarket.wow_server.domain.Permission; | ||
import wowmarket.wow_server.domain.Project; | ||
import wowmarket.wow_server.repository.DemandProjectRepository; | ||
import wowmarket.wow_server.repository.ProjectRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AdminPermissionService { | ||
private final ProjectRepository projectRepository; | ||
private final DemandProjectRepository demandProjectRepository; | ||
|
||
public ProjectListResponse getProjectList(int pageNo, PageRequest pageable) { | ||
LocalDateTime currentDate = LocalDateTime.now(ZoneId.of("Asia/Seoul")); | ||
|
||
Page<Project> findProjects = projectRepository.findProjectsAdmin(currentDate, pageable); | ||
Page<ProjectInfo> projectList = findProjects.map(ProjectInfo::new); | ||
|
||
return new ProjectListResponse(projectList.getTotalPages(), projectList.getNumber(), projectList.getContent()); | ||
} | ||
|
||
@Transactional | ||
public ResponseEntity<Void> updateProjectPermission(String permission, PermissionProjectsRequest permissionProjectsRequest) { | ||
permissionProjectsRequest.getProjectIds() | ||
.forEach(projectId -> projectRepository.updatePermission(Permission.valueOf(permission), projectId)); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
public ProjectListResponse getDemandProjectList(int pageNo, PageRequest pageable) { | ||
LocalDateTime currentDate = LocalDateTime.now(ZoneId.of("Asia/Seoul")); | ||
|
||
Page<DemandProject> findDemandProjects = demandProjectRepository.findDemandProjectsPermission(currentDate, pageable); | ||
Page<ProjectInfo> projectList = findDemandProjects.map(ProjectInfo::new); | ||
|
||
return new ProjectListResponse(projectList.getTotalPages(), projectList.getNumber(), projectList.getContent()); | ||
} | ||
|
||
@Transactional | ||
public ResponseEntity<Void> updateDemandProjectPermission(String permission, PermissionProjectsRequest permissionProjectsRequest) { | ||
permissionProjectsRequest.getProjectIds() | ||
.forEach(projectId -> demandProjectRepository.updatePermission(Permission.valueOf(permission), projectId)); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters