Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ public class PlaylistService {
VideoRepository videoRepository;


public void addPlaylist(PlaylistName playlistName){
public void addPlaylist(PlaylistName playlistName) {

playlistNameRepository.save(playlistName);
}

public void addVideo(PlaylistVideo playlistVideo){
public void addVideo(PlaylistVideo playlistVideo) {

playlistVideoRepository.save(playlistVideo);
}

public List<PlaylistName> listPlaylist(){
public List<PlaylistName> listPlaylist() {
List<PlaylistName> listPlaylistName = playlistNameRepository.findAll();
return listPlaylistName;
}

public List<PlaylistName> sortPlaylist(){
public List<PlaylistName> sortPlaylist() {
List<PlaylistName> listByPlaylistName = playlistNameRepository.findAll();
List<PlaylistName> sortList = listByPlaylistName.stream().sorted(Comparator.comparing(PlaylistName::getPlaylistname)).collect(Collectors.toList());
return sortList;
}

public List<PlaylistVideo> listPlaylistVideo(){
public List<PlaylistVideo> listPlaylistVideo() {
List<PlaylistVideo> listPlaylistVideo = playlistVideoRepository.findAll();
return listPlaylistVideo;
}

public String countPlaylist(String playlistName){
List<PlaylistVideo> listByPlaylistVideo =playlistVideoRepository.findByPlaylistName(playlistName);
public String countPlaylist(String playlistName) {
List<PlaylistVideo> listByPlaylistVideo = playlistVideoRepository.findByPlaylistName(playlistName);

return "Number of videos inside playlist: " + listByPlaylistVideo.size();
}

public String addVideoToPlaylist(String playlist, String videoName){
public String addVideoToPlaylist(String playlist, String videoName) {

PlaylistName playlistName = playlistNameRepository.findOneByName(playlist);
Video video = videoRepository.findOneByName(videoName);
Expand All @@ -71,7 +71,7 @@ public String addVideoToPlaylist(String playlist, String videoName){
return "Success";
}

public ListPlaylistByVideoNameAndChannelNameDto listByVideoNameAndChannelName (String videoName, String channelName){
public ListPlaylistByVideoNameAndChannelNameDto listByVideoNameAndChannelName(String videoName, String channelName) {
List<PlaylistVideo> playlistVideos = playlistVideoRepository.findByVideoNameAndChannelName(videoName, channelName);
ListPlaylistByVideoNameAndChannelNameDto listPlaylistByVideoNameAndChannelNameDtos = new ListPlaylistByVideoNameAndChannelNameDto();
listPlaylistByVideoNameAndChannelNameDtos.setPlaylistName(playlistVideos.get(0).getPlaylistName().getPlaylistname());
Expand All @@ -80,21 +80,13 @@ public ListPlaylistByVideoNameAndChannelNameDto listByVideoNameAndChannelName (S
return listPlaylistByVideoNameAndChannelNameDtos;
}

public List<ListPlaylistByChannelDto> listPlaylistNameByChannelName(String channelName){
public List<ListPlaylistByChannelDto> listPlaylistNameByChannelName(String channelName) {
List<PlaylistVideo> playlistVideos = playlistVideoRepository.findPlaylistNameByChannelName(channelName);
ListPlaylistByChannelDto listPlaylistByChannelDto = new ListPlaylistByChannelDto();
List<ListPlaylistByChannelDto> listPlaylistByChannelDtos = new ArrayList<>();
// for (int i =0; i<playlistVideos.size(); i++)
// {
// ListPlaylistByChannelDto listPlaylistByChannelDto = new ListPlaylistByChannelDto();
// listPlaylistByChannelDto.setPlaylistName(playlistVideos.get(i).getPlaylistName().getPlaylistname());
// listPlaylistByChannelDto.setChannelName(playlistVideos.get(i).getVideo().getChannel().getChannelName());
// listPlaylistByChannelDtos.add(listPlaylistByChannelDto);
// }
for (PlaylistVideo playlistVideoIterator: playlistVideos)
{
ListPlaylistByChannelDto listPlaylistByChannelDto = new ListPlaylistByChannelDto();
listPlaylistByChannelDto.setPlaylistName(playlistVideoIterator.getPlaylistName().getPlaylistname());
listPlaylistByChannelDto.setChannelName(playlistVideoIterator.getVideo().getChannel().getChannelName());
for (int i = 0; i < playlistVideos.size(); i++) {
listPlaylistByChannelDto.setPlaylistName(playlistVideos.get(i).getPlaylistName().getPlaylistname());
listPlaylistByChannelDto.setChannelName(playlistVideos.get(i).getVideo().getChannel().getChannelName());
listPlaylistByChannelDtos.add(listPlaylistByChannelDto);
}
return listPlaylistByChannelDtos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.springKaiser.business.student;

import com.example.springKaiser.entities.Students;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentMapper {

StudentDto toDto(Students students) {
StudentDto studentDto = new StudentDto();
studentDto.setName(students.getName());
studentDto.setEmail(students.getEmail());
studentDto.setGradeId(students.getGrade().getId());
studentDto.setHomeGradeTeacherId(students.getHomeGradeTeacher().getId());
return studentDto;
}

List<StudentDto> toList(List<Students> studentsList) {
List<StudentDto> studentDtoList = new ArrayList<>();
//Same as below
// for (Students studentElement : studentsList){
// studentDtoList.add(toDto(studentElement));
// }

for (int i = 0; i < studentsList.size(); i++) {
StudentDto studentDto = toDto(studentsList.get(i));
studentDtoList.add(studentDto);
}
return studentDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class StudentsService {
@Autowired
TeacherRepository teacherRepository;

@Autowired
StudentMapper studentMapper;

final int gradeOne = 1;

public String saveStudentOnGrade(){
Expand Down Expand Up @@ -87,6 +90,11 @@ public List<Students> listStudents() {
return listStudents;
}

public List<StudentDto> getListOfStudents() {
List<StudentDto> studentsDtos = studentMapper.toList(studentsRepository.findAll());
return studentsDtos;
}

public List<Students> listStudentsByGrade(int studentGrade) {
List<Students> studentsOnThatSpecificGrade = new ArrayList<>();
for(Students student : listStudents()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ public String addStudents(@RequestBody StudentDto studentDto) {
return studentsService.saveStudent(studentDto);
}

@GetMapping("/getStudentDtoList")
public List<StudentDto> getStudentsDtos() {
return studentsService.getListOfStudents();
}

}