Skip to content

Commit

Permalink
feat: 디폴트 폼 작업 진행 (#135)
Browse files Browse the repository at this point in the history
* feat: 디폴트 폼 설정 API 구현

* chore: 회고 생성시 디폴트 폼 작업
  • Loading branch information
mikekks authored Aug 9, 2024
1 parent 4efd7ab commit 5c6bd38
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.request.RecommendFormSetRequest;
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;
Expand Down Expand Up @@ -43,4 +44,7 @@ ResponseEntity<RecommendFormResponseDto> getRecommendTemplate(@ModelAttribute @V

@Operation(summary = "스페이스에 속한 커스텀 템플릿 목록 조회", method = "GET", description = "스페이스의 커스텀 템플릿을 모두 조회합니다. (스페이스에 속한 팀원이라면 조회 가능)")
ResponseEntity<CustomTemplateListResponse> getCustomTemplateList(Pageable pageable, @PathVariable Long spaceId, @MemberId Long memberId);

@Operation(summary = "추천 템플릿 설정", method = "POST", description = "추천 템플릿을 설정하는 기능입니다.")
ResponseEntity<Void> setRecommendTemplate(@RequestBody @Valid RecommendFormSetRequest request, @MemberId Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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.request.RecommendFormSetRequest;
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;
Expand Down Expand Up @@ -39,6 +41,15 @@ public ResponseEntity<RecommendFormResponseDto> getRecommendTemplate(
return ResponseEntity.ok().body(response);
}

@Override
@PostMapping("/recommend")
public ResponseEntity<Void> setRecommendTemplate(@RequestBody @Valid RecommendFormSetRequest request,
@MemberId Long memberId) {

formService.setRecommendTemplate(request, memberId);
return ResponseEntity.ok().build();
}

@Override
@PatchMapping("/{formId}/title")
public ResponseEntity<Void> updateFormTitle(@PathVariable Long formId,
Expand All @@ -59,7 +70,9 @@ public ResponseEntity<Void> deleteFormTitle(@PathVariable Long formId, @MemberId

@Override
@GetMapping("/space/{spaceId}/custom-template")
public ResponseEntity<CustomTemplateListResponse> getCustomTemplateList(@PageableDefault(size=10) Pageable pageable, @PathVariable(name = "spaceId") Long spaceId, @MemberId Long memberId) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
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.*;
import org.layer.domain.form.controller.dto.request.RecommendFormSetRequest;
import org.layer.domain.form.controller.dto.response.CustomTemplateListResponse;
import org.layer.domain.form.controller.dto.response.CustomTemplateResponse;
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.entity.Form;
import org.layer.domain.form.exception.FormException;
import org.layer.domain.form.repository.FormRepository;
Expand Down Expand Up @@ -72,7 +77,7 @@ public RecommendFormResponseDto getRecommendTemplate(RecommendFormQueryDto query
}

@Transactional
public void updateFormTitle(Long formId, FormNameUpdateRequest request, Long memberId){
public void updateFormTitle(Long formId, FormNameUpdateRequest request, Long memberId) {
Form form = formRepository.findByIdOrThrow(formId);

validateIsLeader(memberId, form);
Expand All @@ -81,7 +86,7 @@ public void updateFormTitle(Long formId, FormNameUpdateRequest request, Long mem
}

@Transactional
public void deleteFormTitle(Long formId, Long memberId){
public void deleteFormTitle(Long formId, Long memberId) {
Form form = formRepository.findByIdOrThrow(formId);

validateIsLeader(memberId, form);
Expand Down Expand Up @@ -109,7 +114,19 @@ public CustomTemplateListResponse getCustomTemplateList(Pageable pageable, Long
Page<CustomTemplateResponse> customFormResList = customFormList.map(form -> new CustomTemplateResponse(form.getId(), form.getTitle(), form.getFormTag().getTag(), form.getCreatedAt()));

return CustomTemplateListResponse.builder()
.customTemplateList(customFormResList)
.build();
.customTemplateList(customFormResList)
.build();
}

@Transactional
public void setRecommendTemplate(RecommendFormSetRequest request, Long memberId) {
// 팀 소속 여부 검증 로직
Team team = new Team(memberSpaceRelationRepository.findAllBySpaceId(request.spaceId()));
team.validateTeamMembership(memberId);

Form form = formRepository.findByIdOrThrow(request.formId());

Space space = spaceRepository.findByIdOrThrow(request.spaceId());
space.updateRecentFormId(form.getId(), memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public Long createRetrospect(RetrospectCreateRequest request, Long spaceId, Long

List<Question> myQuestions = getQuestions(request.questions(), null, savedForm.getId());
questionRepository.saveAll(myQuestions);

// 스페이스 최근 폼 수정
Space space = spaceRepository.findByIdOrThrow(spaceId);
space.updateRecentFormId(savedForm.getId(), memberId);
}

return savedRetrospect.getId();
}

Expand Down

0 comments on commit 5c6bd38

Please sign in to comment.