Skip to content

Commit 54048e4

Browse files
authored
Merge branch 'master' into dependabot/maven/junit-junit-4.13.1
2 parents 358dc70 + d9058c0 commit 54048e4

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

src/main/java/com/example/controller/BookController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public List<Book> find(@QueryValue @Size(max = 1024, min = 1) Optional<String> t
3636
books = service.findAll();
3737
}
3838
return books;
39+
3940
}
4041

4142
@Version("1.1")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.controller.api;
2+
3+
public final class URlConstants {
4+
5+
public URlConstants() throws IllegalAccessException {
6+
throw new IllegalAccessException("it is just for constants");
7+
}
8+
9+
private static final String BOOKS = "books";
10+
private static final String TITLE = "title";
11+
private static final String MODEL = "model";
12+
private static final String INIT = "init";
13+
private static final String COUNT = "count";
14+
}

src/main/java/com/example/repository/BookRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ public interface BookRepository extends CrudRepository<Book, Long>, JpaSpecifica
2525
@EntityGraph(attributePaths = {"author", "title"})
2626
List<Book> findAll();
2727

28+
Optional<Integer> findPagesById(Long id);
29+
30+
Long findSumPages();
31+
2832
List<BookDTO> find();
2933
}

src/main/java/com/example/service/AuthorService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
@Primary
99
@Singleton
1010
public class AuthorService {
11-
1211
@Inject
1312
AuthorRepository repository;
1413

15-
1614
public void getAll() {
1715
repository.findAll();
1816
}

src/main/java/com/example/service/BookService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.transaction.Transactional;
1212
import java.util.List;
1313
import java.util.Optional;
14+
import java.util.stream.Collectors;
1415

1516
@Primary
1617
@Singleton
@@ -67,6 +68,24 @@ public Book fall() {
6768

6869
}
6970

71+
@Transactional
72+
public Long totalPages(List<Long> id){
73+
74+
return id.stream()
75+
.map(this::getPages)
76+
.collect(Collectors.summarizingLong(Integer::intValue))
77+
.getCount();
78+
}
79+
80+
@Transactional
81+
public Integer getPages(Long bookId){
82+
return repository.findPagesById(bookId).orElse(0);
83+
}
84+
85+
@Transactional
86+
public Long sumPages(){
87+
return repository.findSumPages();
88+
}
7089
@Transactional
7190
public void create(Book book) {
7291
repository.save(book);

src/main/resources/db/liquibase-changelog.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,4 @@
7878
</sql>
7979
</changeSet>
8080

81-
8281
</databaseChangeLog>

0 commit comments

Comments
 (0)