Refactor Sql Schema, Confirm Email Process
This commit is contained in:
@@ -4,7 +4,7 @@ import java.util.Optional;
|
||||
|
||||
public interface MemberReader {
|
||||
|
||||
Optional<Member> findByNickname(String nickname);
|
||||
boolean existsByNickname(String nickname);
|
||||
|
||||
Optional<Member> findById(Long memberId);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.yam.app.member.domain;
|
||||
|
||||
public interface MemberRepository {
|
||||
|
||||
void save(Member entity);
|
||||
Long save(Member entity);
|
||||
|
||||
void update(Member entity);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.yam.app.member.domain.MemberReader;
|
||||
import com.yam.app.member.domain.MemberRepository;
|
||||
import com.yam.app.member.domain.RegisterAccountConfirmEvent;
|
||||
import com.yam.app.member.domain.UpdateAccountEvent;
|
||||
import java.util.UUID;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -28,10 +29,14 @@ public class MemberEventListener {
|
||||
@EventListener
|
||||
public void handle(RegisterAccountConfirmEvent event) {
|
||||
var nickname = event.getEmail().split("@")[0];
|
||||
memberRepository.save(new Member(nickname, "temp.png"));
|
||||
var member = memberReader.findByNickname(nickname)
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
publisher.publishEvent(new GenerateMemberEvent(member.getId(), event.getEmail()));
|
||||
Long savedEntityId;
|
||||
if (memberReader.existsByNickname(nickname)) {
|
||||
savedEntityId = memberRepository.save(
|
||||
new Member(UUID.randomUUID().toString(), "temp.png"));
|
||||
} else {
|
||||
savedEntityId = memberRepository.save(new Member(nickname, "temp.png"));
|
||||
}
|
||||
publisher.publishEvent(new GenerateMemberEvent(savedEntityId, event.getEmail()));
|
||||
}
|
||||
|
||||
@EventListener
|
||||
|
||||
@@ -18,8 +18,8 @@ public final class MybatisMemberRepository implements MemberRepository, MemberRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Member> findByNickname(String nickname) {
|
||||
return template.getMapper(MemberReader.class).findByNickname(nickname);
|
||||
public boolean existsByNickname(String nickname) {
|
||||
return template.getMapper(MemberReader.class).existsByNickname(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,12 +28,13 @@ public final class MybatisMemberRepository implements MemberRepository, MemberRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Member entity) {
|
||||
public Long save(Member entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">
|
||||
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
|
||||
</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
|
||||
<!-- Rolling File Appender -->
|
||||
<RollingFile name="FileAppender" fileName="logs/app.log"
|
||||
filePattern="logs/app-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout>
|
||||
<Pattern>${LOG_PATTERN}</Pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" />
|
||||
<SizeBasedTriggeringPolicy size="10MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="10"/>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<AsyncLogger name="com.yam.app" level="debug"
|
||||
additivity="false">
|
||||
<AppenderRef ref="ConsoleAppender" />
|
||||
<AppenderRef ref="FileAppender" />
|
||||
</AsyncLogger>
|
||||
|
||||
<Root level="info">
|
||||
<AppenderRef ref="ConsoleAppender" />
|
||||
<AppenderRef ref="FileAppender" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -7,6 +7,9 @@
|
||||
INSERT
|
||||
INTO member (nickname, image, status)
|
||||
VALUES (#{nickname}, #{image}, #{status})
|
||||
<selectKey keyProperty="id" resultType="long" order="AFTER">
|
||||
SELECT LAST_INSERT_ID()
|
||||
</selectKey>
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.yam.app.member.domain.Member">
|
||||
|
||||
@@ -13,4 +13,8 @@
|
||||
SELECT * FROM member WHERE id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="existsByNickname" parameterType="String" resultType="boolean">
|
||||
SELECT COUNT(id) FROM member WHERE nickname = #{nickname}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -3,7 +3,7 @@ create table member
|
||||
id bigint not null auto_increment,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
status varchar(255) not null,
|
||||
status varchar(8) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
@@ -12,18 +12,17 @@ create table account
|
||||
id bigint not null auto_increment,
|
||||
email varchar(255) not null,
|
||||
email_check_token varchar(255),
|
||||
email_check_token_generated_at timestamp,
|
||||
email_check_token_generated_at datetime(6),
|
||||
email_verified boolean not null,
|
||||
joined_at timestamp,
|
||||
last_modified_at timestamp,
|
||||
role varchar(255) not null,
|
||||
joined_at datetime(6),
|
||||
last_modified_at datetime(6),
|
||||
role varchar(10) not null,
|
||||
password varchar(255) not null,
|
||||
withdraw boolean not null,
|
||||
withdrawal_at timestamp,
|
||||
withdrawal_at datetime(6),
|
||||
member_id bigint,
|
||||
status varchar(255) not null,
|
||||
primary key (id),
|
||||
foreign key (member_id) references member (id)
|
||||
status varchar(8) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table tag
|
||||
@@ -37,14 +36,13 @@ create table article
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
created_at datetime(6),
|
||||
image varchar(255) not null,
|
||||
modified_at timestamp,
|
||||
status varchar(255) not null,
|
||||
modified_at datetime(6),
|
||||
status varchar(8) not null,
|
||||
title varchar(255) not null,
|
||||
member_id bigint,
|
||||
primary key (id),
|
||||
foreign key (member_id) references member (id)
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_likes
|
||||
@@ -52,9 +50,7 @@ create table article_likes
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id),
|
||||
foreign key (member_id) references member (id),
|
||||
foreign key (article_id) references article (id)
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_tag
|
||||
@@ -62,23 +58,19 @@ create table article_tag
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint not null,
|
||||
tag_id bigint not null,
|
||||
primary key (id),
|
||||
foreign key (article_id) references article (id),
|
||||
foreign key (tag_id) references tag (id)
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
modified_at timestamp,
|
||||
status varchar(255),
|
||||
created_at datetime(6),
|
||||
modified_at datetime(6),
|
||||
status varchar(8),
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id),
|
||||
foreign key (member_id) references member (id),
|
||||
foreign key (article_id) references article (id)
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment_likes
|
||||
@@ -86,14 +78,13 @@ create table comment_likes
|
||||
id bigint not null auto_increment,
|
||||
comment_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id),
|
||||
foreign key (member_id) references member (id),
|
||||
foreign key (comment_id) references comment (id)
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create index title_idx on article (title);
|
||||
alter table account
|
||||
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
alter table tag
|
||||
add constraint UK_1wdpsed5kna2y38hnbgrnhi5b unique (name);
|
||||
alter table article
|
||||
add constraint UK_571gx7oqo5xpmgocegaidlcu9 unique (title);
|
||||
alter table member
|
||||
add constraint UK_gc3jmn7c2abyo3wf6syln5t2i unique (nickname);
|
||||
|
||||
@@ -66,6 +66,25 @@ final class AccountIntegrationTests extends AbstractIntegrationTests {
|
||||
.andExpect(redirectedUrl(EMAIL_CONFIRM_SUCCESS_REDIRECT_URI));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("이메일 검증 후 회워 정보 기입에서, 닉네임이 동일한 경우"
|
||||
+ "랜덤한 값을 이어붙여서 저장하도록하는 시나리오 테스트")
|
||||
void duplicate_email_and_token_verify_request_in_correctly() throws Exception {
|
||||
// Act
|
||||
final var actions = mockMvc.perform(get(EMAIL_CONFIRM)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.param("token", "emailchecktoken")
|
||||
.param("email", "jiwonDev@naver.com")
|
||||
);
|
||||
|
||||
// Assert
|
||||
actions
|
||||
.andDo(print())
|
||||
.andExpect(status().isSeeOther())
|
||||
.andExpect(redirectedUrl(EMAIL_CONFIRM_SUCCESS_REDIRECT_URI));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여, 성공하고 "
|
||||
+ "이후 자신의 정보를 조회하는 시나리오 테스트.")
|
||||
|
||||
@@ -1,82 +1,90 @@
|
||||
create table account (
|
||||
id bigint generated by default as identity,
|
||||
create table member
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
status varchar(8) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table account
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
email varchar(255) not null,
|
||||
email_check_token varchar(255),
|
||||
email_check_token_generated_at timestamp,
|
||||
email_check_token_generated_at datetime(6),
|
||||
email_verified boolean not null,
|
||||
joined_at timestamp,
|
||||
last_modified_at timestamp,
|
||||
role varchar(255) not null,
|
||||
joined_at datetime(6),
|
||||
last_modified_at datetime(6),
|
||||
role varchar(10) not null,
|
||||
password varchar(255) not null,
|
||||
withdraw boolean not null,
|
||||
withdrawal_at timestamp,
|
||||
withdrawal_at datetime(6),
|
||||
member_id bigint,
|
||||
status varchar(255) not null,
|
||||
status varchar(8) not null,
|
||||
primary key (id)
|
||||
);
|
||||
) engine=InnoDB;
|
||||
|
||||
create table member (
|
||||
id bigint generated by default as identity,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
status varchar(255) not null,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table article (
|
||||
id bigint generated by default as identity,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
image varchar(255) not null,
|
||||
modified_at timestamp,
|
||||
status varchar(255) not null,
|
||||
title varchar(255) not null,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table article_likes (
|
||||
id bigint generated by default as identity,
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table article_tag (
|
||||
id bigint generated by default as identity,
|
||||
article_id bigint not null,
|
||||
tag_id bigint not null,
|
||||
primary key (id));
|
||||
|
||||
create table comment (
|
||||
id bigint generated by default as identity,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
modified_at timestamp,
|
||||
status varchar(255),
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table comment_likes (
|
||||
id bigint generated by default as identity,
|
||||
comment_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table tag (
|
||||
id bigint generated by default as identity,
|
||||
create table tag
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
name varchar(255) not null,
|
||||
primary key (id));
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
alter table account add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
alter table account add constraint FKr5j0huynd7nsv1s7e9vb8qvwo foreign key (member_id) references member;
|
||||
alter table tag add constraint UK_1wdpsed5kna2y38hnbgrnhi5b unique (name);
|
||||
alter table article add constraint UK_571gx7oqo5xpmgocegaidlcu9 unique (title);
|
||||
alter table article add constraint FK6l9vkfd5ixw8o8kph5rj1k7gu foreign key (member_id) references member;
|
||||
alter table article_likes add constraint FK1wt0ww82gfxkuxw3ghxmp55xy foreign key (article_id) references article;
|
||||
alter table article_likes add constraint FKkipxs7p8nrjd4537f3k8rexh5 foreign key (member_id) references member;
|
||||
alter table article_tag add constraint FKenqeees0y8hkm7x1p1ittuuye foreign key (article_id) references article;
|
||||
alter table article_tag add constraint FKesqp7s9jj2wumlnhssbme5ule foreign key (tag_id) references tag;
|
||||
alter table comment add constraint FK5yx0uphgjc6ik6hb82kkw501y foreign key (article_id) references article;
|
||||
alter table comment add constraint FKmrrrpi513ssu63i2783jyiv9m foreign key (member_id) references member;
|
||||
alter table comment_likes add constraint FKd0epu3dcjc57pwe7lt5jgfqsi foreign key (comment_id) references comment;
|
||||
alter table comment_likes add constraint FK7mxs5jtimpj71miv2r0fp6r8p foreign key (member_id) references member;
|
||||
create table article
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at datetime(6),
|
||||
image varchar(255) not null,
|
||||
modified_at datetime(6),
|
||||
status varchar(8) not null,
|
||||
title varchar(255) not null,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_likes
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_tag
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint not null,
|
||||
tag_id bigint not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at datetime(6),
|
||||
modified_at datetime(6),
|
||||
status varchar(8),
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment_likes
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
comment_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create index title_idx on article (title);
|
||||
alter table account
|
||||
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
alter table tag
|
||||
add constraint UK_1wdpsed5kna2y38hnbgrnhi5b unique (name);
|
||||
alter table member
|
||||
add constraint UK_gc3jmn7c2abyo3wf6syln5t2i unique (nickname);
|
||||
|
||||
@@ -8,6 +8,11 @@ insert into account(email, email_check_token, email_check_token_generated_at, em
|
||||
values ('jiwonDev@gmail.com', 'emailchecktoken', now(), false, now(), now(), 'password!',
|
||||
false, 'DEFAULT', 'ALIVE');
|
||||
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role, status)
|
||||
values ('jiwonDev@naver.com', 'emailchecktoken', now(), false, now(), now(), 'password!',
|
||||
false, 'DEFAULT', 'ALIVE');
|
||||
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role, member_id, status)
|
||||
values ('rebwon@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
|
||||
Reference in New Issue
Block a user