Skip to content

Commit

Permalink
feat : api 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
imscow11253 committed Apr 6, 2024
1 parent 704ac4f commit 604060a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
28 changes: 12 additions & 16 deletions src/main/java/com/kukerton/service/RandomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand All @@ -25,27 +24,24 @@ public String getRandomTask(RandomRequest randomRequest) {
String isInterested = randomRequest.getCategory();

List<Config> configList = configRepository.findAllByIsWant(isInterested.equals("Interested"));

List<Task> taskList = new ArrayList<>();
configList
.forEach(config -> taskList.addAll(taskRepository.findAllByCategory(config.getCategory())));

taskList
.forEach(task -> {
if(task.getHour() > randomRequest.getHour()){
taskList.remove(task);
}
else if(task.getHour().equals(randomRequest.getHour())){
if(task.getMinute() > randomRequest.getMinute()){
taskList.remove(task);
}
}
});

System.out.println(taskList.size());
List<Task> newTaskList = taskList.stream()
.filter(task -> task.getHour() <= randomRequest.getHour())
.filter(task -> task.getHour().equals(randomRequest.getHour()) && task.getMinute() <= randomRequest.getMinute())
.toList();


if(newTaskList.isEmpty()){
return null;
}

//System.out.println(newTaskList.size());
Random rnd = new Random();
rnd.setSeed(System.currentTimeMillis());
return taskList.get(rnd.nextInt(taskList.size())).getContent();
return newTaskList.get(rnd.nextInt(newTaskList.size())).getContent();

}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spring:
jpa:
show-sql: true
hibernate:
ddl-auto: none
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ INSERT INTO task(id,content,category,title,hour,minute) values (6,'배달음식2
INSERT INTO task(id,content,category,title,hour,minute) values (7,'게임1','게임','게임쓰','0','30');
INSERT INTO task(id,content,category,title,hour,minute) values (8,'게임2','게임','게임쓰','1','0');

INSERT INTO store(id,name,category,is_opened,end_time,task_id) values (1,'더 클라임 서울','운동',true,'22:00');
INSERT INTO store(id,name,category,is_opened,end_time,task_id) values (1,'더 클라임 서울','운동',true,'22:00',1);

INSERT INTO certification(id, img_url, task_title, user_title, review, local_date, is_cleared,
member_id)
Expand Down

0 comments on commit 604060a

Please sign in to comment.