Skip to content
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

feature: [회원 관리] 로그인 컴포넌트 #72

Merged
merged 16 commits into from
Jul 30, 2020
Merged
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
4 changes: 2 additions & 2 deletions back/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.h2database:h2'
testImplementation 'io.rest-assured:rest-assured:3.3.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile 'com.h2database:h2'
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ArticleCreateRequest(String title, Long price, String category, String co

public Article toArticle() {
return new Article(title, price, Category.fromName(category), contents,
Tags.of(tags), new Member(authorId));
Tags.of(tags), new Member(authorId, "sellerlee@gmail.com", "0000", 4.5));
}

public String getTitle() {
Expand Down
4 changes: 2 additions & 2 deletions back/src/main/java/sellerlee/back/article/domain/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Article {
private Tags tags;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", insertable = false, updatable = false)
@JoinColumn(name = "member_id", updatable = false)
private Member author;

protected Article() {
Expand Down Expand Up @@ -72,7 +72,7 @@ public String getTitle() {
public Long getPrice() {
return price;
}

public Category getCategory() {
return category;
}
Expand Down
21 changes: 0 additions & 21 deletions back/src/main/java/sellerlee/back/config/H2ServerConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.application;

public class MemberLoginRequest {
private String email;
private String password;

private MemberLoginRequest() {
}

public MemberLoginRequest(String email, String password) {
this.email = email;
this.password = password;
}

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.application;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sellerlee.back.member.domain.IllegalMemberLoginException;
import sellerlee.back.member.domain.Member;
import sellerlee.back.member.domain.MemberRepository;

@Service
public class MemberService {
private final MemberRepository memberRepository;

public MemberService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

@Transactional(readOnly = true)
public void login(MemberLoginRequest request) {
Member findMember = memberRepository.findMemberByEmail(request.getEmail())
.orElseThrow(() -> new IllegalMemberLoginException("이메일이 일치하는 회원이 존재하지 않습니다."));

if (!findMember.verify(request.getPassword())) {
throw new IllegalMemberLoginException("비밀번호가 일치하지 않습니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.domain;

public class IllegalMemberLoginException extends IllegalArgumentException {
public IllegalMemberLoginException(String s) {
super(s);
}
}
13 changes: 10 additions & 3 deletions back/src/main/java/sellerlee/back/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @author begaonnuri
* @author kouz95
*/

package sellerlee.back.member.domain;
Expand All @@ -8,6 +8,7 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;

@Entity
public class Member {
Expand All @@ -16,8 +17,10 @@ public class Member {
@Column(name = "member_id")
private Long id;

@NotNull
private String email;

@NotNull
private String password;

private Double score;
Expand All @@ -32,8 +35,12 @@ public Member(Long id, String email, String password, Double score) {
this.score = score;
}

public Member(Long id) {
this(id, null, null, null);
public Member(String email, String password, Double score) {
this(null, email, password, score);
}

public boolean verify(String password) {
return this.password.equals(password);
}

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.domain;

import java.util.Optional;

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

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findMemberByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sellerlee.back.member.presentation;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import sellerlee.back.member.domain.IllegalMemberLoginException;

@ControllerAdvice
public class LoginAdviceController {
@ExceptionHandler(IllegalMemberLoginException.class)
public ResponseEntity<String> handleIllegalMemberLoginException(IllegalMemberLoginException e) {
return ResponseEntity
.badRequest()
.body(e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.presentation;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import sellerlee.back.member.application.MemberLoginRequest;
import sellerlee.back.member.application.MemberService;

@RestController
public class MemberController {
private final MemberService memberService;

public MemberController(MemberService memberService) {
this.memberService = memberService;
}

@PostMapping("/login")
public ResponseEntity<Void> login(@RequestBody MemberLoginRequest request) {
memberService.login(request);

return ResponseEntity
.ok()
.build();
}
}
21 changes: 15 additions & 6 deletions back/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ spring:
profiles:
active: local

logging:
level:
org.hibernate.type.descriptor.sql: trace
org.springframework.web: debug

---

spring:
profiles: local

jpa:
database-platform: org.hibernate.dialect.H2Dialect
database: H2
Expand All @@ -10,16 +20,15 @@ spring:
hibernate:
ddl-auto: create
properties:
hibernate.format-sql: true
hibernate.format_sql: true
use_sql_comments: true

h2:
console:
enabled: true

datasource:
url: jdbc:h2:mem:testdb;IFEXISTS=FALSE;
url: jdbc:h2:tcp://localhost/${user.dir}/test;IFEXISTS=FALSE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

username: sa
password:
driver-class-name: org.h2.Driver

logging:
level:
org.hibernate.type.descriptor.sql: trace
37 changes: 20 additions & 17 deletions back/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/**
* @author begaonnuri
* @author kouz95
*/

insert into member (member_id, email, password, score)
values (1, 'turtle@woowabro.com', '1234', 36);
values (1, 'turtle@woowabro.com', '1234', 36),
(2, 'lxxjn0@gmail.com', '0000', 5.0),
(3, 'sellerlee@gmail.com', '1234', 4.5);

insert into article (article_id, category, contents, price, title, member_id) values (2, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (3, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (4, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (5, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (6, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (7, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (8, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (9, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (10, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (11, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id) values (12, 'PC', 'test contents1', 1234, 'test title1', 1);
insert into article (article_id, category, contents, price, title, member_id)
values (2, 'PC', 'test contents1', 1234, 'test title1', 1),
(3, 'PC', 'test contents1', 1234, 'test title1', 1),
(4, 'PC', 'test contents1', 1234, 'test title1', 1),
(5, 'PC', 'test contents1', 1234, 'test title1', 1),
(6, 'PC', 'test contents1', 1234, 'test title1', 1),
(7, 'PC', 'test contents1', 1234, 'test title1', 1),
(8, 'PC', 'test contents1', 1234, 'test title1', 1),
(9, 'PC', 'test contents1', 1234, 'test title1', 1),
(10, 'PC', 'test contents1', 1234, 'test title1', 1),
(11, 'PC', 'test contents1', 1234, 'test title1', 1),
(12, 'PC', 'test contents1', 1234, 'test title1', 1);

insert into tag (article_id, name)
values (1, 'test tag1'),
(1, 'test tag2'),
(2, 'test tag3'),
(2, 'test tag4');
values (2, 'test tag1'),
(2, 'test tag2'),
(3, 'test tag3'),
(3, 'test tag4');
Loading