Repository navigation
Step1 ~step3 로그인 구현까지 pr합니다. #155
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import codesquad.dto.IssueDto; | ||
| import support.domain.AbstractEntity; | ||
|
|
||
| import javax.persistence.Entity; | ||
|
|
||
| @Entity | ||
| public class Issue extends AbstractEntity { | ||
|
|
||
| private String subject; | ||
| private String comment; | ||
|
|
||
| public Issue(){ | ||
| } | ||
|
|
||
| public Issue(String subject, String comment){ | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public Issue(long id, String subject, String comment){ | ||
| super(id); | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| 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 IssueDto _toIssueDto(){ | ||
| return new IssueDto(this.subject, this.comment); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Issue{" + | ||
| "subject='" + subject + '\'' + | ||
| ", comment='" + comment + '\'' + | ||
| '}'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface IssueRepository extends JpaRepository<Issue, Long> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package codesquad.dto; | ||
|
|
||
| import codesquad.domain.Issue; | ||
|
|
||
| public class IssueDto { | ||
| private String subject; | ||
| private String comment; | ||
|
|
||
| public IssueDto(){ | ||
| } | ||
|
|
||
| public IssueDto(String subject, String comment){ | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public IssueDto(long id, String subject, String comment){ | ||
| super(); | ||
| this.subject = subject; | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public String getSubject() { | ||
| return subject; | ||
| } | ||
|
|
||
| public String getComment() { | ||
| return comment; | ||
| } | ||
|
|
||
| public void setSubject(String subject) { | ||
| this.subject = subject; | ||
| } | ||
|
|
||
| public void setComment(String comment) { | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public Issue _toIssue(){ | ||
| return new Issue(this.subject, this.comment); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| IssueDto other = (IssueDto) obj; | ||
| if (subject == null) { | ||
| if (other.subject != null) | ||
| return false; | ||
| } else if (!subject.equals(other.subject)) | ||
| return false; | ||
| if (comment == null) { | ||
| if (other.comment != null) | ||
| return false; | ||
| } else if (!comment.equals(other.comment)) | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| final int prime = 31; | ||
| int result = 1; | ||
| result = prime * result + ((subject == null) ? 0 : subject.hashCode()); | ||
| result = prime * result + ((comment == null) ? 0 : comment.hashCode()); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "IssueDto{" + | ||
| "subject='" + subject + '\'' + | ||
| ", comment='" + comment + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
| 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.List; | ||
| 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 List<Issue> findAll(){ | ||
| return issueRepository.findAll(); | ||
| } | ||
|
|
||
| public Issue add(IssueDto issueDto){ | ||
| return issueRepository.save(issueDto._toIssue()); | ||
| } | ||
|
|
||
| public Issue findById(Long id){ | ||
| return issueRepository.findById(id).orElseThrow(UnknownError::new); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package codesquad.web; | ||
|
|
||
| import codesquad.dto.IssueDto; | ||
| import codesquad.service.IssueService; | ||
| 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 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("/form") | ||
| public String form(){ | ||
| return "/issue/form"; | ||
| } | ||
|
|
||
|
|
||
| @PostMapping("") | ||
| public String create(IssueDto issueDto){ | ||
| issueService.add(issueDto); | ||
| return "redirect:/issues/list"; | ||
| } | ||
|
|
||
| @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. "list"가 없어도 되지 않을까? |
||
| public String list(Model model){ | ||
| model.addAttribute("issues", issueService.findAll()); | ||
| return "/index"; | ||
| } | ||
|
|
||
| @GetMapping("/show/{id}") | ||
| public String showForm(@PathVariable Long id, Model model){ | ||
| model.addAttribute("issues", issueService.findById(id)); | ||
| return "/issue/show"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package codesquad.web; | ||
|
|
||
| import codesquad.UnAuthenticationException; | ||
| import codesquad.domain.User; | ||
| import codesquad.dto.UserDto; | ||
| import codesquad.security.LoginUser; | ||
|
|
@@ -11,6 +12,7 @@ | |
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.servlet.http.HttpSession; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/users") | ||
|
|
@@ -20,9 +22,27 @@ public class UserController { | |
| @Resource(name = "userService") | ||
| private UserService userService; | ||
|
|
||
| @GetMapping("/login") | ||
| public String loginForm(){ | ||
| return "/user/login"; | ||
| } | ||
|
|
||
| @PostMapping("/loginUser") | ||
| public String login(UserDto userDto, HttpSession session) throws UnAuthenticationException { | ||
|
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.
|
||
| userService.login(userDto._toUser().getUserId(), userDto._toUser().getPassword()); | ||
| session.setAttribute("loginedUser", userService.findByUserId(userDto._toUser().getUserId())); | ||
| return "/index"; | ||
| } | ||
|
|
||
| @GetMapping("/logout") | ||
| public String logout(HttpSession session){ | ||
| session.removeAttribute("loginedUser"); | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @GetMapping("/form") | ||
| public String form() { | ||
| return "/user/form"; | ||
| public String join() { | ||
| return "/user/join"; | ||
| } | ||
|
|
||
| @PostMapping("") | ||
|
|
@@ -31,17 +51,15 @@ public String create(UserDto userDto) { | |
| return "redirect:/users"; | ||
| } | ||
|
|
||
| @GetMapping("/{id}/form") | ||
| @GetMapping("/{id}/modify") | ||
| public String updateForm(@LoginUser User loginUser, @PathVariable long id, Model model) { | ||
| log.debug("LoginUser : {}", loginUser); | ||
| model.addAttribute("user", userService.findById(loginUser, id)); | ||
| model.addAttribute("user", userService.findByUserId(loginUser.getUserId())); | ||
| return "/user/updateForm"; | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| @PutMapping("/{id}/update") | ||
|
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. "update"가 없어도 되지 않을까? |
||
| public String update(@LoginUser User loginUser, @PathVariable long id, UserDto target) { | ||
| userService.update(loginUser, id, target); | ||
| return "redirect:/users"; | ||
| return "/index"; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| 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 user (id, user_id, password, name) values (3, 'a', '1', 'test'); |
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와 IssueDto 사이에 큰 차이점이 없으면 Issue만 있어도 되지 않을까?