|
1 | 1 | package com.codecrafter.commenting.service;
|
2 | 2 |
|
3 |
| -import com.codecrafter.commenting.config.SecurityUtil; |
4 | 3 | import com.codecrafter.commenting.config.jwt.TokenProvider;
|
5 | 4 | import com.codecrafter.commenting.domain.entity.MemberAuth;
|
6 | 5 | import com.codecrafter.commenting.domain.entity.MemberInfo;
|
7 | 6 | import com.codecrafter.commenting.domain.entity.MemberSetting;
|
8 | 7 | import com.codecrafter.commenting.domain.enumeration.Provider;
|
9 | 8 | import com.codecrafter.commenting.domain.request.SignInRequest;
|
10 | 9 | import com.codecrafter.commenting.domain.request.SignUpRequest;
|
| 10 | +import com.codecrafter.commenting.domain.response.MemberInfoResponse; |
11 | 11 | import com.codecrafter.commenting.domain.response.SignInResponse;
|
12 | 12 | import com.codecrafter.commenting.domain.response.SignUpResponse;
|
13 | 13 | import com.codecrafter.commenting.exception.AuthenticationFailedException;
|
|
16 | 16 | import com.codecrafter.commenting.repository.MemberSettingRepository;
|
17 | 17 | import io.jsonwebtoken.Claims;
|
18 | 18 | import jakarta.validation.Valid;
|
| 19 | +import java.util.Collections; |
| 20 | +import java.util.List; |
19 | 21 | import java.util.Optional;
|
| 22 | +import java.util.concurrent.ThreadLocalRandom; |
20 | 23 | import lombok.RequiredArgsConstructor;
|
21 | 24 | import lombok.extern.slf4j.Slf4j;
|
22 | 25 | import org.springframework.dao.DataIntegrityViolationException;
|
|
29 | 32 | @Slf4j
|
30 | 33 | @Transactional(readOnly = true)
|
31 | 34 | public class MemberService {
|
| 35 | + |
32 | 36 | private final MemberAuthRepository memberAuthRepository;
|
33 | 37 | private final MemberInfoRepository memberInfoRepository;
|
34 | 38 | private final MemberSettingRepository memberSettingRepository;
|
@@ -107,4 +111,20 @@ public boolean chkDupEmail(String email) {
|
107 | 111 | return false;
|
108 | 112 | }
|
109 | 113 |
|
| 114 | + @Transactional(readOnly = true) |
| 115 | + public List<MemberInfoResponse> getRandomMembers() { |
| 116 | + List<Long> ids = memberInfoRepository.findAllIds(); |
| 117 | + Collections.shuffle(ids, ThreadLocalRandom.current()); |
| 118 | + |
| 119 | + ids = ids.stream() |
| 120 | + .limit(10) |
| 121 | + .toList(); |
| 122 | + |
| 123 | + List<MemberInfo> memberInfos = memberInfoRepository.findAllById(ids); |
| 124 | + |
| 125 | + return memberInfos.stream() |
| 126 | + .map(MemberInfoResponse::from) |
| 127 | + .toList(); |
| 128 | + } |
| 129 | + |
110 | 130 | }
|
0 commit comments