10
10
import su .foxogram .constants .StorageConstants ;
11
11
import su .foxogram .constants .UserConstants ;
12
12
import su .foxogram .dtos .request .UserEditDTO ;
13
+ import su .foxogram .dtos .response .ChannelDTO ;
13
14
import su .foxogram .exceptions .cdn .UploadFailedException ;
14
15
import su .foxogram .exceptions .code .CodeExpiredException ;
15
16
import su .foxogram .exceptions .code .CodeIsInvalidException ;
16
17
import su .foxogram .exceptions .user .UserCredentialsDuplicateException ;
17
18
import su .foxogram .exceptions .user .UserCredentialsIsInvalidException ;
18
19
import su .foxogram .exceptions .user .UserNotFoundException ;
19
20
import su .foxogram .models .Code ;
21
+ import su .foxogram .models .Member ;
20
22
import su .foxogram .models .User ;
23
+ import su .foxogram .repositories .MemberRepository ;
21
24
import su .foxogram .repositories .UserRepository ;
22
25
import su .foxogram .util .CodeGenerator ;
23
26
import su .foxogram .util .Encryptor ;
24
27
28
+ import java .util .List ;
29
+ import java .util .stream .Collectors ;
30
+
25
31
@ Slf4j
26
32
@ Service
27
33
public class UsersService {
@@ -33,12 +39,15 @@ public class UsersService {
33
39
34
40
private final StorageService storageService ;
35
41
42
+ private final MemberRepository memberRepository ;
43
+
36
44
@ Autowired
37
- public UsersService (UserRepository userRepository , EmailService emailService , CodeService codeService , StorageService storageService ) {
45
+ public UsersService (UserRepository userRepository , EmailService emailService , CodeService codeService , StorageService storageService , MemberRepository memberRepository ) {
38
46
this .userRepository = userRepository ;
39
47
this .emailService = emailService ;
40
48
this .codeService = codeService ;
41
49
this .storageService = storageService ;
50
+ this .memberRepository = memberRepository ;
42
51
}
43
52
44
53
public User getUser (String username ) throws UserNotFoundException {
@@ -49,6 +58,14 @@ public User getUser(String username) throws UserNotFoundException {
49
58
return user ;
50
59
}
51
60
61
+ public List <ChannelDTO > getChannels (User user ) {
62
+ return memberRepository .findAllByUserId (user .getId ())
63
+ .stream ()
64
+ .map (Member ::getChannel )
65
+ .map (ChannelDTO ::new )
66
+ .collect (Collectors .toList ());
67
+ }
68
+
52
69
public User editUser (User user , UserEditDTO body ) throws UserCredentialsDuplicateException , UploadFailedException {
53
70
if (body .getDisplayName () != null ) user .setDisplayName (body .getDisplayName ());
54
71
if (body .getAvatar () != null ) changeAvatar (user , body .getAvatar ());
0 commit comments