-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoService.java
More file actions
67 lines (54 loc) · 2.06 KB
/
VideoService.java
File metadata and controls
67 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.birichani.code.restapi.service;
import com.birichani.code.restapi.constant.ErrorMessage;
import com.birichani.code.restapi.constant.InfoMessage;
import com.birichani.code.restapi.model.Video;
import com.birichani.code.restapi.repository.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author - JoeSeff
* @created - 22/10/2020 23:57
*/
@Service
public class VideoService {
private final VideoRepository videoRepository;
@Autowired
public VideoService(VideoRepository videoRepository) {
this.videoRepository = videoRepository;
}
public String getVideosByTopic(String videoTopic) {
String message;
switch (videoTopic.toLowerCase()) {
case "python":
message = InfoMessage.PYTHON_RESPONSE_MESSAGE;
break;
case "java":
message = InfoMessage.JAVA_RESPONSE_MESSAGE;
break;
default:
message = ErrorMessage.VIDEO_TOPIC_SELECTION_MESSAGE;
}
return message;
}
public List<Video> filterVideosByTopic(String topic) {
List<Video> videoList = videoRepository.findAll();
return videoList.stream()
.filter(Objects::nonNull)
.filter(video -> video.getTopic() != null)
.filter(video -> video.getTopic().equalsIgnoreCase(topic))
.collect(Collectors.toList());
}
// TODO: Implement me
public List<Video> filterVideosByTitle(String title) {
List<Video> videoList = videoRepository.findAll();
return videoList.stream()
.filter(Objects::nonNull)
.filter(video -> video.getTitle() != null)
.filter(video -> video.getTitle().toLowerCase().contains(title.toLowerCase()))
.collect(Collectors.toList());
}
}