Skip to content

Commit

Permalink
[BE/#58] Refactor : Label 테이블 컬럼 추가에 따른 코드 및 로직 변경
Browse files Browse the repository at this point in the history
- hexCode -> backgroundColor, color 세분화
- 이에 따라 각 레이블 관련 코드 수정 (생성자, DAO Read 로직 위주)
  • Loading branch information
MuseopKim committed Jun 19, 2020
1 parent 7e970d0 commit 4fffaa9
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 62 deletions.
21 changes: 15 additions & 6 deletions BE/src/main/java/com/codesquad/issuetracker/main/dao/LabelDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,26 @@ public LabelDao(DataSource dataSource) {
}

public List<LabelSummary> findAttachedLabelsByIssueId(Long issueId) {
String sql = "SELECT l.id, l.name, l.hex_code " +
String sql = "SELECT l.id, l.name, l.background_color, l.color " +
"FROM label l JOIN issue_has_label il ON l.id = il.label_id " +
"WHERE il.issue_id = ?";
return jdbcTemplate.query(sql, new Object[]{issueId},
(rs, rowNum) -> LabelSummary.of(rs.getInt("l.id"), rs.getString("l.name"),
rs.getString("l.hex_code")));
(rs, rowNum) -> new LabelSummary.Builder()
.id(rs.getInt("l.id"))
.name(rs.getString("l.name"))
.backgroundColor(rs.getString("l.background_color"))
.color("l.color")
.build());
}

