Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.net.URI;
import java.util.List;

import jakarta.validation.Valid;

import org.hibernate.validator.constraints.ISBN;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -16,9 +14,12 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;

import ar.com.nanotaboada.java.samples.spring.boot.models.BookDTO;
import ar.com.nanotaboada.java.samples.spring.boot.services.BooksService;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Contact;
Expand All @@ -29,9 +30,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import ar.com.nanotaboada.java.samples.spring.boot.models.BookDTO;
import ar.com.nanotaboada.java.samples.spring.boot.services.BooksService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

@RestController
@Tag(name = "Books")
Expand Down Expand Up @@ -100,6 +100,18 @@ public ResponseEntity<List<BookDTO>> getAll() {
return ResponseEntity.status(HttpStatus.OK).body(books);
}

@GetMapping("/books/search")
@Operation(summary = "Searches books by description keyword")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK - Returns matching books (or empty array if none found)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = BookDTO[].class))),
@ApiResponse(responseCode = "400", description = "Bad Request - Missing or blank description parameter", content = @Content)
})
public ResponseEntity<List<BookDTO>> searchByDescription(
@RequestParam @NotBlank(message = "Description parameter must not be blank") String description) {
List<BookDTO> books = booksService.searchByDescription(description);
return ResponseEntity.status(HttpStatus.OK).body(books);
}

