Skip to content
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

[be] 이슈 수정, 이슈상태 수정,이슈 옵션 수정 #91

Merged
merged 11 commits into from
Aug 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum ErrorCode implements StatusCode {
ALREADY_DELETED_COMMENT(HttpStatus.BAD_REQUEST, "이미 삭제된 댓글입니다."),
FAILED_CREATE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 생성에 실패했습니다."),
FAILED_UPDATE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 수정에 실패했습니다."),
FAILED_DELETE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE,"DB 서버 오류로 인해 댓글 삭제에 실패했습니다."),
FAILED_DELETE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 삭제에 실패했습니다."),

// -- [Milestone] -- //
INVALIDATE_DATE(HttpStatus.BAD_REQUEST, "현재 날짜보다 이전 날짜 입니다."),
Expand All @@ -51,10 +51,9 @@ public enum ErrorCode implements StatusCode {
LABEL_DELETE_FAILED(HttpStatus.BAD_REQUEST, "DB에서 라벨 삭제에 실패했습니다"),
LABEL_FIND_FAILED(HttpStatus.BAD_REQUEST, "서버 오류로 라벨을 조회할 수 없습니다"),


// -- [Issue] -- //
DUPLICATE_OBJECT_FOUND(HttpStatus.BAD_REQUEST, "중복된 항목 선택입니다.");

DUPLICATE_OBJECT_FOUND(HttpStatus.BAD_REQUEST, "중복된 항목 선택입니다."),
NOT_FOUND_ISSUES(HttpStatus.BAD_REQUEST, "이슈를 찾을 수 없습니다.");

private HttpStatus status;
private String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import codesquad.issueTracker.global.common.ApiResponse;
import codesquad.issueTracker.issue.dto.IssueWriteRequestDto;
import codesquad.issueTracker.issue.dto.ModifyAssigneeRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto;
import codesquad.issueTracker.issue.dto.ModifyIssueMilestoneDto;
import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto;
import codesquad.issueTracker.issue.dto.ModifyIssueTitleRequest;
import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse;
import codesquad.issueTracker.issue.dto.ModifyLabelRequestDto;
import codesquad.issueTracker.issue.service.IssueService;
import lombok.RequiredArgsConstructor;

Expand All @@ -29,4 +40,55 @@ public ApiResponse<String> postIssues(@Valid @RequestBody IssueWriteRequestDto r
issueService.save(request, id);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/status")
public ApiResponse<String> patchStatus(@RequestBody ModifyIssueStatusRequestDto request) {
issueService.modifyIssueStatus(request);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/status")
public ApiResponse<String> patchInDetailStatus(@PathVariable Long id,
@RequestBody ModifyIssueStatusRequestDto request) {
issueService.modifyIssueStatusInDetail(id, request);
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);
}

@PatchMapping("/issues/{id}/title")
public ApiResponse<ModifyIssueTitleResponse> patchTitle(@PathVariable Long id,
@Valid @RequestBody ModifyIssueTitleRequest request) {
ModifyIssueTitleResponse response = issueService.modifyIssueTitle(id, request);
return ApiResponse.success(SUCCESS.getStatus(), response);
}

@DeleteMapping("/issues/{id}")
public ApiResponse<String> deleteIssues(@PathVariable Long id) {
issueService.delete(id);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/assignees")
public ApiResponse<String> patchAssignees(@PathVariable Long id, @RequestBody ModifyAssigneeRequestDto request) {
issueService.modifyAssignees(id, request);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/labels")
public ApiResponse<String> patchLabels(@PathVariable Long id, @RequestBody ModifyLabelRequestDto request) {
issueService.modifyLabels(id, request);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/milestones")
public ApiResponse<String> patchMilestone(@PathVariable Long id, @RequestBody ModifyIssueMilestoneDto request) {
issueService.modifyMilestone(id, request);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package codesquad.issueTracker.issue.dto;

import java.util.List;

import lombok.Getter;

@Getter
public class ModifyAssigneeRequestDto {
private List<Long> assignees;
}
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 {
private String modifiedContent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package codesquad.issueTracker.issue.dto;

import lombok.Getter;

@Getter
public class ModifyIssueMilestoneDto {
private Long milestone;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package codesquad.issueTracker.issue.dto;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ModifyIssueStatusRequestDto {
private String status;
private List<Long> issueIds;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package codesquad.issueTracker.issue.dto;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

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

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ModifyIssueTitleRequest {
@NotNull(message = "제목을 입력해주세요.")
@NotBlank(message = "공백은 입력할 수 없습니다.")
private String title;
}
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 ModifyIssueTitleResponse {
private String modifiedTitle;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package codesquad.issueTracker.issue.dto;

import java.util.List;

import lombok.Getter;

@Getter
public class ModifyLabelRequestDto {
private List<Long> labels;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package codesquad.issueTracker.issue.repository;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.Optional;

import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
Expand Down Expand Up @@ -49,4 +55,74 @@ public Long insertAssignees(Long issueId, Long userId) {
jdbcTemplate.update(sql, parameters, keyHolder);
return keyHolder.getKey().longValue();
}

public Optional<Issue> findById(Long id) {
String sql = "SELECT id, milestone_id, user_id, title, content, created_at, is_closed FROM issues WHERE id = :id AND is_deleted = 0";
return Optional.ofNullable(
DataAccessUtils.singleResult(
jdbcTemplate.query(sql, Map.of("id", id), issueRowMapper)));
}

public Long modifyStatus(Long issueId, Boolean status) {
String sql = "UPDATE issues SET is_closed = :status where id = :id AND is_deleted = 0";
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("id", issueId)
.addValue("status", status);
jdbcTemplate.update(sql, parameterSource);
return issueId;
}

private final RowMapper<Issue> issueRowMapper = (rs, rowNum) -> Issue.builder()
.id(rs.getLong("id"))
.milestoneId(rs.getLong("milestone_id"))
.userId(rs.getLong("user_id"))
.title(rs.getString("title"))
.content(rs.getString("content"))
.createdAt(rs.getObject("created_at", LocalDateTime.class))
.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;

}

public Long updateTitle(Long id, String modifiedTitle) {
String sql = "UPDATE issues SET title = :modifiedTitle WHERE Id = :id";
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("id", id)
.addValue("modifiedTitle", modifiedTitle);
jdbcTemplate.update(sql, parameterSource);
return id;
}

public Long delete(Long id) {
String sql = "UPDATE issues SET is_deleted = 1 where id = :id";
SqlParameterSource parameters = new MapSqlParameterSource()
.addValue("id", id);
jdbcTemplate.update(sql, parameters);
return id;
}

public Long resetAssignees(Long issueId) {
String sql = "DELETE FROM assignees WHERE issue_id = :issueId";
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("issueId", issueId);
jdbcTemplate.update(sql, parameterSource);
return issueId;
}

public Long updateMilestone(Long issueId, Long milestoneId) {
String sql = "UPDATE issues SET milestone_id = :milestoneId WHERE id = :issueId ";
SqlParameterSource parameterSource = new MapSqlParameterSource()
.addValue("issueId", issueId)
.addValue("milestoneId", milestoneId);
jdbcTemplate.update(sql, parameterSource);
return issueId;
}
}
Loading