Repository navigation
Step2 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Step2 #105
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package codesquad; | ||
|
|
||
| import codesquad.service.IssueService; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| import javax.annotation.Resource; | ||
|
|
||
| @Controller | ||
| public class HomeController { | ||
|
|
||
| @Resource(name = "issueService") | ||
| private IssueService issueService; | ||
|
|
||
| @GetMapping("/") | ||
| public String home(Model model) { | ||
| model.addAttribute("issues", issueService.findAll()); | ||
| return "index"; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import support.domain.AbstractEntity; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.validation.constraints.Size; | ||
|
|
||
| @Entity | ||
| public class Issue extends AbstractEntity { | ||
|
|
||
| @Size(min = 3, max = 50) | ||
| @Column(nullable = false, length = 50) | ||
| private String subject; | ||
|
|
||
| @Size(min = 3, max = 500) | ||
| @Column(nullable = false, length = 500) | ||
| private String comment; | ||
|
|
||
| public Issue() { | ||
| } | ||
|
|
||
| public Issue(@Size(min = 3, max = 50) String subject, @Size(min = 3, max = 500) String content) { | ||
| this.subject = subject; | ||
| this.comment = content; | ||
| } | ||
|
|
||
| public Issue(long id, @Size(min = 3, max = 50) String subject, @Size(min = 3, max = 500) String content) { | ||
| super(id); | ||
| this.subject = subject; | ||
| this.comment = content; | ||
| } | ||
|
|
||
| public String getSubject() { | ||
| return subject; | ||
| } | ||
|
|
||
| public void setSubject(String subject) { | ||
| this.subject = subject; | ||
| } | ||
|
|
||
| public String getComment() { | ||
| return comment; | ||
| } | ||
|
|
||
| public void setComment(String comment) { | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| // ApiIssueController에서 사용할 것이지만 일단은 만들어 보았다. | ||
| // public IssueDto _toIssueDto() { | ||
| // return new IssueDto(this.subject, this.comment); | ||
| // } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface IssueRepository extends JpaRepository<Issue, Long> { | ||
| @Override | ||
| Optional<Issue> findById(Long Long); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package codesquad.dto; | ||
|
|
||
| import codesquad.domain.Issue; | ||
|
|
||
| import javax.validation.constraints.Size; | ||
|
|
||
| public class IssueDto { | ||
| @Size(min = 3, max = 50) | ||
| private String subject; | ||
|
|
||
| @Size(min = 3, max = 500) | ||
| private String comment; | ||
|
|
||
| public IssueDto() { | ||
| } | ||
|
|
||
| public IssueDto(@Size(min = 3, max = 50) String subject, @Size(min = 3, max = 500) String content) { | ||
| this.subject = subject; | ||
| this.comment = content; | ||
| } | ||
|
|
||
| public String getSubject() { | ||
| return subject; | ||
| } | ||
|
|
||
| public void setSubject(String subject) { | ||
| this.subject = subject; | ||
| } | ||
|
|
||
| public String getComment() { | ||
| return comment; | ||
| } | ||
|
|
||
| public void setComment(String comment) { | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public Issue _toIssue() { | ||
| return new Issue(subject, comment); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "IssueDto{" + | ||
| "subject='" + subject + '\'' + | ||
| ", comment='" + comment + '\'' + | ||
| '}'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package codesquad.service; | ||
|
|
||
| import codesquad.domain.Issue; | ||
| import codesquad.domain.IssueRepository; | ||
| import codesquad.dto.IssueDto; | ||
| import org.slf4j.Logger; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import javax.annotation.Resource; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static org.slf4j.LoggerFactory.getLogger; | ||
|
|
||
| @Service | ||
| public class IssueService { | ||
| private static final Logger log = getLogger(IssueService.class); | ||
|
|
||
| @Resource(name = "issueRepository") | ||
| private IssueRepository issueRepository; | ||
|
|
||
| public Issue add(IssueDto issueDto) { | ||
| return issueRepository.save(issueDto._toIssue()); | ||
| } | ||
|
|
||
| public Iterable<Issue> findAll() { | ||
| return issueRepository.findAll(); | ||
| } | ||
|
|
||
| public Optional<Issue> findById(long id) { | ||
| return issueRepository.findById(id); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package codesquad.web; | ||
|
|
||
| import codesquad.UnAuthorizedException; | ||
| import codesquad.domain.IssueRepository; | ||
| import codesquad.dto.IssueDto; | ||
| import codesquad.service.IssueService; | ||
| import com.sun.org.apache.xpath.internal.operations.Mod; | ||
| import org.slf4j.Logger; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.naming.CannotProceedException; | ||
|
|
||
| import static org.slf4j.LoggerFactory.getLogger; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/issues") | ||
| public class IssueController { | ||
|
|
||
| private static final Logger log = getLogger(IssueController.class); | ||
| @Resource(name = "issueService") | ||
| private IssueService issueService; | ||
|
|
||
| @GetMapping("") | ||
| public String createIssue() { | ||
| return "issue/form"; | ||
| } | ||
|
|
||
| @PostMapping("") | ||
| public String create(IssueDto issueDto) { | ||
| log.debug("IssueDto : {}", issueDto.toString()); | ||
| issueService.add(issueDto); | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public String showDetail(@PathVariable long id, Model model) { | ||
| model.addAttribute("issue", issueService.findById(id) | ||
| .orElseThrow(UnAuthorizedException::new)); | ||
| return "issue/show"; | ||
| } | ||
|
|
||
| @GetMapping("list") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 목록의 경우 "/issues"면 되지 않을까? 굳이 list를 추가할 필요가 있을까? |
||
| public String list() { | ||
| return "issue/list"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| INSERT INTO user (id, user_id, password, name) values (1, 'javajigi', 'test', '자바지기'); | ||
| INSERT INTO user (id, user_id, password, name) values (2, 'sanjigi', 'test', '산지기'); | ||
| INSERT INTO user (id, user_id, password, name) values (2, 'sanjigi', 'test', '산지기'); | ||
|
|
||
| INSERT INTO issue (id, subject, comment) values (1, "this is first issue test", "this is soop's first comment test") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +0,0 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| {{#block "header"}} | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> | ||
| <title>Issue Tracking System</title> | ||
|
|
||
| <link href='https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en' | ||
| rel='stylesheet' type='text/css'> | ||
| <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
| <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.blue_grey-orange.min.css"> | ||
| <link rel="stylesheet" href="/css/styles.css"> | ||
| </head> | ||
| {{/block}} | ||
|
|
||
| {{#block "middle"}} | ||
| {{/block}} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성자에 굳이 @SiZe는 없어도 괜찮음.