Repository navigation
feat: 내 템플릿 수정 API (#52) #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4079064
fix: 템플릿 UPDATE가 바뀐 컬럼만 쓰도록 변경 (#52)
oTAETAEo 8e7d88c
feat: 자기 단축어를 제외하는 내 템플릿 수정 서비스 구현 (#52)
oTAETAEo 099ff2e
feat: 내 템플릿 수정 API 구현 (#52)
oTAETAEo 7287bff
refactor: 템플릿 서비스 의존성 필드 순서 정리 (#52)
oTAETAEo d10fbb3
refactor: 템플릿 서비스 필드 들여쓰기를 탭으로 수정 (#52)
oTAETAEo bf280f9
refactor: 수정 중 휴지통 이동 경쟁을 허용하는 이유를 주석으로 남김 (#52)
oTAETAEo dd714e8
Merge remote-tracking branch 'origin/feat/49-template-detail' into fe…
oTAETAEo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/sniptext/domain/template/controller/dto/TemplateUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.sniptext.domain.template.controller.dto; | ||
|
|
||
| import com.sniptext.domain.template.annotation.ValidShortcut; | ||
| import com.sniptext.domain.template.annotation.ValidTemplateContent; | ||
| import com.sniptext.domain.template.annotation.ValidTemplateTitle; | ||
| import com.sniptext.domain.template.service.dto.command.TemplateUpdateCommand; | ||
|
|
||
| /** | ||
| * 템플릿 수정 (명세 11번). 세 필드를 모두 보내는 전체 수정이다. | ||
| * 여러 개가 틀리면 선언 순서상 첫 에러 하나만 내려주므로 이름 → 단축어 → 내용 순서를 지킨다. | ||
| * 공백·길이 기준이 화면과 같도록 @NotBlank·@Size 대신 값 객체 규칙을 쓰는 검증만 붙인다. | ||
| */ | ||
| public record TemplateUpdateRequest( | ||
| @ValidTemplateTitle String title, | ||
| @ValidShortcut String shortcut, | ||
| @ValidTemplateContent String content | ||
| ) { | ||
|
|
||
| public TemplateUpdateCommand toCommand(Long userId, Long templateId) { | ||
| return new TemplateUpdateCommand(userId, templateId, title, shortcut, content); | ||
| } | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/sniptext/domain/template/controller/dto/TemplateUpdateResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.sniptext.domain.template.controller.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import com.sniptext.domain.template.service.dto.result.TemplateUpdateResult; | ||
|
|
||
| /** 템플릿 수정 결과 (명세 11번). 시각은 전역 직렬화 설정이 +09:00을 붙여 내보낸다. */ | ||
| public record TemplateUpdateResponse( | ||
| Long templateId, | ||
| String title, | ||
| String shortcut, | ||
| String content, | ||
| List<String> variables, | ||
| LocalDateTime lastUsedAt, | ||
| LocalDateTime createdAt, | ||
| LocalDateTime editedAt | ||
| ) { | ||
|
|
||
| public static TemplateUpdateResponse from(TemplateUpdateResult result) { | ||
| return new TemplateUpdateResponse( | ||
| result.templateId(), | ||
| result.title(), | ||
| result.shortcut(), | ||
| result.content(), | ||
| result.variables(), | ||
| result.lastUsedAt(), | ||
| result.createdAt(), | ||
| result.editedAt() | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/sniptext/domain/template/service/dto/command/TemplateUpdateCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.sniptext.domain.template.service.dto.command; | ||
|
|
||
| /** 템플릿 수정 입력. 값은 요청 단계에서 형식 검증을 마친 입력 그대로이고, 정규화는 값 객체가 한다. */ | ||
| public record TemplateUpdateCommand( | ||
| Long userId, | ||
| Long templateId, | ||
| String title, | ||
| String shortcut, | ||
| String content | ||
| ) { | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/sniptext/domain/template/service/dto/result/TemplateUpdateResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.sniptext.domain.template.service.dto.result; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import com.sniptext.domain.template.entity.Template; | ||
| import com.sniptext.domain.template.support.TemplateVariableExtractor; | ||
|
|
||
| /** 수정한 템플릿. 변수 목록은 저장하지 않고 본문에서 뽑는다. */ | ||
| public record TemplateUpdateResult( | ||
| Long templateId, | ||
| String title, | ||
| String shortcut, | ||
| String content, | ||
| List<String> variables, | ||
| LocalDateTime lastUsedAt, | ||
| LocalDateTime createdAt, | ||
| LocalDateTime editedAt | ||
| ) { | ||
|
|
||
| public static TemplateUpdateResult from(Template template) { | ||
| String content = template.getContent().getValue(); | ||
| return new TemplateUpdateResult( | ||
| template.getId(), | ||
| template.getTitle().getValue(), | ||
| template.getShortcut().getValue(), | ||
| content, | ||
| TemplateVariableExtractor.extract(content), | ||
| template.getLastUsedAt(), | ||
| template.getCreatedAt(), | ||
| template.getEditedAt() | ||
| ); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조회와 저장 사이에 다른 탭에서 휴지통으로 옮기면, 휴지통 템플릿에 수정이 들어가고 200이 나갈 것 같은데 맞을까요?!
창이 아주 짧아서 지금은 허용해도 될 것 같은데, 허용한다면 주석에 한 줄 남겨 주면 좋겠습니다! 막으려면
UPDATE조건에deleted_at IS NULL을 거는 방법도 방법 고려해주시면 좋을 거 같아요!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chjpooh2002 말씀해 주신 부분으로 다시한번 보니까 일어날수 있는 상황인것 같습니당 👏
... templateQueryService.getActiveTemplate(command.userId(), command.templateId());해당 라인이 실행이 되어서 조회 후에 마지막
return사이에 발생할수 있는 문제 인걸로 이해 했습니다조회와 저장 사이에 휴지통으로 옮기면 200이 동작은 서비스 이용에는 큰 문제는 없을것 같은 생각이기도 하구
@DynamicUpdate로deleted_at은 되돌아가지 않아서 삭제한 게 다시 풀리지는 않고, 구간이 짧아서 괜찮을 것 같습니다.deleted_at IS NULL조건은 변경 감지 대신@Modifying으로 바꿔야 해서 넣지 않았고, 주석에 남겨 두려고 하는데 다른 의견 있으시면 남겨주세여 !There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 그 판단이 맞다고 봅니다! 휴지통 템플릿은 단축어 점유가 풀려 있어서 충돌도 없고, 복구하면 고친 내용이 남는 정도라 실제 피해가 거의 없네요.
말씀대로 제가 처음 말한 조건부
UPDATE는 변경 감지를 버려야 해서 과했던 것 같아요. 나중에 막아야 하는 상황이 오면 수정용 조회만FOR UPDATE로 잠그는 방법이 있어서, 변경 감지는 그대로 두고 휴지통 이동이 먼저 끝난 경우404_2를 낼 수 있어요. 주석에 그 선택지도 같이 적어 두면 좋겠습니다!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다 !