public List<Label> findAllLabels() {
String sql = "SELECT id, name, description, hex_code FROM label";
return jdbcTemplate.query(sql, (rs, rowNum) -> Label.create(rs.getInt("id"), rs.getString("name"),
rs.getString("description"), rs.getString("hex_code")));
String sql = "SELECT id, name, description, background_color, color FROM label";
return jdbcTemplate.query(sql, (rs, rowNum) -> new Label.Builder()
.id(rs.getInt("id"))
.name(rs.getString("name"))
.description(rs.getString("description"))
.backgroundColor(rs.getString("color"))
.color(rs.getString("color"))
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ public List<LabelSummary> findAttachedLabelsByIssueId(Long issueId) {

public LabelInformation findAllLabels() {
List<Label> labels = labelDao.findAllLabels();
Set<LabelSummary> labelSummaries = labels.stream()
.map(label -> LabelSummary.of(label.getId(), label.getName(), label.getHexCode()))
.collect(Collectors.toSet());
List<LabelSummary> labelSummaries = labels.stream()
.map(label -> new LabelSummary.Builder()
.id(label.getId())
.name(label.getName())
.backgroundColor(label.getBackgroundColor())
.color(label.getColor())
.build()).collect(Collectors.toList());
return LabelInformation.create(labelSummaries.size(), labelSummaries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public ResponseEntity<ApiResponse<String>> create(@RequestBody LabelRequestDto l

@PatchMapping("/labels/{labelId}")
public ResponseEntity<ApiResponse<String>> update(@PathVariable Integer labelId, @RequestBody LabelRequestDto labelRequestDto) {
return new ResponseEntity(ApiResponse.OK(labelService.updateLabel(labelId, labelRequestDto.getLabelName(),
return new ResponseEntity(ApiResponse.OK(labelService.updateLabel(labelId,
labelRequestDto.getLabelName(),
labelRequestDto.getDescription(),
labelRequestDto.getHexCode())), HttpStatus.OK);
labelRequestDto.getBackgroundColor(),
labelRequestDto.getColor())), HttpStatus.OK);
}

@DeleteMapping("/labels/{labelId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,45 @@ public LabelDao_Ragdoll(DataSource dataSource) {
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

public void createNewLabel(String labelName, String description, String hexCode) {
String sql = "INSERT INTO label (name, description, hex_code) VALUES (?, ?, ?)";
jdbcTemplate.update(sql,new Object[]{labelName, description, hexCode});
public void createNewLabel(String labelName, String description, String backgroundColor, String color) {
String sql = "INSERT INTO label (name, description, background_color, color) VALUES (?, ?, ?, ?)";
jdbcTemplate.update(sql,new Object[]{labelName, description, backgroundColor, color});
}

public List<LabelSummary> findAttachedLabelsByIssueId(Long issueId) {
String sql = "SELECT l.id, l.name, l.hex_code " +
String sql = "SELECT l.id, l.name, l.background_color, l.color " +
"FROM label l JOIN issue_has_label il ON l.id = il.label_id " +
"WHERE il.issue_id = ?";
return jdbcTemplate.query(sql, new Object[]{issueId},
(rs, rowNum) -> LabelSummary.of(rs.getInt("l.id"), rs.getString("l.name"),
rs.getString("l.hex_code")));
(rs, rowNum) -> new LabelSummary.Builder()
.id(rs.getInt("l.id"))
.name(rs.getString("l.name"))
.backgroundColor(rs.getString("l.background_color"))
.color(rs.getString("l.color"))
.build());
}

public List<Label> findAllLabels() {
String sql = "SELECT id, name, description, hex_code FROM label";
return jdbcTemplate.query(sql, (rs, rowNum) -> Label.create(rs.getInt("id"), rs.getString("name"),
rs.getString("description"), rs.getString("hex_code")));
String sql = "SELECT id, name, description, background_color, color FROM label";
return jdbcTemplate.query(sql, (rs, rowNum) -> new Label.Builder().id(rs.getInt("id"))
.name(rs.getString("name"))
.description(rs.getString("description"))
.backgroundColor(rs.getString("background_color"))
.color(rs.getString("color"))
.build());
}

public void updateLabel(Integer labelId, String labelName, String description, String hexCode) {
public void updateLabel(Integer labelId, String labelName, String description, String backgroundColor, String color) {
SqlParameterSource namedParameters = new MapSqlParameterSource()
.addValue("labelId", labelId)
.addValue("labelName", labelName)
.addValue("description", description)
.addValue("hexCode", hexCode);
String sql = "UPDATE label SET name = :labelName, description = :description, hex_code = :hexCode WHERE id = :labelId";
.addValue("backgroundColor", backgroundColor)
.addValue("color", color);
String sql = "UPDATE label SET name = :labelName, description = :description, " +
"background_color = :backgroundColor, " +
"color = :color " +
"WHERE id = :labelId";
namedParameterJdbcTemplate.update(sql, namedParameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ public class Label {

private String description;

private String hexCode;
private String backgroundColor;

public Label() {}
private String color;

private Label(Integer id, String name, String description, String hexCode) {
private Label(Integer id, String name, String description, String backgroundColor, String color) {
this.id = id;
this.name = name;
this.description = description;
this.hexCode = hexCode;
}

public static Label create(Integer id, String name, String description, String hexCode) {
return new Label(id, name, description, hexCode);
this.backgroundColor = backgroundColor;
this.color = color;
}

public Integer getId() {
Expand All @@ -47,11 +44,56 @@ public void setDescription(String description) {
this.description = description;
}

public String getHexCode() {
return hexCode;
public String getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public void setHexCode(String hexCode) {
this.hexCode = hexCode;
public static class Builder {
private Integer id;
private String name;
private String description;
private String backgroundColor;
private String color;

public Builder id(Integer id) {
this.id = id;
return this;
}

public Builder name(String name) {
this.name = name;
return this;
}

public Builder description(String description) {
this.description = description;
return this;
}

public Builder backgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
}

public Builder color(String color) {
this.color = color;
return this;
}

public Label build() {
return new Label(id, name, description, backgroundColor, color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public class LabelRequestDto {

private String description;

private String hexCode;
private String backgroundColor;

private String color;

public String getLabelName() {
return labelName;
Expand All @@ -24,11 +26,19 @@ public void setDescription(String description) {
this.description = description;
}

public String getHexCode() {
return hexCode;
public String getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}

public String getColor() {
return color;
}

public void setHexCode(String hexCode) {
this.hexCode = hexCode;
public void setColor(String color) {
this.color = color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ public List<LabelSummary> findAttachedLabelsByIssueId(Long issueId) {

public LabelInformation findAllLabels() {
List<Label> labels = labelDaoRagdoll.findAllLabels();
Set<LabelSummary> labelSummaries = labels.stream()
.map(label -> LabelSummary.of(label.getId(), label.getName(), label.getHexCode()))
.collect(Collectors.toSet());
List<LabelSummary> labelSummaries = labels.stream()
.map(label -> new LabelSummary.Builder()
.id(label.getId())
.name(label.getName())
.backgroundColor(label.getBackgroundColor())
.color(label.getColor())
.build()).collect(Collectors.toList());
return LabelInformation.create(labelSummaries.size(), labelSummaries);
}

public String updateLabel(Integer labelId, String labelName, String description, String hexCode) {
labelDaoRagdoll.updateLabel(labelId, labelName, description, hexCode);
public String updateLabel(Integer labelId, String labelName, String description, String backgroundColor, String color) {
labelDaoRagdoll.updateLabel(labelId, labelName, description, backgroundColor, color);
return ResponseMessages.SUCCESSFULLY_MODIFIED;
}

public String createNewLabel(LabelRequestDto labelRequestDto) {
labelDaoRagdoll.createNewLabel(labelRequestDto.getLabelName(), labelRequestDto.getDescription(), labelRequestDto.getHexCode());
labelDaoRagdoll.createNewLabel(labelRequestDto.getLabelName(), labelRequestDto.getDescription(),
labelRequestDto.getBackgroundColor(), labelRequestDto.getColor());
return ResponseMessages.SUCCESSFULLY_CREATED;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.codesquad.issuetracker.ragdoll.vo.labelVO;

import java.util.List;
import java.util.Set;

public class LabelInformation {

private int countOfLabel;

private Set<LabelSummary> labels;
private List<LabelSummary> labels;

public LabelInformation() {}

private LabelInformation(int countOfLabel, Set<LabelSummary> labels) {
private LabelInformation(int countOfLabel, List<LabelSummary> labels) {
this.countOfLabel = countOfLabel;
this.labels = labels;
}

public static LabelInformation create(int countOfLabel, Set<LabelSummary> labels) {
public static LabelInformation create(int countOfLabel, List<LabelSummary> labels) {
return new LabelInformation(countOfLabel, labels);
}

Expand All @@ -27,11 +28,11 @@ public void setCountOfLabel(int countOfLabel) {
this.countOfLabel = countOfLabel;
}

public Set<LabelSummary> getLabels() {
public List<LabelSummary> getLabels() {
return labels;
}

public void setLabels(Set<LabelSummary> labels) {
public void setLabels(List<LabelSummary> labels) {
this.labels = labels;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ public class LabelSummary {

private String name;

private String hexCode;
private String backgroundColor;

private String color;

public LabelSummary() {}

private LabelSummary(Integer id, String name, String hexCode) {
private LabelSummary(Integer id, String name, String backgroundColor, String color) {
this.id = id;
this.name = name;
this.hexCode = hexCode;
}

public static LabelSummary of(Integer id, String name, String hexCode) {
return new LabelSummary(id, name, hexCode);
this.backgroundColor = backgroundColor;
this.color = color;
}

public Integer getId() {
Expand All @@ -36,11 +35,46 @@ public void setName(String name) {
this.name = name;
}

public String getHexCode() {
return hexCode;
public String getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}

public String getColor() {
return color;
}

public void setHexCode(String hexCode) {
this.hexCode = hexCode;
public static class Builder {
private Integer id;
private String name;
private String backgroundColor;
private String color;

public Builder id(Integer id) {
this.id = id;
return this;
}

public Builder name(String name) {
this.name = name;
return this;
}

public Builder backgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
}

public Builder color(String color) {
this.color = color;
return this;
}

public LabelSummary build() {
return new LabelSummary(id, name, backgroundColor, color);
}
}
}

0 comments on commit 4fffaa9

Please sign in to comment.