Skip to content

Commit

Permalink
feat: 백오피스용 API (#211) (#212)
Browse files Browse the repository at this point in the history
* feat: 스페이스 개수 조회 API 작성

* feat: 회고 개수 조회 API 작성

* feat: 특정 스페이스 내 회고 개수 API 작성

* feat: 특정 기간 내에 진행된 회고 개수 스페이스 별로 보는 API

* fix: 파일 삭제
  • Loading branch information
clean2001 authored Sep 9, 2024
1 parent f39d159 commit c6953e5
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 37 deletions.
7 changes: 0 additions & 7 deletions gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.layer.domain.admin.controller;

import java.time.LocalDateTime;

import org.layer.domain.admin.controller.dto.AdminRetrospectsGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpacesGetResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.layer.domain.admin.controller.dto.AdminRetrospectCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminRetrospectsGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpaceCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpacesGetResponse;
import org.layer.domain.retrospect.dto.AdminRetrospectCountGroupBySpaceGetResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;

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

@Tag(name = "어드민", description = "어드민 관련 API")
public interface AdminApi {
Expand All @@ -32,4 +34,41 @@ ResponseEntity<AdminSpacesGetResponse> getSpaceData(@RequestParam("startDate") L
@Parameter(name = "password", description = "비밀번호 [카톡방으로 공유]", example = "[카톡방으로 공유]", required = true, schema = @Schema(type = "string", format = "string"))})
ResponseEntity<AdminRetrospectsGetResponse> getRetrospectData(@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @RequestParam("password") String password);

@Operation(summary = "스페이스 개수 조회", description = "특정 기간내에 만들어진 스페이스 개수를 조회합니다. (우리 팀원이 만든 스페이스는 제외)")
@Parameters({
@Parameter(name = "startDate", description = "검색 시작 시간", example = "2024-09-05T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "endDate", description = "검색 종료 시간", example = "2024-09-13T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "password", description = "비밀번호 [카톡방으로 공유]", example = "[카톡방으로 공유]", required = true, schema = @Schema(type = "string", format = "string"))})
ResponseEntity<AdminSpaceCountGetResponse> getSpaceCount(@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @RequestParam("password") String password);

@Operation(summary = "회고 개수 조회", description = "특정 기간내에 시작된 회고 개수를 조회합니다. (우리 팀원이 만든 스페이스에서 진행된 회고는 제외)")
@Parameters({
@Parameter(name = "startDate", description = "검색 시작 시간", example = "2024-09-05T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "endDate", description = "검색 종료 시간", example = "2024-09-13T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "password", description = "비밀번호 [카톡방으로 공유]", example = "[카톡방으로 공유]", required = true, schema = @Schema(type = "string", format = "string"))})
ResponseEntity<AdminRetrospectCountGetResponse> getRetrospectCount(@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @RequestParam("password") String password);


@Operation(summary = "특정 스페이스 내 회고 개수 조회", description = "특정 기간내에 특정 스페이스 안에서 시작된 회고 개수를 조회합니다.")
@Parameters({
@Parameter(name = "startDate", description = "검색 시작 시간", example = "2024-09-05T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "endDate", description = "검색 종료 시간", example = "2024-09-13T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "password", description = "비밀번호 [카톡방으로 공유]", example = "[카톡방으로 공유]", required = true, schema = @Schema(type = "string", format = "string"))})
ResponseEntity<AdminRetrospectCountGetResponse> getRetrospectCountInSpace(@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate,
@RequestParam("spaceId") Long spaceId,
@RequestParam("password") String password);


@Operation(summary = "특정 기간 내 회고 개수 스페이스 별로 보기", description = "특정 기간내에 시작된 회고 개수를 스페이스 별로 조회합니다. (우리 팀원이 만든 스페이스는 제외)")
@Parameters({
@Parameter(name = "startDate", description = "검색 시작 시간", example = "2024-09-05T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "endDate", description = "검색 종료 시간", example = "2024-09-13T15:30:45", required = true, schema = @Schema(type = "string")),
@Parameter(name = "password", description = "비밀번호 [카톡방으로 공유]", example = "[카톡방으로 공유]", required = true, schema = @Schema(type = "string", format = "string"))})
ResponseEntity<List<AdminRetrospectCountGroupBySpaceGetResponse>> getRetrospectCountGroupBySpace (@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate,
@RequestParam("password") String password);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package org.layer.domain.admin.controller;

import java.time.LocalDateTime;

import org.layer.common.annotation.MemberId;
import lombok.RequiredArgsConstructor;
import org.layer.domain.admin.controller.dto.AdminRetrospectCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminRetrospectsGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpaceCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpacesGetResponse;
import org.layer.domain.admin.service.AdminService;
import org.layer.domain.retrospect.dto.AdminRetrospectCountGroupBySpaceGetResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import lombok.RequiredArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -40,4 +38,39 @@ public ResponseEntity<AdminRetrospectsGetResponse> getRetrospectData(

return ResponseEntity.ok(adminService.getRetrospectData(startDate, endDate, password));
}

@Override
@GetMapping("/space/count/user-only")
public ResponseEntity<AdminSpaceCountGetResponse> getSpaceCount(
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate,
@RequestParam("password") String password) {
return ResponseEntity.ok(adminService.getSpaceCount(startDate, endDate, password));
}

@Override
@GetMapping("/retrospect/count/user-only")
public ResponseEntity<AdminRetrospectCountGetResponse> getRetrospectCount(
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate,
@RequestParam("password") String password) {

return ResponseEntity.ok(adminService.getRetrospectCount(startDate, endDate, password));
}

@Override
@GetMapping("space/{spaceId}/retrospect/count")
public ResponseEntity<AdminRetrospectCountGetResponse> getRetrospectCountInSpace(@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate,
@PathVariable("spaceId") Long spaceId,
@RequestParam("password") String password) {
return ResponseEntity.ok(adminService.getRetrospectCountInSpace(startDate, endDate, spaceId, password));
}

@Override
@GetMapping("/retrospect/count/group-by-space")
public ResponseEntity<List<AdminRetrospectCountGroupBySpaceGetResponse>> getRetrospectCountGroupBySpace(LocalDateTime startDate, LocalDateTime endDate, String password) {
return ResponseEntity.ok(adminService.getRetrospectCountGroupSpace(startDate, endDate, password));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.layer.domain.admin.controller.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "AdminSpaceCountGetResponse", description = "우리 팀이 만든 스페이스에서 진행된 회고를 제외하고 기간 내에 시작된 회고 수를 리턴합니다.")
public record AdminRetrospectCountGetResponse(
@Schema(description = "기간 내에 만들어진 회고 개수", example = "20")
Long retrospectCount) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.layer.domain.admin.controller.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "AdminSpaceCountGetResponse", description = "우리 팀이 만든 스페이스를 제외하고 기간 내에 만들어진 스페이스 개수를 리턴합니다.")
public record AdminSpaceCountGetResponse(
@Schema(description = "기간 내에 만들어진 스페이스 개수", example = "11")
Long spaceCount) {
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.layer.domain.admin.service;

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

import lombok.RequiredArgsConstructor;
import org.layer.domain.admin.controller.dto.AdminRetrospectCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminRetrospectsGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpaceCountGetResponse;
import org.layer.domain.admin.controller.dto.AdminSpacesGetResponse;
import org.layer.domain.retrospect.dto.AdminRetrospectCountGroupBySpaceGetResponse;
import org.layer.domain.retrospect.dto.AdminRetrospectGetResponse;
import org.layer.domain.retrospect.repository.RetrospectAdminRepository;
import org.layer.domain.space.dto.AdminSpaceGetResponse;
import org.layer.domain.space.entity.Space;
import org.layer.domain.space.repository.SpaceAdminRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -49,4 +49,39 @@ public AdminRetrospectsGetResponse getRetrospectData(LocalDateTime startDate, Lo

return new AdminRetrospectsGetResponse(retrospects, retrospects.size());
}

public AdminSpaceCountGetResponse getSpaceCount(LocalDateTime startDate, LocalDateTime endDate, String requestPassword) {
if(!requestPassword.equals(password)) {
throw new IllegalArgumentException("비밀번호가 틀렸습니다.");
}

Long count = spaceAdminRepository.countSpacesExceptForAdminSpace(startDate, endDate);
return new AdminSpaceCountGetResponse(count);
}

public AdminRetrospectCountGetResponse getRetrospectCount(LocalDateTime startDate, LocalDateTime endDate, String requestPassword) {
if(!requestPassword.equals(password)) {
throw new IllegalArgumentException("비밀번호가 틀렸습니다.");
}

Long count = retrospectAdminRepository.countRetrospectsExceptForAdminSpace(startDate, endDate);
return new AdminRetrospectCountGetResponse(count);
}

public AdminRetrospectCountGetResponse getRetrospectCountInSpace(LocalDateTime startDate, LocalDateTime endDate, Long spaceId, String requestPassword) {
if(!requestPassword.equals(password)) {
throw new IllegalArgumentException("비밀번호가 틀렸습니다.");
}

Long count = retrospectAdminRepository.countRetrospectsBySpaceId(spaceId, startDate, endDate);
return new AdminRetrospectCountGetResponse(count);
}

public List<AdminRetrospectCountGroupBySpaceGetResponse> getRetrospectCountGroupSpace(LocalDateTime startDate, LocalDateTime endDate, String requestPassword) {
if(!requestPassword.equals(password)) {
throw new IllegalArgumentException("비밀번호가 틀렸습니다.");
}

return retrospectAdminRepository.countRetrospectsGroupBySpace(startDate, endDate);
}
}
1 change: 1 addition & 0 deletions layer-api/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ google:
sheet:
id: ${GOOGLE_SHEET_ID}
token_path: ${LOCAL_GOOGLE_TOKEN_PATH}
credential_path: ${PROD_GOOGLE_CREDENTIAL_PATH}

apple:
login:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.layer.domain.retrospect.dto;

import lombok.*;
import org.layer.domain.member.entity.Member;
import org.layer.domain.space.entity.Space;

import java.time.LocalDateTime;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AdminRetrospectCountGroupBySpaceGetResponse {
private Long spaceId;
private String spaceName;
private LocalDateTime spaceCreatedAt;
private Long leaderId;
private String leaderEmail;
private String leaderName;
private Long retrospectCount;
public AdminRetrospectCountGroupBySpaceGetResponse of(Space space, Member leader, Long retrospectCount) {
return AdminRetrospectCountGroupBySpaceGetResponse.builder()
.spaceId(space.getId())
.spaceName(space.getName())
.leaderId(leader.getId())
.leaderEmail(leader.getEmail())
.spaceCreatedAt(space.getCreatedAt())
.leaderName(leader.getName())
.retrospectCount(retrospectCount)
.build();
}

public AdminRetrospectCountGroupBySpaceGetResponse(Space space, Member member, Long retrospectCount) {
this.spaceId = space.getId();
this.spaceName = space.getName();
this.spaceCreatedAt = space.getCreatedAt();
this.leaderId = member.getId();
this.leaderName = member.getName();
this.leaderEmail = member.getEmail();
this.retrospectCount = retrospectCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.layer.domain.retrospect.repository;

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

import org.layer.domain.retrospect.dto.AdminRetrospectCountGroupBySpaceGetResponse;
import org.layer.domain.retrospect.dto.AdminRetrospectGetResponse;
import org.layer.domain.retrospect.entity.Retrospect;
import org.layer.domain.space.dto.AdminSpaceGetResponse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface RetrospectAdminRepository extends JpaRepository<Retrospect, Long> {

@Query
Expand All @@ -23,4 +23,41 @@ public interface RetrospectAdminRepository extends JpaRepository<Retrospect, Lon
List<AdminRetrospectGetResponse> findAllByCreatedAtAfterAndCreatedAtBefore(
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate);

// ADMIN 유저가 만든 스페이스에서 진행된 회고 제외
@Query("SELECT count(*)"
+ "FROM Retrospect r "
+ "JOIN Space s ON r.spaceId = s.id "
+ "JOIN Member m ON s.leaderId = m.id "
+ "WHERE r.createdAt >= :startDate "
+ "AND r.createdAt <= :endDate "
+ "AND m.memberRole = 'USER'"
)
Long countRetrospectsExceptForAdminSpace(@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate);


@Query("SELECT count(*)"
+ "FROM Retrospect r "
+ "JOIN Space s ON r.spaceId = s.id "
+ "JOIN Member m ON s.leaderId = m.id "
+ "WHERE r.spaceId = :spaceId "
+ "AND r.createdAt >= :startDate "
+ "AND r.createdAt <= :endDate"
)
Long countRetrospectsBySpaceId(@Param("spaceId") Long spaceId,
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate);

@Query("SELECT new org.layer.domain.retrospect.dto.AdminRetrospectCountGroupBySpaceGetResponse(s, m, COUNT(r)) "
+ "FROM Retrospect r "
+ "JOIN Space s ON r.spaceId = s.id "
+ "JOIN Member m ON s.leaderId = m.id "
+ "WHERE r.createdAt >= :startDate "
+ "AND r.createdAt <= :endDate "
+ "AND m.memberRole = 'USER' "
+ "GROUP BY s"
)
List<AdminRetrospectCountGroupBySpaceGetResponse> countRetrospectsGroupBySpace(@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.layer.domain.space.repository;

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

import org.layer.domain.space.dto.AdminSpaceGetResponse;
import org.layer.domain.space.entity.Space;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface SpaceAdminRepository extends JpaRepository<Space, Long> {

@Query
Expand All @@ -22,4 +22,18 @@ List<AdminSpaceGetResponse> findAllByCreatedAtAfterAndCreatedAtBefore(
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate
);


// ADMIN 유저가 만든 스페이스 제외
@Query("SELECT count(*)"
+ "FROM Space s "
+ "JOIN Member m ON s.leaderId = m.id "
+ "WHERE s.createdAt >= :startDate "
+ "AND s.createdAt <= :endDate "
+ "AND m.memberRole = 'USER'"
)
Long countSpacesExceptForAdminSpace(
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate
);
}

0 comments on commit c6953e5

Please sign in to comment.