Skip to content

Commit

Permalink
[BE/#33] Feat : 이슈 Labels 추가 / 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hanurii committed Jun 24, 2020
1 parent 3592e24 commit 6d1fd73
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.codesquad.issuetracker.hamill.controller;

import com.codesquad.issuetracker.hamill.dto.request.NewIssueDto;
import com.codesquad.issuetracker.hamill.dto.request.UpdateAttachedLabelsDto;
import com.codesquad.issuetracker.hamill.dto.request.UpdateStateOfIssueDto;
import com.codesquad.issuetracker.hamill.dto.request.UpdateTitleDto;
import com.codesquad.issuetracker.hamill.dto.response.ApiResponse;
import com.codesquad.issuetracker.hamill.dto.response.IssueDto;
import com.codesquad.issuetracker.hamill.dto.response.ListOfIssuesDto;
import com.codesquad.issuetracker.hamill.service.IssueService_Hamill;
import com.codesquad.issuetracker.hamill.service.UserService_Hamill;
import com.codesquad.issuetracker.hamill.service.LabelService_Hamill;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
Expand All @@ -23,9 +24,11 @@ public class IssueController_Hamill {
private static final Logger logger = LoggerFactory.getLogger(IssueController_Hamill.class);

private IssueService_Hamill issueService_Hamill;
private LabelService_Hamill labelService_hamill;

public IssueController_Hamill(IssueService_Hamill issueService_Hamill) {
public IssueController_Hamill(IssueService_Hamill issueService_Hamill, LabelService_Hamill labelService_hamill) {
this.issueService_Hamill = issueService_Hamill;
this.labelService_hamill = labelService_hamill;
}

@GetMapping("")
Expand Down Expand Up @@ -61,4 +64,11 @@ public ResponseEntity<ApiResponse<?>> updateStatusOfIssue(@RequestBody UpdateSta

return new ResponseEntity<>(ApiResponse.OK("SUCCESS"), HttpStatus.OK);
}
}

@PutMapping("/{issueId}/labels")
public ResponseEntity<ApiResponse<?>> updateAttachedLabels(@PathVariable Long issueId, @RequestBody UpdateAttachedLabelsDto updateAttachedLabelsDto) {
labelService_hamill.updateAttachedLabels(issueId, updateAttachedLabelsDto);

return new ResponseEntity<>(ApiResponse.OK("SUCCESS"), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import com.codesquad.issuetracker.hamill.dto.response.ApiResponse;
import com.codesquad.issuetracker.hamill.service.LabelService_Hamill;
import com.codesquad.issuetracker.hamill.vo.labelVO.ContainedDescriptionLabelInformation;
import com.codesquad.issuetracker.hamill.vo.labelVO.LabelInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/hamill/api/labels")
public class LabelController_Hamill {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codesquad.issuetracker.hamill.dao;

import com.codesquad.issuetracker.hamill.dto.request.UpdateAttachedLabelsDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
Expand All @@ -20,4 +21,14 @@ public void deleteIssueHasLabelByLabelId(Integer labelId) {
String sql = "DELETE FROM issue_has_label WHERE label_id = ?";
jdbcTemplate.update(sql, labelId);
}

public void addedAttachedLabel(Long issueId, Integer labelId) {
String sql = "INSERT INTO issue_has_label(label_id, issue_id) VALUES (?, ?) ";
jdbcTemplate.update(sql,labelId, issueId);
}

public void deletedAttachedLabel(Long issueId, Integer labelId) {
String sql = "DELETE FROM issue_has_label WHERE issue_id = ? AND label_id = ?";
jdbcTemplate.update(sql, issueId, labelId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<LabelSummary> findLabelSummariesByIssueId(Long issueId) {
rs.getString("name"),
rs.getString("background_color"),
rs.getString("color"))
, issueId);
, issueId);
}

public void create(NewLabelDto newLabelDto) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.codesquad.issuetracker.hamill.dto.request;

import java.util.List;

public class UpdateAttachedLabelsDto {

private Long userId;

private List<Integer> addedLabelsId;

private List<Integer> deletedLabelsId;

private UpdateAttachedLabelsDto(Long userId, List<Integer> addedLabelsId, List<Integer> deletedLabelsId) {
this.userId = userId;
this.addedLabelsId = addedLabelsId;
this.deletedLabelsId = deletedLabelsId;
}

public static UpdateAttachedLabelsDto of(Long userId, List<Integer> addedLabelsId, List<Integer> deletedLabelsId) {
return new UpdateAttachedLabelsDto(userId, addedLabelsId, deletedLabelsId);
}

public Long getUserId() {
return userId;
}

public List<Integer> getAddedLabelsId() {
return addedLabelsId;
}

public List<Integer> getDeletedLabelsId() {
return deletedLabelsId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.codesquad.issuetracker.hamill.dao.LabelDao_Hamill;
import com.codesquad.issuetracker.hamill.domain.Label;
import com.codesquad.issuetracker.hamill.dto.request.NewLabelDto;
import com.codesquad.issuetracker.hamill.dto.request.UpdateAttachedLabelsDto;
import com.codesquad.issuetracker.hamill.vo.labelVO.ContainedDescriptionLabelInformation;
import com.codesquad.issuetracker.hamill.vo.labelVO.ContainedDescriptionLabelSummary;
import com.codesquad.issuetracker.hamill.vo.labelVO.LabelInformation;
Expand Down Expand Up @@ -56,6 +57,16 @@ public List<LabelSummary> findLabelSummariesByIssueId(Long issueId) {
return labelDao_hamill.findLabelSummariesByIssueId(issueId);
}

public void updateAttachedLabels(Long issueId, UpdateAttachedLabelsDto updateAttachedLabelsDto) {
for (int i = 0; i < updateAttachedLabelsDto.getAddedLabelsId().size(); i++) {
issueHasLabelDao_hamill.addedAttachedLabel(issueId, updateAttachedLabelsDto.getAddedLabelsId().get(i));
}

for (int i = 0; i< updateAttachedLabelsDto.getDeletedLabelsId().size(); i++) {
issueHasLabelDao_hamill.deletedAttachedLabel(issueId, updateAttachedLabelsDto.getDeletedLabelsId().get(i));
}
}

public void create(NewLabelDto newLabelDto) {
labelDao_hamill.create(newLabelDto);
}
Expand Down

0 comments on commit 6d1fd73

Please sign in to comment.