diff --git a/src/main/java/com/kukerton/domain/entity/Certification.java b/src/main/java/com/kukerton/domain/entity/Certification.java index 46c9170..958bf9e 100644 --- a/src/main/java/com/kukerton/domain/entity/Certification.java +++ b/src/main/java/com/kukerton/domain/entity/Certification.java @@ -7,7 +7,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.sql.Date; import org.springframework.format.annotation.DateTimeFormat; @Entity diff --git a/src/main/java/com/kukerton/dto/request/RandomRequest.java b/src/main/java/com/kukerton/dto/request/RandomRequest.java index bc20cec..825edf4 100644 --- a/src/main/java/com/kukerton/dto/request/RandomRequest.java +++ b/src/main/java/com/kukerton/dto/request/RandomRequest.java @@ -7,6 +7,8 @@ @Data @AllArgsConstructor public class RandomRequest { + @NotNull(message = "user id 항목은 필수입니다.") + private Long user_id; @NotNull(message = "분야선택 항목은 필수입니다.") private String category; diff --git a/src/main/java/com/kukerton/service/RandomService.java b/src/main/java/com/kukerton/service/RandomService.java index c8d786f..e05babb 100644 --- a/src/main/java/com/kukerton/service/RandomService.java +++ b/src/main/java/com/kukerton/service/RandomService.java @@ -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; @@ -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(); @@ -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 getStore() {