Skip to content

Commit

Permalink
[BE/#52] Feat : 레이블 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hanurii committed Jun 24, 2020
1 parent a73c0ae commit 5162d7c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hamill")
@RequestMapping("/hamill/api/labels")
public class LabelController_Hamill {

private static final Logger logger = LoggerFactory.getLogger(LabelController_Hamill.class);
Expand All @@ -23,14 +23,24 @@ public LabelController_Hamill(LabelService_Hamill labelService_hamill) {
this.labelService_hamill = labelService_hamill;
}

@GetMapping("/api/labels")
@GetMapping("")
public ResponseEntity<ApiResponse<ContainedDescriptionLabelInformation>> showLabels() {
return new ResponseEntity<>(ApiResponse.OK(labelService_hamill.containDescriptionLabelInformation()), HttpStatus.OK);
}

@PostMapping("/api/labels")
@PostMapping("")
public ResponseEntity<ApiResponse<?>> create(@RequestBody NewLabelDto newLabelDto) {
labelService_hamill.create(newLabelDto);
return new ResponseEntity<>(ApiResponse.OK("SUCCESS"), HttpStatus.OK);
}

@PatchMapping("{labelId}")
public ResponseEntity<ApiResponse<?>> update(@PathVariable Integer labelId,@RequestBody NewLabelDto newLabelDto) throws Exception {
try {
labelService_hamill.update(labelId, newLabelDto);
} catch (Exception e) {
return new ResponseEntity<>(ApiResponse.FORBIDDEN("backgroundColor, color 를 hex code 형식으로 넣어주세요(예:#ffffff)"), HttpStatus.FORBIDDEN);
}
return new ResponseEntity<>(ApiResponse.OK("SUCCESS"), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public void create(NewLabelDto newLabelDto) {
newLabelDto.getBackgroundColor(),
newLabelDto.getColor());
}

public void update(Integer labelId, NewLabelDto newLabelDto) {
String sql = "UPDATE label SET name = ?, description = ?, background_color = ?, color = ? WHERE id = ?";
jdbcTemplate.update(sql,
newLabelDto.getTitle(), newLabelDto.getDescription(),
newLabelDto.getBackgroundColor(), newLabelDto.getColor(), labelId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ public List<LabelSummary> findLabelSummariesByIssueId(Long issueId) {
public void create(NewLabelDto newLabelDto) {
labelDao_hamill.create(newLabelDto);
}

public void update(Integer labelId, NewLabelDto newLabelDto) throws Exception {
// backgroundColor 와 color 의 형태가 hex code 형태이어야 한다
if (!(newLabelDto.getBackgroundColor().startsWith("#") && newLabelDto.getColor().startsWith("#"))) {
throw new Exception("backgroundColor, color 를 hex code 형식으로 넣어주세요(예:#ffffff)");
}
labelDao_hamill.update(labelId, newLabelDto);
}
}

0 comments on commit 5162d7c

Please sign in to comment.