Skip to content

Commit

Permalink
Merge pull request #163 from UMC-WOWMARKET/feat/admin-approve
Browse files Browse the repository at this point in the history
feat: 관리자 페이지 - 프로젝트&수요조사 승인 관리 #158
  • Loading branch information
yoonsseo authored Jan 11, 2024
2 parents d291c09 + bdb62c3 commit 0f5a887
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 2 deletions.
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);
}
}
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;
}
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();
}
}
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;
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import wowmarket.wow_server.domain.DemandProject;
import wowmarket.wow_server.domain.Project;
import wowmarket.wow_server.domain.Permission;

import java.time.LocalDateTime;

Expand Down Expand Up @@ -63,4 +63,11 @@ Page<DemandProject> findBySearchUserUniv(@Param("currentDate") LocalDateTime cur
"WHERE dp.id = :demandProjectId")
void updateDemandProjectUnLike(@Param("demandProjectId") Long demandProjectId);

@Query("SELECT dp FROM DemandProject dp " +
"WHERE dp.isEnd = false AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate")
Page<DemandProject> findDemandProjectsPermission(@Param("currentDate") LocalDateTime currentDate, Pageable pageable);

@Modifying
@Query("UPDATE DemandProject dp SET dp.permission = :permission WHERE dp.id = :demandProjectId")
void updatePermission(@Param("permission") Permission permission, @Param("demandProjectId") Long demandProjectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import wowmarket.wow_server.domain.Permission;
import wowmarket.wow_server.domain.Project;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -64,4 +64,12 @@ Page<Project> findBySearchUserUniv(@Param("currentDate") LocalDateTime currentDa
@Query("UPDATE Project p SET p.likeCnt = p.likeCnt - 1 " +
"WHERE p.id = :projectId")
void updateProjectUnLike(@Param("projectId") Long projectId);

@Query("SELECT p FROM Project p " +
"WHERE p.isDel = false AND p.isEnd = false AND p.endDate >= :currentDate")
Page<Project> findProjectsAdmin(@Param("currentDate") LocalDateTime currentDate, Pageable pageable);

@Modifying
@Query("UPDATE Project p SET p.permission = :permission WHERE p.id = :projectId")
void updatePermission(@Param("permission") Permission permission, @Param("projectId") Long projectId);
}

0 comments on commit 0f5a887

Please sign in to comment.