diff --git a/.idea/biome.xml b/.idea/biome.xml index 8fa01ec..bf802af 100644 --- a/.idea/biome.xml +++ b/.idea/biome.xml @@ -1,9 +1,6 @@ - \ No newline at end of file diff --git a/src/main/java/codes/yam/contacts/Contact.java b/src/main/java/codes/yam/contacts/Contact.java index 6b46004..157c031 100644 --- a/src/main/java/codes/yam/contacts/Contact.java +++ b/src/main/java/codes/yam/contacts/Contact.java @@ -18,16 +18,11 @@ public class Contact { private String slug; - @NotBlank - private String first; + @NotBlank private String first; - @NotBlank - private String last; + @NotBlank private String last; - @NotBlank - @Email - private String email; + @NotBlank @Email private String email; - @NotBlank - private String phone; + @NotBlank private String phone; } diff --git a/src/main/java/codes/yam/contacts/ContactController.java b/src/main/java/codes/yam/contacts/ContactController.java index d1a94e9..5415d7b 100644 --- a/src/main/java/codes/yam/contacts/ContactController.java +++ b/src/main/java/codes/yam/contacts/ContactController.java @@ -72,8 +72,12 @@ public ResponseEntity deleteContact(@PathVariable String slug) { } @DeleteMapping - public ResponseEntity deleteManyContacts(@RequestParam List slugs) { - contactService.deleteMany(slugs); + public ResponseEntity deleteManyContacts( + @RequestParam(name = "selected_contact_slugs", required = false) + List selectedContactSlugs) { + if (selectedContactSlugs != null && !selectedContactSlugs.isEmpty()) { + contactService.deleteMany(selectedContactSlugs); + } return ResponseEntity.status(HttpStatus.SEE_OTHER).location(URI.create("/contacts")).build(); } diff --git a/src/main/java/codes/yam/contacts/ContactRepository.java b/src/main/java/codes/yam/contacts/ContactRepository.java index 89809da..a97cc73 100644 --- a/src/main/java/codes/yam/contacts/ContactRepository.java +++ b/src/main/java/codes/yam/contacts/ContactRepository.java @@ -15,9 +15,10 @@ public interface ContactRepository extends JpaRepository { List findAllBySlugIn(Collection slugs); - @Query("SELECT c FROM Contact c WHERE " + - "LOWER(c.first) LIKE LOWER(CONCAT('%', :q, '%')) OR " + - "LOWER(c.last) LIKE LOWER(CONCAT('%', :q, '%')) OR " + - "LOWER(c.email) LIKE LOWER(CONCAT('%', :q, '%'))") + @Query( + "SELECT c FROM Contact c WHERE " + + "LOWER(c.first) LIKE LOWER(CONCAT('%', :q, '%')) OR " + + "LOWER(c.last) LIKE LOWER(CONCAT('%', :q, '%')) OR " + + "LOWER(c.email) LIKE LOWER(CONCAT('%', :q, '%'))") List search(@Param("q") String q); } diff --git a/src/main/java/codes/yam/contacts/WebConfig.java b/src/main/java/codes/yam/contacts/WebConfig.java index 05fa7e6..0716be2 100644 --- a/src/main/java/codes/yam/contacts/WebConfig.java +++ b/src/main/java/codes/yam/contacts/WebConfig.java @@ -18,10 +18,10 @@ public void addViewControllers(ViewControllerRegistry registry) { @Bean public FilterRegistrationBean trailingSlashFilter() { - UrlHandlerFilter filter = UrlHandlerFilter - .trailingSlashHandler("/**") - .redirect(HttpStatus.PERMANENT_REDIRECT) - .build(); + UrlHandlerFilter filter = + UrlHandlerFilter.trailingSlashHandler("/**") + .redirect(HttpStatus.PERMANENT_REDIRECT) + .build(); return new FilterRegistrationBean<>(filter); } } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index c4792ce..9ba7332 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,3 +1,21 @@ -INSERT INTO contact (id, slug, first, last, email, phone) VALUES -('550e8400-e29b-41d4-a716-446655440000', 'john-doe', 'John', 'Doe', 'john@example.com', '555-1234'), -('550e8400-e29b-41d4-a716-446655440001', 'jane-doe', 'Jane', 'Doe', 'jane@example.com', '555-5678'); +INSERT INTO contact (id, slug, first, last, email, phone) +VALUES ('550e8400-e29b-41d4-a716-446655440000', 'john-doe', 'John', 'Doe', 'john@example.com', '555-1234'), + ('550e8400-e29b-41d4-a716-446655440001', 'jane-doe', 'Jane', 'Doe', 'jane@example.com', '555-5678'), + ('550e8400-e29b-41d4-a716-446655440002', 'alice-smith', 'Alice', 'Smith', 'alice@example.com', '555-2001'), + ('550e8400-e29b-41d4-a716-446655440003', 'bob-johnson', 'Bob', 'Johnson', 'bob@example.com', '555-2002'), + ('550e8400-e29b-41d4-a716-446655440004', 'carol-williams', 'Carol', 'Williams', 'carol@example.com', '555-2003'), + ('550e8400-e29b-41d4-a716-446655440005', 'dave-brown', 'Dave', 'Brown', 'dave@example.com', '555-2004'), + ('550e8400-e29b-41d4-a716-446655440006', 'eve-jones', 'Eve', 'Jones', 'eve@example.com', '555-2005'), + ('550e8400-e29b-41d4-a716-446655440007', 'frank-garcia', 'Frank', 'Garcia', 'frank@example.com', '555-2006'), + ('550e8400-e29b-41d4-a716-446655440008', 'grace-martinez', 'Grace', 'Martinez', 'grace@example.com', '555-2007'), + ('550e8400-e29b-41d4-a716-446655440009', 'henry-davis', 'Henry', 'Davis', 'henry@example.com', '555-2008'), + ('550e8400-e29b-41d4-a716-44665544000a', 'iris-miller', 'Iris', 'Miller', 'iris@example.com', '555-2009'), + ('550e8400-e29b-41d4-a716-44665544000b', 'jack-wilson', 'Jack', 'Wilson', 'jack@example.com', '555-2010'), + ('550e8400-e29b-41d4-a716-44665544000c', 'karen-moore', 'Karen', 'Moore', 'karen@example.com', '555-2011'), + ('550e8400-e29b-41d4-a716-44665544000d', 'leo-taylor', 'Leo', 'Taylor', 'leo@example.com', '555-2012'), + ('550e8400-e29b-41d4-a716-44665544000e', 'mia-anderson', 'Mia', 'Anderson', 'mia@example.com', '555-2013'), + ('550e8400-e29b-41d4-a716-44665544000f', 'nick-thomas', 'Nick', 'Thomas', 'nick@example.com', '555-2014'), + ('550e8400-e29b-41d4-a716-446655440010', 'olivia-jackson', 'Olivia', 'Jackson', 'olivia@example.com', '555-2015'), + ('550e8400-e29b-41d4-a716-446655440011', 'paul-white', 'Paul', 'White', 'paul@example.com', '555-2016'), + ('550e8400-e29b-41d4-a716-446655440012', 'quinn-harris', 'Quinn', 'Harris', 'quinn@example.com', '555-2017'), + ('550e8400-e29b-41d4-a716-446655440013', 'rachel-clark', 'Rachel', 'Clark', 'rachel@example.com', '555-2018'); diff --git a/src/main/resources/templates/contacts/edit.html b/src/main/resources/templates/contacts/edit.html index 43e555e..6db3851 100644 --- a/src/main/resources/templates/contacts/edit.html +++ b/src/main/resources/templates/contacts/edit.html @@ -3,26 +3,26 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"> - Edit Contact + Edit Contact
-

Edit Contact

-
- - -
- -

- Back -

+

Edit Contact

+
+ + +
+ +

+ Back +

diff --git a/src/main/resources/templates/contacts/list.html b/src/main/resources/templates/contacts/list.html index 099c4ff..9678d03 100644 --- a/src/main/resources/templates/contacts/list.html +++ b/src/main/resources/templates/contacts/list.html @@ -1,51 +1,52 @@ - +
-
- - - -
+
+ + + +
-

Results for "":

+

Results for "":

-

No contacts found.

- - - - - - - - - - - - - - - - - - - +

No contacts found.

+ +
FirstLastPhoneEmail
- Edit - View -
+ + + + + + + + + + +
FirstLastPhoneEmail
-

- Add New Contact -

+ + +

+ Add New Contact + +

\ No newline at end of file diff --git a/src/main/resources/templates/contacts/new.html b/src/main/resources/templates/contacts/new.html index 5a14452..ec8c6d6 100644 --- a/src/main/resources/templates/contacts/new.html +++ b/src/main/resources/templates/contacts/new.html @@ -1,20 +1,20 @@ + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + xmlns:th="http://www.thymeleaf.org"> - New Contact + New Contact
-

New Contact

-
- - -
-

- Back -

+

New Contact

+
+ + +
+

+ Back +

diff --git a/src/main/resources/templates/contacts/view.html b/src/main/resources/templates/contacts/view.html index cc7ff2e..dfc22d5 100644 --- a/src/main/resources/templates/contacts/view.html +++ b/src/main/resources/templates/contacts/view.html @@ -1,22 +1,22 @@ - + - View Contact + View Contact
-

-
-

Phone:

-

Email:

-
-

- Back - Edit -

+

+
+

Phone:

+

Email:

+
+

+ Back + Edit +

diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index 8ffeacd..4e23ca8 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -1,15 +1,14 @@ - - Error + Error
-

Something went wrong

-

An unexpected error occurred. Please try again later.

- Back to contacts +

Something went wrong

+

An unexpected error occurred. Please try again later.

+ Back to contacts
diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html index 82fe027..c3b883e 100644 --- a/src/main/resources/templates/error/404.html +++ b/src/main/resources/templates/error/404.html @@ -2,13 +2,13 @@ - Not Found + Not Found
-

Page Not Found

-

The page you were looking for doesn't exist.

- Back to contacts +

Page Not Found

+

The page you were looking for doesn't exist.

+ Back to contacts
\ No newline at end of file diff --git a/src/main/resources/templates/fragments/contact-fields.html b/src/main/resources/templates/fragments/contact-fields.html index 7fee8be..5c5ae62 100644 --- a/src/main/resources/templates/fragments/contact-fields.html +++ b/src/main/resources/templates/fragments/contact-fields.html @@ -4,40 +4,40 @@
- Contact Values + Contact Values +
+ +
- - -
- -
+
+
+
+ +
- - -
- -
+
+
+
+ +
- - -
- -
+
+
+
+ +
- - -
- -
+
+
diff --git a/src/main/resources/templates/fragments/contact-list-rows.html b/src/main/resources/templates/fragments/contact-list-rows.html new file mode 100644 index 0000000..bd7b8e9 --- /dev/null +++ b/src/main/resources/templates/fragments/contact-list-rows.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + Edit + View + Delete + + + + + diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html index c1b4ed7..1b4e4ad 100644 --- a/src/main/resources/templates/layout.html +++ b/src/main/resources/templates/layout.html @@ -1,26 +1,25 @@ + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + xmlns:th="http://www.thymeleaf.org"> - - - - Contacts - - + + + + Contacts +
-
-

- - contact.app - - A Demo Contacts Application -

-
-
+
+

+ + contact.app + + A Demo Contacts Application +

+
+
diff --git a/src/test/java/codes/yam/contacts/ContactsApplicationTests.java b/src/test/java/codes/yam/contacts/ContactsApplicationTests.java index fdbbe2f..d1bf14c 100644 --- a/src/test/java/codes/yam/contacts/ContactsApplicationTests.java +++ b/src/test/java/codes/yam/contacts/ContactsApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class ContactsApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} }