Skip to content

Commit

Permalink
refactor/rename
Browse files Browse the repository at this point in the history
  • Loading branch information
akozadaev committed Mar 20, 2023
1 parent 1e09348 commit 75f7fcf
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import ru.tsutmb.entities.Author;

public interface AuthorDao extends JpaRepository<Author, Integer> {
public interface AuthorRepository extends JpaRepository<Author, Integer> {

// SELECT * FROM author WHERE name = ?
Author findByName(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.List;

public interface BookDao extends JpaRepository<Book, Integer> {
public interface BookRepository extends JpaRepository<Book, Integer> {

@Override
@EntityGraph(attributePaths = {"genre", "author", "comments"}) // Решение N + 1, по сути внутри join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.List;

public interface CommentDao extends JpaRepository<Comment, Integer> {
public interface CommentRepositoryo extends JpaRepository<Comment, Integer> {

@Modifying
@Query("update Comment c set c.content = :content where c.id = :id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import ru.tsutmb.entities.Genre;

public interface GenreDao extends JpaRepository<Genre, Integer> {
public interface GenreRepository extends JpaRepository<Genre, Integer> {

// SELECT * FROM genre WHERE name = ?
Genre findByName(String name);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/ru/tsutmb/service/AuthorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.tsutmb.repository.AuthorDao;
import ru.tsutmb.repository.AuthorRepository;
import ru.tsutmb.entities.Author;

import java.util.List;
Expand All @@ -12,13 +12,13 @@
@RequiredArgsConstructor
public class AuthorService implements AuthorServiceInterface {

private final AuthorDao authorDao;
private final AuthorRepository authorRepository;

@Override
@Transactional
public Author insert(Author author) {

return authorDao.save(author);
return authorRepository.save(author);
}


Expand All @@ -32,31 +32,31 @@ public Author update(int id, String newNameAuthor) {
.name(newNameAuthor)
.build();

return authorDao.save(author);
return authorRepository.save(author);
}

@Override
public List<Author> getAll() {

return authorDao.findAll();
return authorRepository.findAll();
}

@Override
public Author getById(int id) {

return authorDao.getById(id);
return authorRepository.getById(id);
}

@Override
public Author getByName(String nameAuthor) {

return authorDao.findByName(nameAuthor);
return authorRepository.findByName(nameAuthor);
}

@Override
@Transactional
public void deleteById(int id) {

authorDao.deleteById(id);
authorRepository.deleteById(id);
}
}
28 changes: 14 additions & 14 deletions src/main/java/ru/tsutmb/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import ru.tsutmb.repository.AuthorDao;
import ru.tsutmb.repository.BookDao;
import ru.tsutmb.repository.GenreDao;
import ru.tsutmb.repository.AuthorRepository;
import ru.tsutmb.repository.BookRepository;
import ru.tsutmb.repository.GenreRepository;
import ru.tsutmb.entities.Author;
import ru.tsutmb.entities.Book;
import ru.tsutmb.entities.Genre;
Expand All @@ -18,9 +18,9 @@
@RequiredArgsConstructor
public class BookService implements BookServiceInterface {

private final GenreDao genreDao;
private final BookDao bookDao;
private final AuthorDao authorDao;
private final GenreRepository genreRepository;
private final BookRepository bookRepository;
private final AuthorRepository authorRepository;
private final AuthorServiceInterface authorServiceInterface;
private final GenreServiceInterface genreServiceInterface;

Expand All @@ -30,14 +30,14 @@ public Book insert(String nameBook,
String nameGenre,
String nameAuthor) {

Author author = authorDao.findByName(nameAuthor);
Author author = authorRepository.findByName(nameAuthor);
if (ObjectUtils.isEmpty(author)) {
author = Author.builder()
.name(nameAuthor)
.build();
}

Genre genre = genreDao.findByName(nameGenre);
Genre genre = genreRepository.findByName(nameGenre);
if (ObjectUtils.isEmpty(genre)) {
genre = Genre.builder()
.name(nameGenre)
Expand All @@ -50,7 +50,7 @@ public Book insert(String nameBook,
.genre(genre)
.build();

return bookDao.save(book);
return bookRepository.save(book);
}


Expand All @@ -68,31 +68,31 @@ public Book update(int id,
.genre(genreServiceInterface.getByName(nameGenre))
.build();

return bookDao.save(book);
return bookRepository.save(book);
}

@Override
public List<Book> getAll() {

return bookDao.findAll();
return bookRepository.findAll();
}

@Override
public Book getById(int id) {

return bookDao.getById(id);
return bookRepository.getById(id);
}

@Override
public Book getByName(String name) {

return bookDao.findByName(name);
return bookRepository.findByName(name);
}

@Transactional
@Override
public void deleteById(int id) {

bookDao.deleteById(id);
bookRepository.deleteById(id);
}
}
22 changes: 11 additions & 11 deletions src/main/java/ru/tsutmb/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.tsutmb.repository.BookDao;
import ru.tsutmb.repository.CommentDao;
import ru.tsutmb.repository.BookRepository;
import ru.tsutmb.repository.CommentRepositoryo;
import ru.tsutmb.entities.Book;
import ru.tsutmb.entities.Comment;

Expand All @@ -14,52 +14,52 @@
@RequiredArgsConstructor
public class CommentService implements CommentServiceInterface {

private final CommentDao commentDao;
private final BookDao bookDao;
private final CommentRepositoryo commentRepositoryo;
private final BookRepository bookRepository;

@Override
@Transactional
public Comment insert(String content, int bookId) {

Book book = bookDao.findById(bookId).orElse(null);
Book book = bookRepository.findById(bookId).orElse(null);

Comment comment = Comment.builder()
.content(content)
.book(book)
.build();

return commentDao.save(comment);
return commentRepositoryo.save(comment);
}

@Override
public List<Comment> getAll() {

return commentDao.findAll();
return commentRepositoryo.findAll();
}

@Override
public Comment getById(int id) {

return commentDao.getById(id);
return commentRepositoryo.getById(id);
}

@Override
public List<Comment> getByBookId(int id) {

return commentDao.findByBookId(id);
return commentRepositoryo.findByBookId(id);
}

@Override
@Transactional
public void update(int id, String content) {

commentDao.updateContentById(id, content);
commentRepositoryo.updateContentById(id, content);
}

@Override
@Transactional
public void deleteById(int id) {

commentDao.deleteById(id);
commentRepositoryo.deleteById(id);
}
}
16 changes: 8 additions & 8 deletions src/main/java/ru/tsutmb/service/GenreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.tsutmb.repository.GenreDao;
import ru.tsutmb.repository.GenreRepository;
import ru.tsutmb.entities.Genre;


Expand All @@ -13,13 +13,13 @@
@RequiredArgsConstructor
public class GenreService implements GenreServiceInterface {

private final GenreDao genreDao;
private final GenreRepository genreRepository;

@Override
@Transactional
public Genre insert(Genre genre) {

return genreDao.save(genre);
return genreRepository.save(genre);
}

@Override
Expand All @@ -31,31 +31,31 @@ public Genre update(int id, String name) {
.name(name)
.build();

return genreDao.save(genre);
return genreRepository.save(genre);
}

@Override
public List<Genre> getAll() {

return genreDao.findAll();
return genreRepository.findAll();
}

@Override
public Genre getById(int id) {

return genreDao.getById(id);
return genreRepository.getById(id);
}

@Override
public Genre getByName(String name) {

return genreDao.findByName(name);
return genreRepository.findByName(name);
}

@Override
@Transactional
public void deleteById(int id) {

genreDao.deleteById(id);
genreRepository.deleteById(id);
}
}

0 comments on commit 75f7fcf

Please sign in to comment.