Skip to content

Commit

Permalink
Merge pull request #129 from Katchup-dev/feat/#127-update-card
Browse files Browse the repository at this point in the history
[FEAT] 업무 카드 수정 API
  • Loading branch information
yeseul106 authored Aug 26, 2023
2 parents 247760e + e5fa4d4 commit 07d7978
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.web.bind.annotation.*;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardUpdateRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.service.CardService;
import site.katchup.katchupserver.common.dto.ApiResponseDto;
Expand Down Expand Up @@ -65,4 +66,19 @@ public ApiResponseDto deleteCards(@RequestBody final CardDeleteRequestDto cardDe
cardService.deleteCardList(cardDeleteRequestDto);
return ApiResponseDto.success();
}

@Operation(summary = "업무 카드 수정 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "업무 카드 수정 성공"),
@ApiResponse(responseCode = "400", description = "업무 카드 수정 실패", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PatchMapping("/{cardId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto updateCard(Principal principal, @PathVariable Long cardId,
@Valid @RequestBody CardUpdateRequestDto cardUpdateRequestDto ) {
Long memberId = MemberUtil.getMemberId(principal);
cardService.updateCard(memberId, cardId, cardUpdateRequestDto);
return ApiResponseDto.success();
}
}
10 changes: 10 additions & 0 deletions src/main/java/site/katchup/katchupserver/api/card/domain/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import site.katchup.katchupserver.api.file.domain.File;
import site.katchup.katchupserver.api.file.dto.request.FileCreateRequestDto;
import site.katchup.katchupserver.api.link.domain.Link;
import site.katchup.katchupserver.api.screenshot.domain.Screenshot;
import site.katchup.katchupserver.api.screenshot.dto.request.ScreenshotCreateRequestDto;
import site.katchup.katchupserver.api.subTask.domain.SubTask;
import site.katchup.katchupserver.common.domain.BaseEntity;

Expand Down Expand Up @@ -73,4 +75,12 @@ public void deletedCard() {
public void plusPlacementOrder() {
this.placementOrder += 1;
}

public void updateCard(Long placementOrder, String content, String note, SubTask subTask) {
this.placementOrder = placementOrder;
this.content = content;
this.note = note;
this.subTask = subTask;
this.subTask.addCard(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.Getter;
import site.katchup.katchupserver.api.file.dto.request.FileCreateRequestDto;
import site.katchup.katchupserver.api.screenshot.dto.request.ScreenshotCreateRequestDto;
import site.katchup.katchupserver.api.sticker.dto.request.StickerCreateRequestDto;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package site.katchup.katchupserver.api.card.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import site.katchup.katchupserver.api.file.dto.request.FileCreateRequestDto;
import site.katchup.katchupserver.api.screenshot.dto.request.ScreenshotCreateRequestDto;

import java.util.List;

@AllArgsConstructor(staticName = "of")
@Getter
public class CardUpdateRequestDto {
@NotNull(message = "CD-110")
private Long categoryId;

@NotNull(message = "CD-111")
private Long taskId;

@Schema(description = "세부 업무 작성 안할 시, 해당 값 0으로")
@NotNull(message = "CD-112")
private Long subTaskId;

@NotNull(message = "CD-113")
private List<Long> keywordIdList;

private List<ScreenshotCreateRequestDto> screenshotList;

private List<FileCreateRequestDto> fileList;

private String note;

@NotBlank(message = "CD-114")
private String content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.transaction.annotation.Transactional;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardUpdateRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.response.CardListGetResponseDto;

Expand All @@ -15,5 +16,6 @@ public interface CardService {
CardGetResponseDto getCard(Long cardId);
void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto);
void createCard(Long memberId, CardCreateRequestDto cardCreateRequestDto);
void updateCard(Long memberId, Long cardId, CardUpdateRequestDto cardUpdateRequestDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardUpdateRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.response.CardListGetResponseDto;
import site.katchup.katchupserver.api.file.domain.File;
Expand Down Expand Up @@ -36,6 +37,8 @@
import site.katchup.katchupserver.api.task.repository.TaskRepository;
import site.katchup.katchupserver.api.trash.domain.Trash;
import site.katchup.katchupserver.api.trash.repository.TrashRepository;
import site.katchup.katchupserver.common.exception.BadRequestException;
import site.katchup.katchupserver.common.response.ErrorCode;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -151,7 +154,56 @@ public void createCard(Long memberId, CardCreateRequestDto requestDto) {

fileRepository.save(newFile);
}
}

@Override
@Transactional
public void updateCard(Long memberId, Long cardId, CardUpdateRequestDto requestDto) {

SubTask subTask;
if (requestDto.getSubTaskId() == SUB_TASK_ETC_ID) {
Task task = taskRepository.findByIdOrThrow(requestDto.getTaskId());
subTask = subTaskRepository.findOrCreateEtcSubTask(task, SUB_TASK_ETC_NAME);
} else {
subTask = subTaskRepository.findByIdOrThrow(requestDto.getSubTaskId());
}

Card card = cardRepository.findByIdOrThrow(cardId);
card.updateCard(getPlacementOrder(subTask), requestDto.getContent(), requestDto.getNote(), subTask);

List<CardKeyword> cardKeywordList = cardKeywordRepository.findAllByCardId(cardId);
cardKeywordRepository.deleteAll(cardKeywordList);

for (Long keywordId : requestDto.getKeywordIdList()) {
CardKeyword cardKeyword = CardKeyword.builder()
.card(card)
.keyword(keywordRepository.findByIdOrThrow(keywordId))
.build();
cardKeywordRepository.save(cardKeyword);
}

for (ScreenshotCreateRequestDto screenshotInfo : requestDto.getScreenshotList()) {
Screenshot newScreenshot = Screenshot.builder()
.id(screenshotInfo.getScreenshotUUID())
.screenshotKey(screenshotService.createKey(memberId, screenshotInfo))
.url(screenshotService.findUrl(memberId, screenshotInfo))
.card(card)
.build();

screenshotRepository.save(newScreenshot);
}

for (FileCreateRequestDto fileInfo : requestDto.getFileList()) {
File newFile = File.builder()
.id(fileInfo.getFileUUID())
.fileKey(fileService.createKey(memberId, fileInfo))
.name(fileInfo.getFileName())
.size(fileInfo.getSize())
.card(card)
.build();

fileRepository.save(newFile);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import org.springframework.data.jpa.repository.JpaRepository;
import site.katchup.katchupserver.api.keyword.domain.CardKeyword;
import site.katchup.katchupserver.api.keyword.domain.Keyword;

import java.util.List;

public interface CardKeywordRepository extends JpaRepository<CardKeyword, Long> {
List<CardKeyword> findAllByCardId(Long cardId);

}

0 comments on commit 07d7978

Please sign in to comment.