-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#5] DB연동 및 docker-compose 적용 #6
base: develop
Are you sure you want to change the base?
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,4 @@ | ||
MYSQL_ROOT_PASSWORD=market | ||
MYSQL_DATABASE=RefurbMarket | ||
MYSQL_USER=refurb | ||
MYSQL_PASSWORD=market |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.refurbmarket.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class User { | ||
private Long id; | ||
private String name; | ||
private String email; | ||
private String password; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.refurbmarket.repository.implementation; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.refurbmarket.domain.User; | ||
import com.refurbmarket.repository.interfaces.UserRepository; | ||
import com.refurbmarket.repository.mapper.UserMapper; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MyBatisUserRepositoryImpl implements UserRepository { | ||
private final UserMapper userMapper; | ||
|
||
@Override | ||
public User insertUser(User user) { | ||
userMapper.insertUser(user); | ||
return user; | ||
} | ||
|
||
@Override | ||
public Optional<User> findByEmail(String email) { | ||
return userMapper.findByEmail(email); | ||
} | ||
|
||
@Override | ||
public Optional<User> findByEmailAndPassword(String email, String password) { | ||
return userMapper.findByEmailAndPassword(email, password); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.refurbmarket.repository.interfaces; | ||
|
||
import java.util.Optional; | ||
|
||
import com.refurbmarket.domain.User; | ||
|
||
public interface UserRepository { | ||
User insertUser(User user); | ||
|
||
Optional<User> findByEmail(String email); | ||
|
||
Optional<User> findByEmailAndPassword(String email, String password); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.refurbmarket.repository.mapper; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import com.refurbmarket.domain.User; | ||
|
||
@Mapper | ||
public interface UserMapper { | ||
void insertUser(@Param("user") User user); | ||
|
||
Optional<User> findByEmail(String email); | ||
|
||
Optional<User> findByEmailAndPassword(String email, String password); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||
package com.refurbmarket.service; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import org.springframework.stereotype.Service; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import com.refurbmarket.domain.User; | ||||||||||||||||||||||||||||
import com.refurbmarket.dto.user.LoginRequestDto; | ||||||||||||||||||||||||||||
import com.refurbmarket.dto.user.LoginResponseDto; | ||||||||||||||||||||||||||||
import com.refurbmarket.dto.user.SignUpRequestDto; | ||||||||||||||||||||||||||||
import com.refurbmarket.repository.interfaces.UserRepository; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Service | ||||||||||||||||||||||||||||
@RequiredArgsConstructor | ||||||||||||||||||||||||||||
public class UserService { | ||||||||||||||||||||||||||||
private final UserRepository userRepository; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public LoginResponseDto createUser(SignUpRequestDto request) { | ||||||||||||||||||||||||||||
User user = request.toDomain(); | ||||||||||||||||||||||||||||
if (userRepository.findByEmail(user.getEmail()).isPresent()) { | ||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||
throw new IllegalArgumentException("이메일 중복"); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+20
to
+22
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.
Suggested change
Suggested change
|
||||||||||||||||||||||||||||
user = userRepository.insertUser(user); | ||||||||||||||||||||||||||||
return LoginResponseDto.of(user, "asdf"); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public LoginResponseDto login(LoginRequestDto request) { | ||||||||||||||||||||||||||||
User user = request.toDomain(); | ||||||||||||||||||||||||||||
if (userRepository.findByEmailAndPassword(user.getEmail(), user.getPassword()).isEmpty()) { | ||||||||||||||||||||||||||||
throw new IllegalArgumentException("로그인 정보가 올바르지 않습니다."); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return LoginResponseDto.of(user, "asdf"); | ||||||||||||||||||||||||||||
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. Service에서 DTO를 알고 있는 것이 좋은 것인가요? |
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="com.refurbmarket.repository.mapper.UserMapper"> | ||
<select id="findByEmail" resultType="com.refurbmarket.domain.User"> | ||
SELECT id, name, email, password | ||
FROM User | ||
WHERE email = #{email} | ||
</select> | ||
<select id="findByEmailAndPassword" resultType="com.refurbmarket.domain.User"> | ||
SELECT id, name, email, password | ||
FROM User | ||
WHERE email = #{email} | ||
AND password = #{password} | ||
</select> | ||
<insert id="insertUser"> | ||
INSERT INTO User (email, password, name) | ||
VALUES (#{user.email}, #{user.password}, #{user.name}) | ||
</insert> | ||
</mapper> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
grant all privileges on RefurbMarket.* to refurb@'%'; | ||
drop table if exists member CASCADE; | ||
create table User | ||
( | ||
id bigint AUTO_INCREMENT, | ||
name VARCHAR(255), | ||
email VARCHAR(255), | ||
password VARCHAR(255), | ||
created_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6), | ||
primary key (id) | ||
) comment = "회원"; | ||
|
||
insert into User (name, email, password) values ("김테스트", "test@email.com", "testtest12!"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3.8' | ||
services: | ||
database: | ||
image: mysql:latest | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
ports: | ||
- "13306:3306" | ||
volumes: | ||
- ./api/src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/init.sql |
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.
DTO안에 비지니스 로직이 들어가는 것이 좋은 것인가요?