added quantityChange validation, product validation, checking existing object in db, throwing exeption

This commit is contained in:
prgres 2019-01-22 02:42:50 +01:00
parent 0d4b2dcf75
commit c2badfe536
13 changed files with 468 additions and 238 deletions

View File

@ -9,7 +9,7 @@
<module name="sysmag" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<bytecodeTargetLevel target="11">
<module name="sysmag" target="1.8" />
</bytecodeTargetLevel>
</component>

View File

@ -2,7 +2,20 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="2dc093a7-8382-4e31-b457-ce6c9fd10d13" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/exception/ProductNotFoundException.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/ProductValidator.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/QuantityChangeValidator.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/application.properties" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/target/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -26,39 +39,30 @@
<select />
</component>
<component name="FileEditorManager">
<splitter split-orientation="horizontal" split-proportion="0.5">
<split-first>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="19" column="27" selection-start-line="19" selection-start-column="27" selection-end-line="19" selection-end-column="27" />
<state relative-caret-position="-75">
<caret line="22" column="18" selection-start-line="22" selection-start-column="18" selection-end-line="22" selection-end-column="18" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1394#1395#0" expanded="true" />
<element signature="e#1489#1490#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="405">
<caret line="41" column="19" selection-start-line="41" selection-start-column="19" selection-end-line="41" selection-end-column="19" />
<state relative-caret-position="-70">
<caret line="23" column="4" selection-start-line="23" selection-start-column="4" selection-end-line="23" selection-end-column="4" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1935#1936#0" expanded="true" />
<element signature="e#1982#1983#0" expanded="true" />
<element signature="e#2038#2039#0" expanded="true" />
<element signature="e#2086#2087#0" expanded="true" />
</folding>
</state>
</provider>
@ -67,8 +71,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="18" column="32" selection-start-line="18" selection-start-column="32" selection-end-line="18" selection-end-column="32" />
<state relative-caret-position="240">
<caret line="16" column="28" selection-start-line="16" selection-start-column="28" selection-end-line="16" selection-end-column="28" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -77,51 +81,39 @@
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" column="1" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="17" column="24" selection-start-line="17" selection-start-column="24" selection-end-line="17" selection-end-column="24" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/HomeController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="165">
<caret line="11" column="13" selection-start-line="11" selection-start-column="13" selection-end-line="11" selection-end-column="13" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/ProductValidator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="7" selection-start-line="8" selection-start-column="7" selection-end-line="8" selection-end-column="7" />
<caret line="10" column="10" selection-start-line="10" selection-start-column="10" selection-end-line="10" selection-end-column="10" />
</state>
</provider>
</entry>
</file>
</leaf>
</split-first>
<split-second>
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/ProductValidator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#438#439#0" expanded="true" />
<element signature="e#496#497#0" expanded="true" />
<element signature="e#234#235#0" expanded="true" />
<element signature="e#289#290#0" expanded="true" />
<element signature="e#351#352#0" expanded="true" />
<element signature="e#410#411#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</split-second>
</splitter>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
@ -131,6 +123,11 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>asc</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="ROOT_SYNC" value="SYNC" />
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@ -144,17 +141,20 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/HomeController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/MainController.java" />
<option value="$PROJECT_DIR$/src/main/resources/application.properties" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/exception/ProductNotFoundException.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/QuantityChangeValidator.java" />
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/HomeController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java" />
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/main/resources/application.properties" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/MainController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/ProductValidator.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java" />
<option value="$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java" />
</list>
</option>
</component>
@ -165,7 +165,24 @@
</MavenImportingSettings>
</option>
</component>
<component name="ProjectFrameBounds">
<component name="MavenProjectNavigator">
<treeState>
<expand>
<path>
<item name="" type="16c1761:MavenProjectsStructure$RootNode" />
<item name="sysmag" type="9519ce18:MavenProjectsStructure$ProjectNode" />
</path>
<path>
<item name="" type="16c1761:MavenProjectsStructure$RootNode" />
<item name="sysmag" type="9519ce18:MavenProjectsStructure$ProjectNode" />
<item name="Lifecycle" type="58874e2:MavenProjectsStructure$LifecycleNode" />
</path>
</expand>
<select />
</treeState>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="840" />
<option name="y" value="23" />
<option name="width" value="840" />
<option name="height" value="1027" />
@ -258,6 +275,15 @@
<item name="sysmag" type="462c0819:PsiDirectoryNode" />
<item name="service" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="sysmag" type="b2602c69:ProjectViewProjectNode" />
<item name="sysmag" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="sysmag" type="462c0819:PsiDirectoryNode" />
<item name="validator" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="sysmag" type="b2602c69:ProjectViewProjectNode" />
<item name="sysmag" type="462c0819:PsiDirectoryNode" />
@ -284,7 +310,7 @@
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="restartRequiresConfirmation" value="false" />
<property name="settings.editor.selected.configurable" value="project.propVCSSupport.Mappings" />
<property name="settings.editor.selected.configurable" value="reference.projectsettings.compiler.javacompiler" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -353,33 +379,34 @@
<option name="presentableId" value="Default" />
<updated>1547322958782</updated>
<workItem from="1547322960420" duration="21872000" />
<workItem from="1547401179909" duration="588000" />
<workItem from="1547401179909" duration="28165000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="22460000" />
<option name="totallyTimeSpent" value="50037000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="840" height="1027" extended-state="0" />
<frame x="0" y="23" width="1680" height="1027" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.36842105" />
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.49810606" visible="true" weight="0.17948718" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Designer" order="2" />
<window_info id="UI Designer" order="3" />
<window_info id="Favorites" order="4" side_tool="true" />
<window_info id="Web" order="5" side_tool="true" />
<window_info id="Web" order="5" sideWeight="0.50189394" side_tool="true" weight="0.36842105" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32941177" />
<window_info anchor="bottom" id="Find" order="1" sideWeight="0.498779" weight="0.32941177" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.498779" weight="0.3315508" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Spring" order="7" sideWeight="0.4993895" weight="0.32941177" />
<window_info active="true" anchor="bottom" id="Terminal" order="8" sideWeight="0.4993895" visible="true" weight="0.43529412" />
<window_info anchor="bottom" id="Terminal" order="8" sideWeight="0.498779" weight="0.20855615" />
<window_info anchor="bottom" id="Docker" order="9" show_stripe_button="false" />
<window_info anchor="bottom" id="Event Log" order="10" sideWeight="0.50061053" side_tool="true" weight="0.32941177" />
<window_info anchor="bottom" id="Event Log" order="10" sideWeight="0.501221" side_tool="true" weight="0.32941177" />
<window_info anchor="bottom" id="Messages" order="11" weight="0.32941177" />
<window_info anchor="bottom" id="Java Enterprise" order="12" />
<window_info anchor="bottom" id="Database Changes" order="13" show_stripe_button="false" />
@ -388,7 +415,7 @@
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Maven" order="3" />
<window_info anchor="right" id="Maven" order="3" weight="0.32967034" />
<window_info anchor="right" id="Palette" order="4" />
<window_info anchor="right" id="Database" order="5" weight="0.32967034" />
<window_info anchor="right" id="Palette&#9;" order="6" />
@ -452,78 +479,31 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-commons/2.1.4.RELEASE/spring-data-commons-2.1.4.RELEASE.jar!/org/springframework/data/repository/PagingAndSortingRepository.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="310">
<caret line="43" selection-start-line="43" selection-end-line="44" />
<state relative-caret-position="180">
<caret line="17" lean-forward="true" selection-start-line="17" selection-end-line="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/application.properties">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
<state relative-caret-position="240">
<caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="19" column="27" selection-start-line="19" selection-start-column="27" selection-end-line="19" selection-end-column="27" />
<folding>
<element signature="imports" expanded="true" />
</folding>
<state relative-caret-position="150">
<caret line="10" selection-start-line="10" selection-end-line="10" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/exception/ProductNotFoundException.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="405">
<caret line="41" column="19" selection-start-line="41" selection-start-column="19" selection-end-line="41" selection-end-column="19" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1935#1936#0" expanded="true" />
<element signature="e#1982#1983#0" expanded="true" />
<element signature="e#2038#2039#0" expanded="true" />
<element signature="e#2086#2087#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="18" column="32" selection-start-line="18" selection-start-column="32" selection-end-line="18" selection-end-column="32" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" column="1" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="17" column="24" selection-start-line="17" selection-start-column="24" selection-end-line="17" selection-end-column="24" />
<folding>
<element signature="imports" expanded="true" />
</folding>
<state relative-caret-position="120">
<caret line="8" lean-forward="true" selection-start-line="8" selection-end-line="8" />
</state>
</provider>
</entry>
@ -537,10 +517,105 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/IdDto.java">
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/dto/QuantityChange.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="7" selection-start-line="8" selection-start-column="7" selection-end-line="8" selection-end-column="7" />
<state relative-caret-position="150">
<caret line="10" column="18" selection-start-line="10" selection-start-column="18" selection-end-line="10" selection-end-column="18" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-commons/2.1.4.RELEASE/spring-data-commons-2.1.4.RELEASE.jar!/org/springframework/data/repository/CrudRepository.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="15" column="16" selection-start-line="15" selection-start-column="16" selection-end-line="15" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="603">
<caret line="51" selection-start-line="51" selection-end-line="51" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/repository/ProductRepository.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="21" lean-forward="true" selection-start-line="21" selection-end-line="21" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductService.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240">
<caret line="16" column="28" selection-start-line="16" selection-start-column="28" selection-end-line="16" selection-end-column="28" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/QuantityChangeValidator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" column="13" selection-start-line="13" selection-start-column="13" selection-end-line="13" selection-end-column="13" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-70">
<caret line="23" column="4" selection-start-line="23" selection-start-column="4" selection-end-line="23" selection-end-column="4" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-75">
<caret line="22" column="18" selection-start-line="22" selection-start-column="18" selection-end-line="22" selection-end-column="18" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1394#1395#0" expanded="true" />
<element signature="e#1489#1490#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/model/Product.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="15" column="7" lean-forward="true" selection-start-line="15" selection-start-column="7" selection-end-line="15" selection-end-column="7" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/dino/scrum/sysmag/validator/ProductValidator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" column="4" selection-start-line="13" selection-start-column="4" selection-end-line="13" selection-end-column="4" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#438#439#0" expanded="true" />
<element signature="e#496#497#0" expanded="true" />
<element signature="e#234#235#0" expanded="true" />
<element signature="e#289#290#0" expanded="true" />
<element signature="e#351#352#0" expanded="true" />
<element signature="e#410#411#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