/*
* -------------------------------------------------------------------------
* HTTP PUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,171 @@
definitions and measures of productivity.""");
book9781484242216.setWebsite("https://link.springer.com/book/10.1007/978-1-4842-4221-6");
books.add(book9781484242216);
Book book9781642002232 = new Book();
book9781642002232.setIsbn("9781642002232");
book9781642002232.setTitle("Database Design Succinctly");
book9781642002232.setAuthor("Joseph D. Booth");
book9781642002232.setPublisher("Syncfusion");

Check failure on line 123 in src/main/java/ar/com/nanotaboada/java/samples/spring/boot/models/BooksDataInitializer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "Syncfusion" 8 times.

See more on https://sonarcloud.io/project/issues?id=nanotaboada_java.samples.spring.boot&issues=AZrg95IqzhjEHvPrAzUJ&open=AZrg95IqzhjEHvPrAzUJ&pullRequest=231
book9781642002232.setPublished(LocalDate.of(2022, 5, 25));
book9781642002232.setPages(87);
book9781642002232.setDescription(
"""
The way a user might perceive and use data and the optimal way a computer \
system might store it are often very different. In this Database Design \
Succinctly®, learn how to model the user's information into data in a computer \
database system in such a way as to allow the system to produce useful results \
for the end user. Joseph D. Booth will cover how to design a database system to \
allow businesses to get better reporting and control over their information, as \
well as how to improve their data to make sure it is as accurate as possible.""");
book9781642002232.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/database-design-succinctly");
books.add(book9781642002232);
Book book9781642001174 = new Book();
book9781642001174.setIsbn("9781642001174");
book9781642001174.setTitle("SOLID Principles Succinctly");
book9781642001174.setAuthor("Gaurav Kumar Arora");
book9781642001174.setPublisher("Syncfusion");
book9781642001174.setPublished(LocalDate.of(2016, 10, 31));
book9781642001174.setPages(78);
book9781642001174.setDescription(
"""
There is always room for improving one's coding ability, and SOLID design \
principles offer one way to see marked improvements in final output. With SOLID \
Principles Succinctly®, author Gaurav Kumar Arora will instruct you in how to \
use SOLID principles to take your programming skills to the next level.""");
book9781642001174.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/solidprinciplessuccinctly");
books.add(book9781642001174);
Book book9781642001440 = new Book();
book9781642001440.setIsbn("9781642001440");
book9781642001440.setTitle("Java Succinctly Part 1");
book9781642001440.setAuthor("Christopher Rose");
book9781642001440.setPublisher("Syncfusion");
book9781642001440.setPublished(LocalDate.of(2017, 8, 29));
book9781642001440.setPages(125);
book9781642001440.setDescription(
"""
Java is a high-level, cross-platform, object-oriented programming language that \
allows applications to be written once and run on a multitude of different \
devices. Java applications are ubiquitous, and the language is consistently \
ranked as one of the most popular and dominant in the world. Christopher Rose's \
Java Succinctly® Part 1 describes the foundations of Java—from printing a line \
of text to the console, to inheritance hierarchies in object-oriented \
programming. The e-book covers practical aspects of programming, such as \
debugging and using an IDE, as well as the core mechanics of the language.""");
book9781642001440.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/java-succinctly-part-1");
books.add(book9781642001440);
Book book9781642001457 = new Book();
book9781642001457.setIsbn("9781642001457");
book9781642001457.setTitle("Java Succinctly Part 2");
book9781642001457.setAuthor("Christopher Rose");
book9781642001457.setPublisher("Syncfusion");
book9781642001457.setPublished(LocalDate.of(2017, 9, 5));
book9781642001457.setPages(134);
book9781642001457.setDescription(
"""
In this second e-book on Java, Christopher Rose takes readers through some of \
the more advanced features of the language. Java Succinctly® Part 2 explores \
powerful and practical features of Java, such as multithreading, building GUI \
applications, and 2-D graphics and game programming. Then learn techniques for \
using these mechanisms in coherent projects by building a calculator app and a \
simple game with the author.""");
book9781642001457.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/java-succinctly-part-2");
books.add(book9781642001457);
Book book9781642001495 = new Book();
book9781642001495.setIsbn("9781642001495");
book9781642001495.setTitle("Scala Succinctly");
book9781642001495.setAuthor("Chris Rose");
book9781642001495.setPublisher("Syncfusion");
book9781642001495.setPublished(LocalDate.of(2017, 10, 16));
book9781642001495.setPages(110);
book9781642001495.setDescription(
"""
Learning a new programming language can be a daunting task, but Scala \
Succinctly® makes it a simple matter. Author Chris Rose guides readers through \
the basics of Scala, from installation to syntax shorthand, so that they can \
get up and running quickly.""");
book9781642001495.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/scala-succinctly");
books.add(book9781642001495);
Book book9781642001242 = new Book();
book9781642001242.setIsbn("9781642001242");
book9781642001242.setTitle("SQL Queries Succinctly");
book9781642001242.setAuthor("Nick Harrison");
book9781642001242.setPublisher("Syncfusion");
book9781642001242.setPublished(LocalDate.of(2017, 2, 4));
book9781642001242.setPages(102);
book9781642001242.setDescription(
"""
SQL is the language of data, and therefore the intermediary language for those \
who straddle the line between technology and business. Every business \
application needs a database and SQL is the key to working with these databases. \
Nick Harrison's SQL Queries Succinctly® will show you how to craft queries in \
SQL, from basic CRUD statements and slicing and dicing the data, to applying \
filters and using aggregate functions to summarize the data. You will look at \
solving common problems, navigating hierarchical data, and exploring the data \
dictionary.""");
book9781642001242.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/sql-queries-succinctly");
books.add(book9781642001242);
Book book9781642001563 = new Book();
book9781642001563.setIsbn("9781642001563");
book9781642001563.setTitle("Docker Succinctly");
book9781642001563.setAuthor("Elton Stoneman");
book9781642001563.setPublisher("Syncfusion");
book9781642001563.setPublished(LocalDate.of(2018, 1, 16));
book9781642001563.setPages(98);
book9781642001563.setDescription(
"""
Containers have revolutionized software development, allowing developers to \
bundle their applications with everything they need, from the operating system \
up, into a single package. Docker is one of the most popular platforms for \
containers, allowing them to be hosted on-premises or on the cloud, and to run \
on Linux, Windows, and Mac machines. With Docker Succinctly® by Elton Stoneman, \
learn the basics of building Docker images, sharing them on the Docker Hub, \
orchestrating containers to deliver large applications, and much more.""");
book9781642001563.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/docker-succinctly");
books.add(book9781642001563);
Book book9781642001792 = new Book();
book9781642001792.setIsbn("9781642001792");
book9781642001792.setTitle("Kubernetes Succinctly");
book9781642001792.setAuthor("Rahul Rai, Tarun Pabbi");
book9781642001792.setPublisher("Syncfusion");
book9781642001792.setPublished(LocalDate.of(2019, 3, 1));
book9781642001792.setPages(121);
book9781642001792.setDescription(
"""
With excellent orchestration and routing capabilities, Kubernetes is an \
enterprise-grade platform for building microservices applications. Kubernetes is \
evolving as the de facto container management tool used by organizations and \
cloud vendors all over the world. Kubernetes Succinctly® by Rahul Rai and Tarun \
Pabbi is your guide to learning Kubernetes and leveraging its many capabilities \
for developing, validating, and maintaining your applications.""");
book9781642001792.setWebsite("https://www.syncfusion.com/succinctly-free-ebooks/kubernetes-succinctly");
books.add(book9781642001792);
Book book9781838820756 = new Book();
book9781838820756.setIsbn("9781838820756");
book9781838820756.setTitle("The Kubernetes Workshop");
book9781838820756
.setAuthor("Zachary Arnold, Sahil Dua, Wei Huang, Faisal Masood, Mélony Qin, Mohammed Abu Taleb");
book9781838820756.setPublisher("Packt");
book9781838820756.setPublished(LocalDate.of(2020, 9, 1));
book9781838820756.setPages(780);
book9781838820756.setDescription(
"""
Thanks to its extensive support for managing hundreds of containers that run \
cloud-native applications, Kubernetes is the most popular open source container \
orchestration platform that makes cluster management easy. This workshop adopts a \
practical approach to get you acquainted with the Kubernetes environment and its \
applications. Starting with an introduction to the fundamentals of Kubernetes, \
you'll install and set up your Kubernetes environment. You'll understand how to \
write YAML files and deploy your first simple web application container using \
Pod. You'll then assign human-friendly names to Pods, explore various Kubernetes \
entities and functions, and discover when to use them. As you work through the \
chapters, this Kubernetes book will show you how you can make full-scale use of \
Kubernetes by applying a variety of techniques for designing components and \
deploying clusters. You'll also get to grips with security policies for limiting \
access to certain functions inside the cluster. Toward the end of the book, \
you'll get a rundown of Kubernetes advanced features for building your own \
controller and upgrading to a Kubernetes cluster without downtime.""");
book9781838820756.setWebsite("https://www.packtpub.com/free-ebook/the-kubernetes-workshop/9781838820756");
books.add(book9781838820756);
return books;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ar.com.nanotaboada.java.samples.spring.boot.repositories;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import ar.com.nanotaboada.java.samples.spring.boot.models.Book;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -16,4 +19,14 @@ public interface BooksRepository extends CrudRepository<Book, String> {
// Non-default methods in interfaces are not shown in coverage reports
// https://www.jacoco.org/jacoco/trunk/doc/faq.html
Optional<Book> findByIsbn(String isbn);

/**
* Finds books whose description contains the given keyword (case-insensitive).
* Uses JPQL with CAST to handle CLOB description field.
*
* @param keyword the keyword to search for in the description
* @return a list of books matching the search criteria
*/
@Query("SELECT b FROM Book b WHERE LOWER(CAST(b.description AS string)) LIKE LOWER(CONCAT('%', :keyword, '%'))")
List<Book> findByDescriptionContainingIgnoreCase(@Param("keyword") String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public List<BookDTO> retrieveAll() {
.toList();
}

/*
* -------------------------------------------------------------------------
* Search
* -------------------------------------------------------------------------
*/

public List<BookDTO> searchByDescription(String keyword) {
return booksRepository.findByDescriptionContainingIgnoreCase(keyword)
.stream()
.map(this::mapFrom)
.toList();
}

/*
* -------------------------------------------------------------------------
* Update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ public static Book createOneValid() {
Book book = new Book();
book.setIsbn("9781484200773");
book.setTitle("Pro Git");
book.setSubtitle("Everything you neeed to know about Git");
book.setAuthor("Scott Chacon and Ben Straub");
book.setPublisher("lulu.com; First Edition");
book.setSubtitle("Everything You Need to Know About Git");
book.setAuthor("Scott Chacon, Ben Straub");
book.setPublisher("Apress");
book.setPublished(LocalDate.of(2014, 11, 18));
book.setPages(458);
book.setPages(456);
book.setDescription(
"""
Pro Git (Second Edition) is your fully-updated guide to Git and its \
usage in the modern world. Git has come a long way since it was first developed by \
Linus Torvalds for Linux kernel development. It has taken the open source world by \
storm since its inception in 2005, and this book teaches you how to use it like a \
pro.""");
Pro Git is your fully-updated guide to Git and its usage in the modern world. \
Git has come a long way since it was first developed by Linus Torvalds for Linux \
kernel development. It has taken the open source world by storm since its \
inception in 2005, and this book teaches you how to use it like a pro. Effective \
and well-implemented version control is a necessity for successful web projects, \
whether large or small. This book will help you master the fundamentals of Git, \
including branching and merging, creating and managing repositories, customizing \
your workflow, and using Git in a team environment. You'll also learn advanced \
topics such as Git internals, debugging, automation, and customization.""");
book.setWebsite("https://git-scm.com/book/en/v2");
return book;
}
Expand Down
Loading