Cleanup Code

This commit is contained in:
Tim
2025-05-08 14:55:40 +02:00
parent 903a200dcf
commit 854f603455
12 changed files with 32 additions and 17 deletions

View File

@@ -5,10 +5,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class WebshopApplication { public class WebshopApplication {
private static final String BASE_PORT = "8085"; private static final String BASE_PORT = "8085";
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("server.port", BASE_PORT); System.setProperty("server.port", BASE_PORT);
SpringApplication.run(WebshopApplication.class, args); SpringApplication.run(WebshopApplication.class, args);
} }
} }

View File

@@ -12,8 +12,9 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static de.htwsaar.webshop.config.ControllerPathConfig.*; import static de.htwsaar.webshop.config.ControllerPathConfig.ARTICLE_BASE;
import static de.htwsaar.webshop.config.ParameterConfig.*; import static de.htwsaar.webshop.config.ControllerPathConfig.ARTICLE_GET_ALL;
import static de.htwsaar.webshop.config.ParameterConfig.PARAM_UUID;
import static de.htwsaar.webshop.util.LoggerUtil.logRequest; import static de.htwsaar.webshop.util.LoggerUtil.logRequest;
@RestController @RestController
@@ -41,7 +42,7 @@ public class ArticleController {
@RequestMapping(path = ARTICLE_BASE, method = RequestMethod.POST, produces = "application/json") @RequestMapping(path = ARTICLE_BASE, method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<Boolean> add(HttpServletRequest request, public ResponseEntity<Boolean> add(HttpServletRequest request,
@RequestBody Article article) { @RequestBody Article article) {
logRequest(request); logRequest(request);
if (article.getPrice100() < 0 || article.getStock() < 0 || if (article.getPrice100() < 0 || article.getStock() < 0 ||
article.getDiscount100() > 100 || article.getDiscount100() < 0) { article.getDiscount100() > 100 || article.getDiscount100() < 0) {

View File

@@ -12,8 +12,10 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import static de.htwsaar.webshop.config.ControllerPathConfig.*; import static de.htwsaar.webshop.config.ControllerPathConfig.IMAGE_BASE;
import static de.htwsaar.webshop.config.ParameterConfig.*; import static de.htwsaar.webshop.config.ControllerPathConfig.IMAGE_GET_ALL;
import static de.htwsaar.webshop.config.ParameterConfig.PARAM_ARTICLE_ID;
import static de.htwsaar.webshop.config.ParameterConfig.PARAM_IMAGE_ID;
import static de.htwsaar.webshop.util.LoggerUtil.logRequest; import static de.htwsaar.webshop.util.LoggerUtil.logRequest;
@RestController @RestController

View File

@@ -12,6 +12,8 @@ import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public interface ArticleRepository extends JpaRepository<Article, Long> { public interface ArticleRepository extends JpaRepository<Article, Long> {
Optional<Article> findArticleById(@NonNull Long id); Optional<Article> findArticleById(@NonNull Long id);
Optional<Article> findArticleByName(@NonNull String Name); Optional<Article> findArticleByName(@NonNull String Name);
Optional<Article> findArticleByUuid(@NonNull UUID uuid); Optional<Article> findArticleByUuid(@NonNull UUID uuid);
} }

View File

@@ -11,6 +11,8 @@ import java.util.List;
@Repository @Repository
public interface ImageRepository extends JpaRepository<Image, Long> { public interface ImageRepository extends JpaRepository<Image, Long> {
List<Image> findAllByArticleId(@NonNull Long articleId); List<Image> findAllByArticleId(@NonNull Long articleId);
Image findImageByArticleId(@NotNull Long articleId); Image findImageByArticleId(@NotNull Long articleId);
Image findImageById(Long id); Image findImageById(Long id);
} }

View File

@@ -3,7 +3,10 @@ package de.htwsaar.webshop.repository.entities;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import lombok.*; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.UUID; import java.util.UUID;

View File

@@ -6,7 +6,6 @@ import lombok.*;
import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDelete;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
@Entity @Entity
@Table(name = "OrderItems") @Table(name = "OrderItems")

View File

@@ -2,8 +2,8 @@ package de.htwsaar.webshop.repository.entities;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Max;
import lombok.AllArgsConstructor;
import jakarta.validation.constraints.PositiveOrZero; import jakarta.validation.constraints.PositiveOrZero;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;

View File

@@ -9,12 +9,19 @@ import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public interface ArticleService { public interface ArticleService {
List<Article> findAll(); List<Article> findAll();
Article findByUUID(UUID uuid); Article findByUUID(UUID uuid);
Article findByTitle(String title); Article findByTitle(String title);
Article findById(Long articleId); Article findById(Long articleId);
void delete(Long id); void delete(Long id);
Article save(Article article); Article save(Article article);
double getRating(Long id); double getRating(Long id);
double getRating(UUID uuid); double getRating(UUID uuid);
ArticleModel from(Article article); ArticleModel from(Article article);

View File

@@ -10,7 +10,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -21,7 +20,7 @@ public class ArticleServiceImpl implements ArticleService {
private final ReviewRepository reviewRepository; private final ReviewRepository reviewRepository;
@Autowired @Autowired
public ArticleServiceImpl(ArticleRepository articleRepository, ReviewRepository reviewRepository, ArticleService articleService) { public ArticleServiceImpl(ArticleRepository articleRepository, ReviewRepository reviewRepository) {
this.articleRepository = articleRepository; this.articleRepository = articleRepository;
this.reviewRepository = reviewRepository; this.reviewRepository = reviewRepository;
} }

View File

@@ -46,7 +46,7 @@ public class ImageServiceImpl implements ImageService {
@Override @Override
public ImageModel from(Image image) { public ImageModel from(Image image) {
return new ImageModel(articleService.findById(image.getArticleId()).getUuid(),image.getUri()); return new ImageModel(articleService.findById(image.getArticleId()).getUuid(), image.getUri());
} }
@Override @Override

View File

@@ -22,8 +22,8 @@ public class ValidatorServiceImpl implements ValidatorService {
* Jakarta Validator * Jakarta Validator
* *
* @param validatable any Validatable * @param validatable any Validatable
* @param <T> any Validatable
* @return whether the Object is Invalid * @return whether the Object is Invalid
* @param <T> any Validatable
*/ */
@Override @Override
public <T> boolean isInvalid(T validatable) { public <T> boolean isInvalid(T validatable) {