Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106-v23-03
backend
Commits
3f88bbe2
Commit
3f88bbe2
authored
2 years ago
by
Birk Øvstetun Narvhus
Browse files
Options
Downloads
Patches
Plain Diff
added categories to products before saving
parent
96d1dc92
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java
+10
-2
10 additions, 2 deletions
...6/v233/SmartMat/controller/product/ProductController.java
with
10 additions
and
2 deletions
src/main/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductController.java
+
10
−
2
View file @
3f88bbe2
...
@@ -2,10 +2,11 @@ package ntnu.idatt2016.v233.SmartMat.controller.product;
...
@@ -2,10 +2,11 @@ package ntnu.idatt2016.v233.SmartMat.controller.product;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest
;
import
ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Category
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Product
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Product
;
import
ntnu.idatt2016.v233.SmartMat.service.product.CategoryService
;
import
ntnu.idatt2016.v233.SmartMat.service.product.ProductService
;
import
ntnu.idatt2016.v233.SmartMat.service.product.ProductService
;
import
ntnu.idatt2016.v233.SmartMat.util.CategoryUtil
;
import
ntnu.idatt2016.v233.SmartMat.util.CategoryUtil
;
import
ntnu.idatt2016.v233.SmartMat.util.ProductUtil
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -26,6 +27,8 @@ public class ProductController {
...
@@ -26,6 +27,8 @@ public class ProductController {
private
final
ProductService
productService
;
private
final
ProductService
productService
;
private
final
CategoryService
categoryService
;
/**
/**
* Creates a product if it does not already exist.
* Creates a product if it does not already exist.
* @param productRequest The product to be registered.
* @param productRequest The product to be registered.
...
@@ -40,10 +43,15 @@ public class ProductController {
...
@@ -40,10 +43,15 @@ public class ProductController {
.
url
(
productRequest
.
image
())
.
url
(
productRequest
.
image
())
.
build
();
.
build
();
Category
category
=
categoryService
.
getCategoryByName
(
CategoryUtil
.
defineCategory
(
product
.
getName
(),
product
.
getDescription
()))
.
orElse
(
null
);
if
(
category
==
null
)
return
ResponseEntity
.
badRequest
().
build
();
product
.
setCategory
(
category
);
CategoryUtil
.
defineCategory
(
product
.
getName
(),
product
.
getDescription
());
if
(
productService
.
getProductById
(
productRequest
.
ean
()).
isPresent
())
if
(
productService
.
getProductById
(
productRequest
.
ean
()).
isPresent
())
return
ResponseEntity
.
status
(
409
).
build
();
return
ResponseEntity
.
status
(
409
).
build
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment