Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Apply fixes from IDE recommendations (#13)
Browse files Browse the repository at this point in the history
* Remove unused code

* Add minor improvements

* Suppress noisy IDE warnings
  • Loading branch information
cmenon12 authored Apr 4, 2024
1 parent d65b27e commit e1907d2
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public String home(Model model) {
return "shop";
}

@SuppressWarnings("OptionalGetWithoutIsPresent")
@PostMapping(value = "/order")
public String order(@AuthenticationPrincipal UserDetails userDetails,
RedirectAttributes redirectAttrs,
Expand Down Expand Up @@ -100,7 +101,6 @@ public String order(@AuthenticationPrincipal UserDetails userDetails,
}
redirectAttrs.addFlashAttribute("resultDanger", resultDanger.toString());
}
return "redirect:/";

} else {
// create order
Expand All @@ -115,10 +115,11 @@ public String order(@AuthenticationPrincipal UserDetails userDetails,
} else {
redirectAttrs.addFlashAttribute("resultDanger", result);
}
return "redirect:/";
}
return "redirect:/";
}

@SuppressWarnings("OptionalGetWithoutIsPresent")
@GetMapping(value = "/orders")
public String orders(@AuthenticationPrincipal UserDetails userDetails, Model model) {
List<Order> allOrders = orderService.getAllByUser(userService.get(userDetails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class UserController {
@Autowired
PasswordEncoder passwordEncoder;

SecurityContextLogoutHandler logoutHandler = new SecurityContextLogoutHandler();
final SecurityContextLogoutHandler logoutHandler = new SecurityContextLogoutHandler();

@GetMapping(value = "/login")
public String login(@AuthenticationPrincipal UserDetails userDetails, Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
public interface ProductCategoryRepository extends JpaRepository<ProductCategory, Long> {

@Query("select c from product_category c where c.name = :name")
public Optional<ProductCategory> findByName(String name);
Optional<ProductCategory> findByName(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {

@SuppressWarnings("NullableProblems")
@Query("select p from Product p where p.isDeleted = false")
List<Product> findAll();

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/sportyshoes/repository/UserRepository.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.sportyshoes.repository;

import com.sportyshoes.entity.User;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<User, String> {

@Query("select u from users u where u.isAdmin = true")
List<User> getAdmin();

}
9 changes: 0 additions & 9 deletions src/main/java/com/sportyshoes/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ public Optional<User> getByEmail(String email) {
return userRepository.findById(email);
}

public Optional<User> getAdmin() {
List<User> admins = userRepository.getAdmin();
if (admins.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(admins.get(0));
}
}

public Optional<User> get(UserDetails userDetails) {
return getByEmail(userDetails.getUsername());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/admin_product_categories.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head
th:replace="~{fragments/base :: head('Sporty Shoes Shop - Admin - Product Categories')}"></head>
<body class="text-bg-light">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>
<!--suppress HtmlRequiredTitleElement -->
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<head
th:replace="~{fragments/base :: head('Sporty Shoes Shop - Admin - ' + ${category.getId() != null ? 'Edit' : 'Create'} + ' Product Category')}"></head>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/admin_products.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head th:replace="~{fragments/base :: head('Sporty Shoes Shop - Admin - Products')}"></head>
<body class="text-bg-light">
<header th:replace="~{fragments/base :: header('Sporty Shoes Shop - Admin - Products')}"></header>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/templates/admin_products_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!DOCTYPE html>
<!--suppress HtmlUnknownTag -->
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head
th:replace="~{fragments/base :: head('Sporty Shoes Shop - Admin - ' + ${product.getId() != null ? 'Edit' : 'Create'} + ' Product')}"></head>
<body class="text-bg-light">
Expand Down Expand Up @@ -48,10 +50,12 @@
<div class="row m-3">
<div class="col">
<div class="form-floating">
<!--suppress XmlDuplicatedId -->
<select th:if="${allCategories.isEmpty()}" class="form-select" id="productCategory"
aria-label="Product Category" disabled>
<option>No categories available.</option>
</select>
<!--suppress XmlDuplicatedId -->
<select th:unless="${allCategories.isEmpty()}" name="categoryId"
class="form-select" id="productCategory" aria-label="Product Category">
<option value="none">None</option>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head th:replace="~{fragments/base :: head('Sporty Shoes Shop - Login')}"></head>
<body class="text-bg-light">
<!--/*@thymesVar id="resultDanger" type="java.lang.String"*/-->
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/orders.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head
th:replace="~{fragments/base :: head('Sporty Shoes Shop - ' + ${showUser != null ? 'Admin - ' : ''} + 'Orders')}"></head>
<body class="text-bg-light">
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/register.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head th:replace="~{fragments/base :: head('Sporty Shoes Shop - Register')}"></head>
<body class="text-bg-light">

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/shop.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en-GB">
<!--suppress HtmlRequiredTitleElement -->
<head th:replace="~{fragments/base :: head('Sporty Shoes Shop')}"></head>
<body class="text-bg-light">
<header th:replace="~{fragments/base :: header('Sporty Shoes Shop')}"></header>
Expand Down

0 comments on commit e1907d2

Please sign in to comment.