Repository navigation
Step2 PR #101
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 PR #101
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
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,82 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import codesquad.dto.IssueDto; | ||
| import support.domain.AbstractEntity; | ||
|
|
||
| import javax.persistence.*; | ||
| import javax.validation.constraints.Size; | ||
|
|
||
| @Entity | ||
| public class Issue extends AbstractEntity { | ||
| @Size(min = 3, max = 100) | ||
| @Column(nullable = false, length = 100) | ||
| private String subject; | ||
|
|
||
| @Size(min = 3) | ||
| @Lob | ||
| private String comment; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(foreignKey = @ForeignKey(name = "fk_issue_writer")) | ||
| private User writer; | ||
|
|
||
| public Issue() { | ||
|
|
||
| } | ||
|
|
||
| public Issue(String subject, String comment) { | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public Issue(String subject, String comment, User writer) { | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| this.writer = writer; | ||
| } | ||
|
|
||
| public Issue(long id, String subject, String comment, User writer) { | ||
| super(id); | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| this.writer = writer; | ||
| } | ||
|
|
||
| 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 User getWriter() { | ||
| return writer; | ||
| } | ||
|
|
||
| public void writeBy(User loginUser) { | ||
| this.writer = loginUser; | ||
| } | ||
|
|
||
| public IssueDto _toIssueDto() { | ||
| return new IssueDto(this.subject, this.comment, this.writer); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Issue{" + | ||
| "id='" + getId() + '\'' + | ||
| "subject='" + subject + '\'' + | ||
| ", comment='" + comment + '\'' + | ||
| ", writer=" + writer + | ||
| '}'; | ||
| } | ||
| } | ||
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,9 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface IssueRepository extends JpaRepository<Issue, Long> { | ||
| Optional<Issue> findBySubject(String title); | ||
| } |
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,64 @@ | ||
| package codesquad.dto; | ||
|
|
||
| import codesquad.domain.Issue; | ||
| import codesquad.domain.User; | ||
|
|
||
| import javax.validation.constraints.Size; | ||
|
|
||
| public class IssueDto { | ||
| @Size(min = 3, max = 100) | ||
| private String subject; | ||
|
|
||
| @Size(min = 3) | ||
| private String comment; | ||
|
|
||
| private User writer; | ||
|
|
||
| public IssueDto() { | ||
|
|
||
| } | ||
|
|
||
| public IssueDto(String subject, String comment, User writer) { | ||
| super(); | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| this.writer = writer; | ||
| } | ||
|
|
||
| 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 User getWriter() { | ||
| return writer; | ||
| } | ||
|
|
||
| public void writeBy(User loginUser) { | ||
| this.writer = loginUser; | ||
| } | ||
|
|
||
| public Issue _toIssue() { | ||
| return new Issue(this.subject, this.comment, this.writer); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "IssueDto{" + | ||
| "subject='" + subject + '\'' + | ||
| ", comment='" + comment + '\'' + | ||
| ", writer=" + writer + | ||
| '}'; | ||
| } | ||
| } |
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,43 @@ | ||
| package codesquad.service; | ||
|
|
||
| import codesquad.domain.Issue; | ||
| import codesquad.domain.IssueRepository; | ||
| import codesquad.domain.User; | ||
| import codesquad.dto.IssueDto; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.persistence.EntityNotFoundException; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class IssueService { | ||
|
|
||
| @Resource(name = "issueRepository") | ||
| private IssueRepository issueRepository; | ||
|
|
||
| public Issue add(IssueDto issueDto) { | ||
| return issueRepository.save(issueDto._toIssue()); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Issue create(User loginUser, IssueDto issueDto) { | ||
| issueDto.writeBy(loginUser); | ||
| add(issueDto); | ||
| return issueDto._toIssue(); | ||
| } | ||
|
|
||
| // public Iterable<Issue> findAll() { | ||
| // return issueRepository.findByDeleted(false); | ||
| // } | ||
|
|
||
| public List<Issue> findAll(Pageable pageable) { | ||
| return issueRepository.findAll(pageable).getContent(); | ||
| } | ||
|
|
||
| public Issue findById(long id) { | ||
| return issueRepository.findById(id).orElseThrow(EntityNotFoundException::new); | ||
| } | ||
| } |
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,25 @@ | ||
| package codesquad.web; | ||
|
|
||
| import codesquad.domain.Issue; | ||
| import codesquad.service.IssueService; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import java.util.List; | ||
|
|
||
| @Controller | ||
| public class HomeController { | ||
|
|
||
| @Resource(name = "issueService") | ||
| private IssueService issueService; | ||
|
|
||
| @GetMapping("/") | ||
| public String home(Model model, Pageable pageable) { | ||
| List<Issue> issues = issueService.findAll(pageable); | ||
| model.addAttribute("issues", issues); | ||
| 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,50 @@ | ||
| package codesquad.web; | ||
|
|
||
| import codesquad.domain.Issue; | ||
| import codesquad.domain.User; | ||
| import codesquad.dto.IssueDto; | ||
| import codesquad.security.LoginUser; | ||
| import codesquad.service.IssueService; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| 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; | ||
|
|
||
|
|
||
| @Controller | ||
| @RequestMapping("/newIssue") | ||
|
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"로 구현할 것을 추천 |
||
| public class IssueController { | ||
| private static final Logger log = LoggerFactory.getLogger(IssueController.class); | ||
|
|
||
| @Resource(name = "issueService") | ||
| private IssueService issueService; | ||
|
|
||
| @GetMapping("/form") | ||
| public String form() { | ||
| return "/issue/form"; | ||
| } | ||
|
|
||
| @PostMapping("") | ||
| public String create(@LoginUser User loginUser, IssueDto issueDto) { | ||
| issueService.create(loginUser, issueDto); | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @GetMapping("") | ||
| public String list() { | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public String read(@PathVariable long id, Model model) { | ||
| Issue issue = issueService.findById(id); | ||
| model.addAttribute("issue", issue); | ||
| return "/issue/show"; | ||
| } | ||
| } | ||
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
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,16 @@ | ||
| 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, create_date, modified_date) values (1, 'javajigi', 'test', '자바지기', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (2, 'sanjigi', 'test', '산지기', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (3, 'third', 'test', '셋째', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (4, 'fourth', 'test', '넷째', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (5, 'fifth', 'test', '다섯째', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (6, 'sixth', 'test', '여섯째', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO user (id, user_id, password, name, create_date, modified_date) values (7, 'seventh', 'test', '일곱째', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
|
|
||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (1, 1, '자바지기 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (2, 2, '산지기 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (3, 3, '셋째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (4, 4, '넷째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (5, 5, '다섯째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (6, 6, '여섯째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (7, 7, '일곱째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); | ||
| INSERT INTO issue (id, writer_id, subject, comment, create_date, modified_date) values (8, 1, '자바지기 두 번째 이슈', '내용', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()); |
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
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.
Issue 생성자가 너무 많음.
꼭 필요한 생성자가 가지도록 구현