-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorServiceImpl.java
More file actions
54 lines (41 loc) · 1.61 KB
/
AuthorServiceImpl.java
File metadata and controls
54 lines (41 loc) · 1.61 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
package com.mehmetpekdemir.librarymanagementsystem.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.mehmetpekdemir.librarymanagementsystem.entity.Author;
import com.mehmetpekdemir.librarymanagementsystem.exception.NotFoundException;
import com.mehmetpekdemir.librarymanagementsystem.repository.AuthorRepository;
import com.mehmetpekdemir.librarymanagementsystem.service.AuthorService;
@Service
public class AuthorServiceImpl implements AuthorService {
private final AuthorRepository authorRepository;
public AuthorServiceImpl(AuthorRepository authorRepository) {
this.authorRepository = authorRepository;
}
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Override
public List<Author> findAllAuthors() {
return authorRepository.findAll();
}
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Override
public Author findAuthorById(Long id) {
return authorRepository.findById(id)
.orElseThrow(() -> new NotFoundException(String.format("Author not found with ID %d", id)));
}
@Override
public void createAuthor(Author author) {
authorRepository.save(author);
}
@Override
public void updateAuthor(Author author) {
authorRepository.save(author);
}
@Override
public void deleteAuthor(Long id) {
final Author author = authorRepository.findById(id)
.orElseThrow(() -> new NotFoundException(String.format("Author not found with ID %d", id)));
authorRepository.deleteById(author.getId());
}
}