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

[DEV-189] 배치 인서트를 위한 로직 수정 및 설정 수정 반영 #83

Merged
merged 4 commits into from
Apr 12, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
hibernate:
ddl-auto: validate
show-sql: true
properties:
hibernate:
format_sql: true
jdbc.batch_size: 300
order_inserts: true
order_updates: true
generate_statistics: true
flyway:
enabled: true
mail:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.tiketeer.Tiketeer.domain.stresstest.usecase;

import java.util.HashMap;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tiketeer.Tiketeer.domain.member.Member;
import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository;
import com.tiketeer.Tiketeer.domain.role.Role;
import com.tiketeer.Tiketeer.domain.role.exception.RoleNotFoundException;
import com.tiketeer.Tiketeer.domain.role.constant.RoleEnum;
import com.tiketeer.Tiketeer.domain.role.repository.RoleRepository;
import com.tiketeer.Tiketeer.domain.stresstest.controller.dto.BasicMemberInfo;
import com.tiketeer.Tiketeer.domain.stresstest.controller.dto.CreateMembersForStressTestCommandDto;

@Service
Expand All @@ -29,24 +30,21 @@ public CreateMembersForStressTestUseCase(MemberRepository memberRepository, Role

@Transactional
public void createMembers(CreateMembersForStressTestCommandDto command) {
command.getMembers().forEach(
this::createMember
);
var memberInfoList = command.getMembers();
var roles = roleRepository.findAll();
HashMap<RoleEnum, Role> roleMap = new HashMap<>();
roles.forEach((role) -> {
roleMap.put(role.getName(), role);
});
var members = memberInfoList.stream().map((meta) ->
Member.builder()
.email(meta.email())
.point(10000000)
.enabled(true)
.profileUrl(null)
.role(roleMap.get(meta.role()))
.password(passwordEncoder.encode(meta.password())).build()
).toList();
memberRepository.saveAll(members);
}

private void createMember(BasicMemberInfo basicMemberInfo) {
Role role = roleRepository.findByName(basicMemberInfo.role()).orElseThrow(RoleNotFoundException::new);
String pwd = passwordEncoder.encode(basicMemberInfo.password());

Member member = Member.builder()
.email(basicMemberInfo.email())
.point(10000000)
.enabled(true)
.profileUrl(null)
.role(role)
.password(pwd)
.build();
memberRepository.save(member);
}

}
4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ spring:
properties:
hibernate:
format_sql: true
jdbc.batch_size: 300
order_inserts: true
order_updates: true
generate_statistics: true
flyway:
enabled: false
h2:
Expand Down
Loading