Skip to content

Commit

Permalink
codesquad-issue-team-05#80 feat : 이슈 내용 수정 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
DOEKYONG committed Aug 14, 2023
1 parent d014f49 commit 9d6ffbe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import codesquad.issueTracker.global.common.ApiResponse;
import codesquad.issueTracker.issue.dto.IssueWriteRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto;
import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto;
import codesquad.issueTracker.issue.service.IssueService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -46,4 +48,10 @@ public ApiResponse<String> patchInDetailStatus(@PathVariable Long id,
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/content")
public ApiResponse<ModifyIssueContentResponseDto> patchContent(@PathVariable Long id,
@RequestBody ModifyIssueContentRequestDto request) {
ModifyIssueContentResponseDto response = issueService.modifyIssueContent(id, request);
return ApiResponse.success(SUCCESS.getStatus(), response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package codesquad.issueTracker.issue.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ModifyIssueContentRequestDto {
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package codesquad.issueTracker.issue.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ModifyIssueContentResponseDto {
String modifiedContent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ public Long modifyStatus(Long issueId, Boolean status) {
.isClosed(rs.getBoolean("is_closed"))
.build();

public Long updateContent(Long id, String modifiedContent) {
String sql = "UPDATE issues SET content = :modifiedContent WHERE Id = :id";
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("id", id)
.addValue("modifiedContent", modifiedContent);
jdbcTemplate.update(sql, parameterSource);
return id;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import codesquad.issueTracker.global.exception.ErrorCode;
import codesquad.issueTracker.issue.domain.Issue;
import codesquad.issueTracker.issue.dto.IssueWriteRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto;
import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto;
import codesquad.issueTracker.issue.repository.IssueRepository;
import codesquad.issueTracker.label.service.LabelService;
Expand Down Expand Up @@ -96,4 +98,11 @@ public Long modifyIssueStatusInDetail(Long id, ModifyIssueStatusRequestDto reque
private Issue validateExistIssue(Long issuesIds) {
return issueRepository.findById(issuesIds).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES));
}

@Transactional
public ModifyIssueContentResponseDto modifyIssueContent(Long id, ModifyIssueContentRequestDto request) {
String modifiedContent = request.getContent();
issueRepository.updateContent(id, modifiedContent);
return new ModifyIssueContentResponseDto(modifiedContent);
}
}

0 comments on commit 9d6ffbe

Please sign in to comment.