-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHomeCacheService.kt
More file actions
54 lines (44 loc) · 1.68 KB
/
HomeCacheService.kt
File metadata and controls
54 lines (44 loc) · 1.68 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.stepbookstep.server.domain.home.application
import com.stepbookstep.server.domain.book.domain.Book
import com.stepbookstep.server.domain.book.domain.BookRepository
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
@Service
@Transactional(readOnly = true)
class HomeCacheService(
private val bookRepository: BookRepository
) {
@Cacheable(value = ["genreBooks"], key = "#genre")
fun getGenreBooks(genre: String): List<Book> {
return bookRepository.findAllByGenre(genre)
}
@Cacheable(value = ["under200Books"])
fun getUnder200Books(): List<Book> {
return bookRepository.findAllUnder200Pages()
}
@Cacheable(value = ["bestsellerBooks"])
fun getBestsellerBooks(): List<Book> {
return bookRepository.findAllBestsellers()
}
@Cacheable(value = ["level3Books"])
fun getLevel3Books(): List<Book> {
return bookRepository.findAllByLevel3()
}
@Cacheable(value = ["categoryBooks"], key = "#categoryId")
fun getBooksByCategoryId(categoryId: Long): List<Book> {
return bookRepository.findAllByCategoryId(categoryId)
}
@Cacheable(value = ["genreIdBooks"], key = "#genreId")
fun getBooksByGenreId(genreId: Long): List<Book> {
return bookRepository.findAllByGenreId(genreId)
}
@Cacheable(value = ["distinctCategoryIds"])
fun getDistinctCategoryIds(): List<Long> {
return bookRepository.findDistinctCategoryIds()
}
@Cacheable(value = ["distinctGenreIds"])
fun getDistinctGenreIds(): List<Long> {
return bookRepository.findDistinctGenreIds()
}
}