Skip to content
Merged

Step4 #137

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/codesquad/ImsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@SpringBootApplication
@EnableJpaAuditing
public class ImsApplication {

public static void main(String[] args) {
SpringApplication.run(ImsApplication.class, args);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/codesquad/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.format.FormatterRegistry;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import support.converter.LocalDateConverter;
Expand All @@ -23,7 +24,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateConverter("yyyy-MM-dd"));
registry.addConverter(new LocalDateTimeConverter("yyyy-MM-dd HH:mm:ss.SSS"));
registry.addConverter(new LocalDateTimeConverter("yyyy-MM-dd'T'HH:mm:ss.SSS"));
registry.addConverter(new LocalDateTimeConverter("yyyy-MM-dd'T'HH:mm"));
}

@Bean
Expand Down
59 changes: 51 additions & 8 deletions src/main/java/codesquad/domain/Issue.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package codesquad.domain;

import codesquad.UnAuthorizedException;
import codesquad.dto.IssueDto;
import org.slf4j.Logger;
import sun.jvm.hotspot.debugger.cdbg.basic.LazyBlockSym;
import support.domain.AbstractEntity;

import javax.persistence.*;
import javax.validation.constraints.Size;

import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -22,6 +23,18 @@ public class Issue extends AbstractEntity {
@JoinColumn(foreignKey = @ForeignKey(name = "fk_issue_writer"))
private User writer;

@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "fk_issue_milestone"))
private Milestone milestone;

@OneToOne
@JoinColumn(foreignKey = @ForeignKey(name = "fk_issue_assignee"))
private User assignee;

@ManyToMany
@JoinColumn(foreignKey = @ForeignKey(name = "fk_issue_labels"))
private List<Label> lables;

private boolean deleted = false;

public Issue() {
Expand Down Expand Up @@ -65,12 +78,32 @@ public void writeBy(User loginUser) {
this.writer = loginUser;
}

public boolean isOwner(User loginUser) {
return writer.equals(loginUser);
public Milestone getMilestone() {
return milestone;
}

public void setMilestone(Milestone milestone) {
this.milestone = milestone;
}

public User getAssignee() {
return assignee;
}

public void setAssignee(User assignee) {
this.assignee = assignee;
}

public IssueDto _toIssueDto() {
return new IssueDto(this.issueBody);
public List<Label> getLables() {
return lables;
}

public void setLables(List<Label> lables) {
this.lables = lables;
}

public boolean isOwner(User loginUser) {
return writer.equals(loginUser);
}

public void update(User loginUser, IssueBody target) {
Expand All @@ -81,11 +114,21 @@ public void update(User loginUser, IssueBody target) {
}

public void delete(User loginUser) {
log.debug("loginUser : {}", loginUser);
log.debug("writer : {}", writer);
if (!isOwner(loginUser)) {
throw new UnAuthorizedException();
}
this.deleted = true;
}

public void addMilestone(Milestone milestone) {
this.milestone = milestone;
}

public void addAssignee(User assignee) {
this.assignee = assignee;
}

public void addLable(Label lable) {
this.lables.add(lable);
}
}
30 changes: 30 additions & 0 deletions src/main/java/codesquad/domain/Label.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package codesquad.domain;


import support.domain.AbstractEntity;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Label extends AbstractEntity {

@Column(nullable = false)
private String label;


public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

@Override
public String toString() {
return "Label{" +
"label='" + label + '\'' +
'}';
}
}
6 changes: 6 additions & 0 deletions src/main/java/codesquad/domain/LabelRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package codesquad.domain;

import org.springframework.data.jpa.repository.JpaRepository;

public interface LabelRepository extends JpaRepository<Label, Long> {
}
84 changes: 84 additions & 0 deletions src/main/java/codesquad/domain/Milestone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package codesquad.domain;

import support.domain.AbstractEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

@Entity
public class Milestone extends AbstractEntity {

private String subject;

private LocalDateTime startDate;

private LocalDateTime endDate;

public Milestone() {

}

public Milestone(String subject, LocalDateTime startDate, LocalDateTime endDate) {
this.subject = subject;
this.startDate = startDate;
this.endDate = endDate;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public LocalDateTime getStartDate() {
return startDate;
}

public void setStartDate(LocalDateTime startDate) {
this.startDate = startDate;
}

public LocalDateTime getEndDate() {
return endDate;
}

public void setEndDate(LocalDateTime endDate) {
this.endDate = endDate;
}

public String getDueBy() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yyyy");
LocalDateTime dateTime = endDate;
return dateTime.format(formatter);
}

@Override
public String toString() {
return "Milestone{" +
"subject='" + subject + '\'' +
", startDate=" + startDate +
", endDate=" + endDate +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Milestone milestone = (Milestone) o;
return Objects.equals(subject, milestone.subject) &&
Objects.equals(startDate, milestone.startDate) &&
Objects.equals(endDate, milestone.endDate);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), subject, startDate, endDate);
}
}
6 changes: 6 additions & 0 deletions src/main/java/codesquad/domain/MilestoneRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package codesquad.domain;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MilestoneRepository extends JpaRepository<Milestone, Long> {
}
53 changes: 0 additions & 53 deletions src/main/java/codesquad/dto/IssueDto.java

This file was deleted.

12 changes: 10 additions & 2 deletions src/main/java/codesquad/security/RestSecurityControllerAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import support.domain.ErrorMessage;
import support.domain.Result;

import javax.persistence.EntityNotFoundException;

Expand All @@ -32,8 +33,15 @@ public void unAuthorized() {

@ExceptionHandler(UnAuthenticationException.class)
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
public ErrorMessage unAuthentication(UnAuthenticationException e) {
public Result unAuthentication(UnAuthenticationException e) {
log.debug("JSON API UnAuthenticationException is happend!");
return new ErrorMessage(e.getMessage());
return Result.fail(e.getMessage());
}

// @ExceptionHandler(UnAuthenticationException.class)
// @ResponseStatus(value = HttpStatus.UNAUTHORIZED)
// public ErrorMessage unAuthentication(UnAuthenticationException e) {
// log.debug("JSON API UnAuthenticationException is happend!");
// return new ErrorMessage(e.getMessage());
// }
}
Loading