Skip to content

Commit

Permalink
Merge pull request #9 from Kusitms-Kukerton-D/dev/task
Browse files Browse the repository at this point in the history
update : 랜덤 박스 시 새로운 certification entity 생성
  • Loading branch information
imscow11253 authored Apr 6, 2024
2 parents 16d64db + 179ae64 commit 0e9166c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.sql.Date;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kukerton/dto/request/RandomRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@Data
@AllArgsConstructor
public class RandomRequest {
@NotNull(message = "user id 항목은 필수입니다.")
private Long user_id;

@NotNull(message = "분야선택 항목은 필수입니다.")
private String category;
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/kukerton/service/RandomService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.kukerton.service;

import com.kukerton.domain.entity.Certification;
import com.kukerton.domain.entity.Config;
import com.kukerton.domain.entity.Store;
import com.kukerton.domain.entity.Task;
import com.kukerton.domain.repository.ConfigRepository;
import com.kukerton.domain.repository.CouponRepository;
import com.kukerton.domain.repository.StoreRepository;
import com.kukerton.domain.repository.TaskRepository;
import com.kukerton.domain.repository.*;
import com.kukerton.dto.request.RandomRequest;
import com.kukerton.global.response.StoreResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,6 +24,8 @@ public class RandomService {
private final TaskRepository taskRepository;
private final StoreRepository storeRepository;
private final CouponRepository couponRepository;
private final CertificationRepository certificationRepository;
private final MemberRepository memberRepository;
public String getRandomTask(RandomRequest randomRequest) {

String isInterested = randomRequest.getCategory();
Expand All @@ -48,8 +48,16 @@ public String getRandomTask(RandomRequest randomRequest) {
//System.out.println(newTaskList.size());
Random rnd = new Random();
rnd.setSeed(System.currentTimeMillis());
return newTaskList.get(rnd.nextInt(newTaskList.size())).getContent();

Task result = newTaskList.get(rnd.nextInt(newTaskList.size()));

certificationRepository.save(
Certification.builder()
.taskTitle(result.getTitle())
.member(memberRepository.findById(randomRequest.getUser_id()).orElse(null))
.build());

return result.getContent();
}

public List<StoreResponse> getStore() {
Expand Down

0 comments on commit 0e9166c

Please sign in to comment.