Skip to content

Commit

Permalink
[BE/#51] Feat : 레이블 등록 API 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
hanurii committed Jun 22, 2020
1 parent fb0bddf commit eca9598
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codesquad.issuetracker.hamill.controller;

import com.codesquad.issuetracker.hamill.dto.request.NewLabelDto;
import com.codesquad.issuetracker.hamill.dto.response.ApiResponse;
import com.codesquad.issuetracker.hamill.service.LabelService_Hamill;
import com.codesquad.issuetracker.hamill.vo.labelVO.ContainedDescriptionLabelInformation;
Expand All @@ -8,9 +9,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hamill")
Expand All @@ -28,4 +27,10 @@ public LabelController_Hamill(LabelService_Hamill labelService_hamill) {
public ResponseEntity<ApiResponse<ContainedDescriptionLabelInformation>> showLabels() {
return new ResponseEntity<>(ApiResponse.OK(labelService_hamill.containDescriptionLabelInformation()), HttpStatus.OK);
}

@PostMapping("/api/labels")
public ResponseEntity<ApiResponse<?>> create(@RequestBody NewLabelDto newLabelDto) {
labelService_hamill.create(newLabelDto);
return new ResponseEntity<>(ApiResponse.OK("SUCCESS"), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codesquad.issuetracker.hamill.dao;

import com.codesquad.issuetracker.hamill.domain.Label;
import com.codesquad.issuetracker.hamill.dto.request.NewLabelDto;
import com.codesquad.issuetracker.hamill.vo.labelVO.LabelSummary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -44,4 +45,13 @@ public List<LabelSummary> findLabelSummariesByIssueId(Long issueId) {
rs.getString("color"))
, issueId);
}

public void create(NewLabelDto newLabelDto) {
String sql = "INSERT INTO label(name, description, background_color, color) VALUES(?, ?, ?, ?)";
jdbcTemplate.update(sql,
newLabelDto.getTitle(),
newLabelDto.getDescription(),
newLabelDto.getBackgroundColor(),
newLabelDto.getColor());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.codesquad.issuetracker.hamill.dto.request;

public class NewLabelDto {

private String title;

private String description;

private String backgroundColor;

private String color;

private NewLabelDto(String title, String description, String backgroundColor, String color) {
this.title = title;
this.description = description;
this.backgroundColor = backgroundColor;
this.color = color;
}

public static NewLabelDto of(String title, String description, String backgroundColor, String color) {
return new Builder()
.title(title)
.description(description)
.backgroundColor(backgroundColor)
.color(color)
.build();
}

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public String getBackgroundColor() {
return backgroundColor;
}

public String getColor() {
return color;
}

private static class Builder {
private String title;
private String description;
private String backgroundColor;
private String color;

private Builder title(String title) {
this.title = title;
return this;
}

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

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

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

private NewLabelDto build() {
return new NewLabelDto(title, description, backgroundColor, color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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.vo.labelVO.ContainedDescriptionLabelInformation;
import com.codesquad.issuetracker.hamill.vo.labelVO.ContainedDescriptionLabelSummary;
import com.codesquad.issuetracker.hamill.vo.labelVO.LabelInformation;
Expand Down Expand Up @@ -53,4 +54,8 @@ public ContainedDescriptionLabelInformation containDescriptionLabelInformation()
public List<LabelSummary> findLabelSummariesByIssueId(Long issueId) {
return labelDao_hamill.findLabelSummariesByIssueId(issueId);
}

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

0 comments on commit eca9598

Please sign in to comment.