View File

@ -49,6 +49,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--<release>10</release>-->
</configuration>
</plugin>
</plugins>
</build>

View File

@ -3,12 +3,15 @@ package com.dino.scrum.sysmag.controller;
import com.dino.scrum.sysmag.model.Product;
import com.dino.scrum.sysmag.model.dto.IdDto;
import com.dino.scrum.sysmag.model.dto.QuantityChange;
import com.dino.scrum.sysmag.service.ProductService;
import com.dino.scrum.sysmag.service.ProductServiceImpl;
import com.dino.scrum.sysmag.validator.QuantityChangeValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import javax.validation.Valid;
import java.util.Collections;
import java.util.Map;
@ -16,53 +19,70 @@ import java.util.Map;
* Created by prgres on 2019-01-12.
*/
@Controller
@RestController
@RequestMapping(value = "/api")
public class ProductController {
private final ProductServiceImpl productService;
private final
ProductServiceImpl productService;
private final
QuantityChangeValidator quantityChangeValidator;
@Autowired
public ProductController(ProductServiceImpl productService) {
public ProductController(ProductServiceImpl productService, QuantityChangeValidator quantityChangeValidator) {
this.productService = productService;
this.quantityChangeValidator = quantityChangeValidator;
}
@GetMapping(value = "/get-all")
public @ResponseBody
Iterable<Product> getAll(){
return productService.getAllProducts();
public Iterable<Product> getAll(Pageable pageable) {
return productService.getAll(pageable);
}
@GetMapping(value = "/get-price-of-all")
public @ResponseBody
public
Map getPriceOfAllProducts(){
return Collections.singletonMap("price-of-all", productService.getPriceOfAllProducts());
return Collections.singletonMap("price-of-all", productService.getPriceOfAll());
}
@PostMapping(value = "/product/add")
public @ResponseBody
Product addProduct(@RequestBody Product product){
return productService.addProduct(product);
public Product addProduct(@Valid @RequestBody Product product) {
try {
return productService.add(product);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
}
}
@DeleteMapping(value = "/product/delete")
public @ResponseBody
public
String deleteProduct(@RequestBody IdDto id){
productService.deleteProduct(id.getId());
try {
productService.delete(id.getId());
return "Deleted" + id;
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
}
}
@GetMapping(value = "/product/get-by-id")
public @ResponseBody
public
Product getById(@RequestBody IdDto id){
try {
return productService.getById(id.getId());
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
}
}
@PostMapping(value = "/product/change-quantity")
public @ResponseBody
public
Product changeQuantity(@RequestBody QuantityChange quantityChange){
try {
quantityChangeValidator.validate(quantityChange);
return productService.changeQuantity(quantityChange);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
}
}
}

View File

@ -0,0 +1,8 @@
package com.dino.scrum.sysmag.exception;
/**
* Created by prgres on 2019-01-21.
*/
public class ProductNotFoundException extends ClassNotFoundException {
}

View File

@ -5,6 +5,10 @@ import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
/**
@ -23,16 +27,33 @@ public class Product {
@Column(name = "id")
private Long id;
@NotNull(message = "name cannot be null")
@Size(min = 2, message = "name cannot be shorter that 2")
@Column(name = "name")
private String name;
@NotNull(message = "price cannot be null")
@DecimalMin(value = "0.00", message = "price cannot be under 0.00")
@Column(name = "price")
private BigDecimal price;
@NotNull(message = "quantity cannot be null")
@Min(value = 0, message = "quantity cannot be under 0")
@Column(name = "quantity")
private long quantity;
@NotNull(message = "quantityMax cannot be null")
@Min(value = 1, message = "quantityMax cannot be under 1")
@Column(name = "quantityMax")
private long quantityMax;
@NotNull(message = "image_link cannot be null")
@Column(name = "image_link")
private String imageLink;
public Product setChangeQuantity(long change) {
this.quantity += change;
return this;
}
}

View File

@ -8,5 +8,6 @@ import lombok.Getter;
@Getter
public class IdDto {
long id;
}

View File

@ -1,5 +1,6 @@
package com.dino.scrum.sysmag.model.dto;
import lombok.EqualsAndHashCode;
import lombok.Getter;
/**
@ -7,6 +8,7 @@ import lombok.Getter;
*/
@Getter
@EqualsAndHashCode
public class QuantityChange {
long id;
long change;

View File

@ -1,16 +1,19 @@
package com.dino.scrum.sysmag.repository;
import com.dino.scrum.sysmag.model.Product;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
/**
* Created by prgres on 2019-01-12.
*/
@Repository
public interface ProductRepository extends PagingAndSortingRepository<Product, Long> {
boolean existsByName(String name);
public interface ProductRepository extends CrudRepository<Product, Long> {
List<Product> findAll();
Optional<Product> findByName(String name);
Product findById(long id);
}

View File

@ -2,19 +2,24 @@ package com.dino.scrum.sysmag.service;
import com.dino.scrum.sysmag.model.Product;
import com.dino.scrum.sysmag.model.dto.QuantityChange;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
/**
* Created by prgres on 2019-01-12.
*/
public interface ProductService {
List<Product> getAllProducts();
Product changeQuantity(QuantityChange quantityChange);
Product getById(Long id);
float getPriceOfAllProducts();
Product addProduct(Product product);
void deleteProduct(long id);
Slice<Product> getAll(Pageable pageable);
Product changeQuantity(QuantityChange quantityChange) throws Exception;
Product getById(Long id) throws Exception;
Product add(Product product) throws Exception;
float getPriceOfAll();
void delete(long id) throws Exception;
}

View File

@ -3,14 +3,15 @@ package com.dino.scrum.sysmag.service;
import com.dino.scrum.sysmag.model.Product;
import com.dino.scrum.sysmag.model.dto.QuantityChange;
import com.dino.scrum.sysmag.repository.ProductRepository;
import com.dino.scrum.sysmag.validator.ProductValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.persistence.EntityNotFoundException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by prgres on 2019-01-12.
@ -19,57 +20,60 @@ import java.util.stream.Collectors;
@Service
public class ProductServiceImpl implements ProductService {
private final ProductRepository productRepository;
private final
ProductRepository productRepository;
private final
ProductValidator productValidator;
@Autowired
public ProductServiceImpl(ProductRepository productRepository) {
public ProductServiceImpl(ProductRepository productRepository, ProductValidator productValidator) {
this.productRepository = productRepository;
this.productValidator = productValidator;
}
@Override
public List<Product> getAllProducts() {
return productRepository.findAll();
public Slice<Product> getAll(Pageable pageable) {
if (pageable.getSort().isUnsorted()) {
pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), new Sort(Sort.Direction.ASC, "id"));
}
return productRepository.findAll(pageable);
}
@Override
public Product changeQuantity(QuantityChange quantityChange) {
return productRepository.findById(quantityChange.getId())
.map(product -> {
product.setQuantity(
product.getQuantity() + quantityChange.getChange()
);
return productRepository.save(product);
}).orElse(null);
public Product changeQuantity(QuantityChange quantityChange) throws Exception {
productValidator.checkIfExists(quantityChange.getId());
return productRepository.findById(quantityChange.getId()).setChangeQuantity(quantityChange.getChange());
}
@Override
public Product getById(Long id) {
return productRepository.findById(id).orElse(null);
public Product getById(Long id) throws Exception {
productValidator.checkIfExists(id);
return productRepository.findById(id.longValue());
}
@Override
public float getPriceOfAllProducts() {
public float getPriceOfAll() {
BigDecimal result = new BigDecimal(0);
List<Product> tempProductList = productRepository.findAll();
Iterable<Product> tempProductList = productRepository.findAll();
for (Product product : tempProductList) {
result = result.add(
product.getPrice()
.multiply( new BigDecimal(product.getQuantity())));
}
return result.floatValue();
}
@Override
public Product addProduct(Product product) {
public Product add(Product product) throws Exception {
productValidator.checkIfExists(product.getName());
return productRepository.save(product);
}
@Override
public void deleteProduct(long id) {
public void delete(long id) throws Exception {
productValidator.checkIfExists(id);
productRepository.deleteById(id);
}
}

View File

@ -0,0 +1,38 @@
package com.dino.scrum.sysmag.validator;
import com.dino.scrum.sysmag.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by prgres on 2019-01-22.
*/
@Component
public class ProductValidator {
private final ProductRepository productRepository;
@Autowired
public ProductValidator(ProductRepository productRepository) {
this.productRepository = productRepository;
}
private boolean existsById(long id) {
return productRepository.existsById(id);
}
private boolean existsByName(String name) {
return productRepository.existsByName(name);
}
public void checkIfExists(long id) throws Exception {
if (existsById(id))
throw new Exception("Product with id: " + id + " not found");
}
public void checkIfExists(String name) throws Exception {
if (existsByName(name))
throw new Exception("Product " + name + " already exists");
}
}

View File

@ -0,0 +1,44 @@
package com.dino.scrum.sysmag.validator;
import com.dino.scrum.sysmag.model.Product;
import com.dino.scrum.sysmag.model.dto.QuantityChange;
import com.dino.scrum.sysmag.service.ProductServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by prgres on 2019-01-20.
*/
@Component
public class QuantityChangeValidator {
private final
ProductServiceImpl productService;
@Autowired
public QuantityChangeValidator(ProductServiceImpl productService) {
this.productService = productService;
}
public void validate(QuantityChange quantityChange) throws Exception {
Product product = productService.getById(quantityChange.getId());
if (ifUnderStock(product.getQuantity(), quantityChange.getChange())) {
throw new RuntimeException("Too low product with id: " + quantityChange.getId() + " on stock");
}
if (ifAboveMaxLimitStock(product.getQuantity(), product.getQuantityMax(), quantityChange.getChange())) {
throw new RuntimeException("Over max quantity limit of product with id: " + quantityChange.getId());
}
}
private boolean ifUnderStock(long quantityOfProduct, long quantityChange) {
return ((quantityOfProduct + quantityChange) < 0);
}
private boolean ifAboveMaxLimitStock(long quantityOfProduct, long maxQuantityOfProduct, long quantityChange) {
return ((quantityOfProduct + quantityChange) > maxQuantityOfProduct);
}
}