Skip to content

Commit

Permalink
feat: 스페이스에 속한 커스텀 폼 목록 조회 (#109)
Browse files Browse the repository at this point in the history
* feat: 스페이스에 속한 커스텀 폼 목록 조회

* fix: schema example 수정

* chore: custom template response spaceId 제거
  • Loading branch information
clean2001 authored Aug 3, 2024
1 parent 449f356 commit 4975078
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.layer.common.annotation.MemberId;
import org.layer.domain.form.controller.dto.request.FormNameUpdateRequest;
import org.layer.domain.form.controller.dto.request.RecommendFormQueryDto;
import org.layer.domain.form.controller.dto.response.CustomTemplateListResponse;
import org.layer.domain.form.controller.dto.response.FormGetResponse;
import org.layer.domain.form.controller.dto.response.RecommendFormResponseDto;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -38,4 +40,7 @@ ResponseEntity<RecommendFormResponseDto> getRecommendTemplate(@ModelAttribute @V

@Operation(summary = "커스텀 템플릿 삭제", method = "DELETE", description = "커스텀 템플릿을 삭제합니다.")
ResponseEntity<Void> deleteFormTitle(@PathVariable Long formId, @MemberId Long memberId);

@Operation(summary = "스페이스에 속한 커스텀 템플릿 목록 조회", method = "GET", description = "스페이스의 커스텀 템플릿을 모두 조회합니다. (스페이스에 속한 팀원이라면 조회 가능)")
ResponseEntity<CustomTemplateListResponse> getCustomTemplateList(Pageable pageable, @PathVariable Long spaceId, @MemberId Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package org.layer.domain.form.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.layer.common.annotation.MemberId;
import org.layer.domain.form.controller.dto.request.FormNameUpdateRequest;
import org.layer.domain.form.controller.dto.request.RecommendFormQueryDto;
import org.layer.domain.form.controller.dto.response.CustomTemplateListResponse;
import org.layer.domain.form.controller.dto.response.FormGetResponse;
import org.layer.domain.form.controller.dto.response.RecommendFormResponseDto;
import org.layer.domain.form.service.FormService;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -61,4 +57,10 @@ public ResponseEntity<Void> deleteFormTitle(@PathVariable Long formId, @MemberId
return ResponseEntity.ok().build();
}

@Override
@GetMapping("/space/{spaceId}/custom-template")
public ResponseEntity<CustomTemplateListResponse> getCustomTemplateList(@PageableDefault(size=10) Pageable pageable, @PathVariable(name = "spaceId") Long spaceId, @MemberId Long memberId) {
CustomTemplateListResponse response = formService.getCustomTemplateList(pageable, spaceId, memberId);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.layer.domain.form.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import org.springframework.data.domain.Page;

@Builder
@Schema(name = "CustomFormGetResponse", description = "커스텀 템플릿 조회 응답 Dto")
public record CustomTemplateListResponse(
@NotNull
@Schema(description = "커스템 템플릿 객체 목록")
Page<CustomTemplateResponse> customTemplateList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.layer.domain.form.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
@Schema(name = "DefaultFormGetResponse", description = "커스텀 템플릿 조회 간단 정보 응답 Dto")
public record CustomTemplateResponse(
@NotNull
@Schema(description = "회고폼 이름", example = "Mad Sad Glad 커스텀 템플릿")
String title,
@NotNull
@Schema(description = "태그", example = "Mad Sad Glad")
String formTag,
@NotNull
@Schema(description = "폼 생성일자", example = "2024-08-03T21:40:52.880535")
LocalDateTime createdAt
) {
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package org.layer.domain.form.service;

import java.util.List;
import java.util.Random;

import lombok.RequiredArgsConstructor;
import org.layer.domain.form.controller.dto.request.FormNameUpdateRequest;
import org.layer.domain.form.controller.dto.request.RecommendFormQueryDto;
import org.layer.domain.form.controller.dto.response.FormGetResponse;
import org.layer.domain.form.controller.dto.response.QuestionGetResponse;
import org.layer.domain.form.controller.dto.response.RecommendFormResponseDto;
import org.layer.domain.form.controller.dto.response.*;
import org.layer.domain.form.entity.Form;
import org.layer.domain.form.entity.FormType;
import org.layer.domain.form.exception.FormException;
import org.layer.domain.form.repository.FormRepository;
import org.layer.domain.question.entity.Question;
import org.layer.domain.question.repository.QuestionRepository;
import org.layer.domain.space.entity.MemberSpaceRelation;
import org.layer.domain.space.entity.Space;
import org.layer.domain.space.entity.Team;
import org.layer.domain.space.repository.MemberSpaceRelationRepository;
import org.layer.domain.space.repository.SpaceRepository;
import org.layer.domain.tag.entity.Tag;
import org.layer.domain.tag.repository.TagRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Optional;
import java.util.Random;

import static org.layer.common.exception.FormExceptionType.UNAUTHORIZED_GET_FORM;
import static org.layer.domain.form.entity.FormType.CUSTOM;

@Service
@RequiredArgsConstructor
Expand All @@ -42,7 +46,7 @@ public FormGetResponse getForm(Long formId, Long memberId) {
List<Tag> tags = tagRepository.findAllByFormId(formId);

// 해당 스페이스 팀원인지 검증
if (form.getFormType().equals(FormType.CUSTOM)) {
if (form.getFormType().equals(CUSTOM)) {
Team team = new Team(memberSpaceRelationRepository.findAllBySpaceId(form.getSpaceId()));
team.validateTeamMembership(memberId);
}
Expand Down Expand Up @@ -96,4 +100,20 @@ private void validateIsLeader(Long memberId, Form form) {
space.isLeaderSpace(memberId);
}

public CustomTemplateListResponse getCustomTemplateList(Pageable pageable, Long spaceId, Long memberId) {
// 멤버가 스페이스에 속하는지 검증
Optional<MemberSpaceRelation> spaceMemberRelation = memberSpaceRelationRepository.findBySpaceIdAndMemberId(spaceId, memberId);
if(spaceMemberRelation.isEmpty()) {
throw new FormException(UNAUTHORIZED_GET_FORM);
}

Page<Form> customFormList = formRepository.findAllByFormTypeOrderByIdDesc(pageable, CUSTOM);

Page<CustomTemplateResponse> customFormResList = customFormList.map(form -> new CustomTemplateResponse(form.getTitle(), form.getFormTag().getTag(), form.getCreatedAt()));

return CustomTemplateListResponse.builder()
.spaceId(spaceId)
.customTemplateList(customFormResList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.layer.domain.retrospect.controller.dto.request;

import org.layer.domain.question.enums.QuestionType;

import io.swagger.v3.oas.annotations.media.Schema;
import org.layer.domain.form.controller.dto.response.CustomTemplateResponse;
import org.layer.domain.form.enums.FormTag;

import java.time.LocalDateTime;

@Schema(name = "QuestionCreateRequest", description = "질문 객체 생성 요청 Dto")
public record QuestionCreateRequest(
Expand All @@ -11,4 +13,12 @@ public record QuestionCreateRequest(
@Schema(description = "질문 타입", example = "plain_text")
String questionType
) {

public static CustomTemplateResponse of(String title, FormTag formTag, LocalDateTime createdAt) {
return CustomTemplateResponse.builder()
.title(title)
.formTag(formTag.getTag())
.createdAt(createdAt)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public enum FormExceptionType implements ExceptionType {

UNAUTHORIZED_UPDATE_FORM(HttpStatus.UNAUTHORIZED, "회고 폼 수정 권한이 없습니다."),
UNAUTHORIZED_GET_FORM(HttpStatus.UNAUTHORIZED, "회고 폼 조회 권한이 없습니다."),
NOT_FOUND_FORM(HttpStatus.NOT_FOUND, "찾을 수 없는 회고폼(커스텀 템플릿) 입니다.");

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.layer.domain.form.entity.Form;
import org.layer.domain.form.entity.FormType;
import org.layer.domain.form.exception.FormException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
Expand All @@ -17,5 +19,6 @@ default Form findByIdOrThrow(Long formId) {

List<Form> findByFormTypeOrderById(FormType formType);

Page<Form> findAllByFormTypeOrderByIdDesc(Pageable pageable, FormType formType);

}

0 comments on commit 4975078

Please sign in to comment.