-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseService.java
More file actions
40 lines (28 loc) · 1 KB
/
Copy pathDatabaseService.java
File metadata and controls
40 lines (28 loc) · 1 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
package com.example.WatchlistApplication.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.WatchlistApplication.entity.Movie;
import com.example.WatchlistApplication.repository.MovieRepo;
@Service
public class DatabaseService {
@Autowired
MovieRepo movieRepo;
public void create(Movie movie){
movieRepo.save(movie);
}
public List<Movie> getAllMovies() {
return movieRepo.findAll();
}
public Movie getMovieById(Integer id) {
return movieRepo.findById(id).get();
}
public void update(Movie movie,Integer id) {
Movie toBeUpdated = getMovieById(id);
toBeUpdated.setTitle(movie.getTitle());
toBeUpdated.setRating(movie.getRating());
toBeUpdated.setComment(movie.getComment());
toBeUpdated.setPriority(movie.getPriority());
movieRepo.save(toBeUpdated);
}
}