Skip to content

Commit

Permalink
refactor: 사용하지 않는 메서드 제거 및 리팩터링
Browse files Browse the repository at this point in the history
  • Loading branch information
SeonJuuuun committed Mar 31, 2024
1 parent 19e8ab6 commit 994dcda
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 31 deletions.
1 change: 0 additions & 1 deletion doochul/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
Expand Down
10 changes: 0 additions & 10 deletions doochul/src/main/java/org/doochul/config/SchedulingConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

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

import java.time.LocalDateTime;
import java.util.List;

public interface LessonRepository extends JpaRepository<Lesson, Long> {
default Lesson getById(final Long id) {
return findById(id).orElseThrow(() -> new IllegalArgumentException("해당 수업이 없습니다."));
}

List<Lesson> findByStartedAtBefore(final LocalDateTime currentServerTime);
List<Lesson> findOngoingLessons(final LocalDateTime now);
}
4 changes: 0 additions & 4 deletions doochul/src/main/java/org/doochul/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ public class User extends BaseEntity {

private String deviceToken;

private String passWord;

@Enumerated(EnumType.STRING)
private Gender gender;

@Enumerated(EnumType.STRING)
private Identity identity;

private String email;

private User(final Identity identity, final String socialId, final String name) {
this.identity = identity;
this.socialId = Long.parseLong(socialId);
Expand Down
6 changes: 3 additions & 3 deletions doochul/src/main/java/org/doochul/job/BatchScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class BatchScheduler {
private final Job updateRemainingCountJob;

public BatchScheduler(JobLauncher jobLauncher,
@Qualifier("sandNotificationAfterLessonJob") Job sandNotificationAfterLessonJob,
@Qualifier("sandNotificationBeforeLessonJob") Job sandNotificationBeforeLessonJob,
@Qualifier("sendNotificationAfterLessonJob") Job sandNotificationAfterLessonJob,
@Qualifier("sendNotificationBeforeLessonJob") Job sandNotificationBeforeLessonJob,
@Qualifier("updateRemainingCountJob") Job updateRemainingCountJob) {
this.jobLauncher = jobLauncher;
this.sandNotificationAfterLessonJob = sandNotificationAfterLessonJob;
Expand All @@ -39,4 +39,4 @@ private void runJob(Job job) throws Exception {
.toJobParameters();
jobLauncher.run(job, parameters);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SendNotificationAfterLessonJobConfig(final DataSource dataSource, final S
}

@Bean
public Job sandNotificationAfterLessonJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) throws Exception {
public Job sendNotificationAfterLessonJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) throws Exception {
return new JobBuilder("sandNotificationAfterLesson", jobRepository)
.incrementer(new RunIdIncrementer())
.start(sendNotificationBeforeClassStep(jobRepository, transactionManager))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public class SendNotificationBeforeLessonJobConfig {
private final DataSource dataSource;
private final SendNotificationItemWriter sendNotificationItemWriter;

public SendNotificationBeforeLessonJobConfig(final DataSource dataSource, final SendNotificationItemWriter sendNotificationItemWriter) {
public SendNotificationBeforeLessonJobConfig(final DataSource dataSource,
final SendNotificationItemWriter sendNotificationItemWriter) {
this.dataSource = dataSource;
this.sendNotificationItemWriter = sendNotificationItemWriter;
}

@Bean
public Job sandNotificationBeforeLessonJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) throws Exception {
public Job sendNotificationBeforeLessonJob(JobRepository jobRepository,
PlatformTransactionManager transactionManager) throws Exception {
return new JobBuilder("sandNotificationBeforeLessonJob", jobRepository)
.incrementer(new RunIdIncrementer())
.start(sendNotificationBeforeLessonStep(jobRepository, transactionManager))
Expand Down Expand Up @@ -80,8 +82,10 @@ public JdbcPagingItemReader<Map<String, Object>> addNotificationItemReader() thr
private PagingQueryProvider createQueryProvider() throws Exception {
SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean();
queryProvider.setDataSource(dataSource);
queryProvider.setSelectClause("SELECT u.device_token AS student_token, u.name AS student_name, t.name AS teacher_name, l.started_at");
queryProvider.setFromClause("FROM lesson l JOIN users u ON l.student_id = u.id JOIN users t ON l.teacher_id = t.id");
queryProvider.setSelectClause(
"SELECT u.device_token AS student_token, u.name AS student_name, t.name AS teacher_name, l.started_at");
queryProvider.setFromClause(
"FROM lesson l JOIN users u ON l.student_id = u.id JOIN users t ON l.teacher_id = t.id");
queryProvider.setWhereClause("WHERE l.started_at <= :startedAt");
Map<String, Order> sortKeys = new HashMap<>(1);
sortKeys.put("l.started_at", Order.ASCENDING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.doochul.application.MemberShipService;
import org.doochul.resolver.AuthenticationPrincipal;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.doochul.application.ProductService;
import org.doochul.resolver.AuthenticationPrincipal;
import org.doochul.ui.dto.ProductRegisterRequest;
import org.doochul.ui.dto.ProductResponse;
import org.springframework.http.ResponseEntity;
Expand Down
2 changes: 1 addition & 1 deletion doochul/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;

spring.main.allow-bean-definition-overriding=true
fcm.certification.path=kwakdoochul-bbb43-firebase-adminsdk-oyokf-f075393454.json
77 changes: 77 additions & 0 deletions doochul/src/test/java/org/doochul/MemberShipServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.doochul;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.times;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.doochul.application.RedisService;
import org.doochul.domain.membership.MemberShip;
import org.doochul.domain.membership.MemberShipRepository;
import org.doochul.domain.product.Product;
import org.doochul.domain.product.ProductRepository;
import org.doochul.domain.product.ProductType;
import org.doochul.domain.user.User;
import org.doochul.domain.user.UserRepository;
import org.doochul.ui.dto.ProductRegisterRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;

@SpringBootTest
public class MemberShipServiceTest {

@MockBean
private MemberShipRepository memberShipRepository;

@Autowired
private ProductRepository productRepository;

@Autowired
private UserRepository userRepository;

@Autowired
private RedisService redisService;

@Test
void memberShip_save() throws InterruptedException {
// Given
User user = User.of("123", "1234");
User teacher = User.of("1234", "123");

userRepository.save(user);
userRepository.save(teacher);

Product product = Product.of(teacher, new ProductRegisterRequest("페이커", ProductType.LOL, 10));
productRepository.save(product);

ExecutorService executorService = Executors.newFixedThreadPool(5);
CountDownLatch latch = new CountDownLatch(5);

given(memberShipRepository.save(any())).willReturn(new MemberShip(1L, user, product, 10));

for (int i = 0; i < 5; i++) {
executorService.submit(() -> {
try {
final String key = Long.toString(user.getId());
if (redisService.setNX(key, "apply", Duration.ofSeconds(5))) {
memberShipRepository.save(MemberShip.of(user, product, product.getCount()));
redisService.delete(key);
}
} finally {
latch.countDown();
}
});
}

latch.await();
executorService.shutdown();

then(memberShipRepository).should(times(1)).save(any());
}
}

0 comments on commit 994dcda

Please sign in to comment.