Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
warehouse-management
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
warehouse-management
Commits
26fdd410
Commit
26fdd410
authored
May 11, 2021
by
Alex Pinto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added block on update endpoint
parent
0aa69552
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
11 deletions
+38
-11
pom.xml
pom.xml
+11
-0
WarehouseApplication.java
...om/ascendfinalproject/warehouse/WarehouseApplication.java
+9
-0
WarehouseController.java
...nalproject/warehouse/controllers/WarehouseController.java
+2
-5
WarehouseOrderService.java
...inalproject/warehouse/services/WarehouseOrderService.java
+16
-6
No files found.
pom.xml
View file @
26fdd410
...
...
@@ -85,6 +85,17 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.7.0
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.7.0
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/ascendfinalproject/warehouse/WarehouseApplication.java
View file @
26fdd410
...
...
@@ -2,6 +2,10 @@ package com.ascendfinalproject.warehouse;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
@SpringBootApplication
public
class
WarehouseApplication
{
...
...
@@ -9,6 +13,11 @@ public class WarehouseApplication {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
WarehouseApplication
.
class
,
args
);
}
@Bean
public
Docket
productApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
).
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.ascendfinalproject.warehouse"
)).
build
();
}
}
src/main/java/com/ascendfinalproject/warehouse/controllers/WarehouseController.java
View file @
26fdd410
...
...
@@ -42,11 +42,8 @@ public class WarehouseController {
@CrossOrigin
@PutMapping
(
value
=
"/orders/{id}"
)
public
Mono
<
ResponseEntity
>
updateOrder
(
@RequestBody
WarehouseOrderResponse
order
,
@PathVariable
(
value
=
"id"
)
String
id
)
{
return
orderService
.
updateOrder
(
order
,
id
)
.
map
(
updatedOrder
->
(
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
order
)))
.
cast
(
ResponseEntity
.
class
)
.
defaultIfEmpty
(
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
(
null
));
public
Mono
<
WarehouseOrderResponse
>
updateOrder
(
@RequestBody
WarehouseOrderResponse
order
,
@PathVariable
(
value
=
"id"
)
String
id
)
{
return
orderService
.
updateOrder
(
order
,
id
);
}
@CrossOrigin
...
...
src/main/java/com/ascendfinalproject/warehouse/services/WarehouseOrderService.java
View file @
26fdd410
...
...
@@ -6,8 +6,9 @@ import com.ascendfinalproject.warehouse.models.WarehouseOrderRequest;
import
com.ascendfinalproject.warehouse.models.WarehouseOrderResponse
;
import
com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
reactor.core.CoreSubscriber
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
...
...
@@ -16,6 +17,10 @@ import java.util.Date;
@Service
public
class
WarehouseOrderService
{
private
String
RECEIVED
=
"RECEIVED"
;
private
String
FULFILLED
=
"FULFILLED"
;
private
String
CANCELLED
=
"CANCELLED"
;
@Autowired
WarehouseOrderRepository
orderRepository
;
...
...
@@ -30,9 +35,8 @@ public class WarehouseOrderService {
public
Mono
<
WarehouseOrderResponse
>
createOrder
(
WarehouseOrderRequest
order
)
{
WarehouseOrderResponse
response
=
new
WarehouseOrderResponse
();
response
.
setOrderId
(
order
.
getId
());
response
.
setStatus
(
"RECEIVED"
);
response
.
setStatus
(
RECEIVED
);
response
.
setCreatedAt
(
new
Date
(
order
.
getOrderCreatedAt
()));
response
.
setModifiedAt
(
new
Date
(
order
.
getOrderUpdatedAt
()));
response
.
setOrderItems
(
order
.
getOrderItems
());
Address
address
=
order
.
getCustomerAddress
();
response
.
setAddress
(
address
.
getStreet
()
+
", "
+
...
...
@@ -46,10 +50,16 @@ public class WarehouseOrderService {
public
Mono
<
WarehouseOrderResponse
>
updateOrder
(
WarehouseOrderResponse
order
,
String
id
)
{
return
orderRepository
.
findById
(
id
)
.
flatMap
(
existingOrder
->
{
existingOrder
.
setStatus
(
order
.
getStatus
());
existingOrder
.
setModifiedAt
(
new
Date
(
System
.
currentTimeMillis
()));
return
orderRepository
.
save
(
existingOrder
);
if
(
existingOrder
.
getStatus
().
equals
(
RECEIVED
))
{
if
(
order
.
getStatus
().
equals
(
FULFILLED
)
||
order
.
getStatus
().
equals
(
CANCELLED
))
{
existingOrder
.
setStatus
(
order
.
getStatus
());
existingOrder
.
setModifiedAt
(
new
Date
(
System
.
currentTimeMillis
()));
}
}
return
orderRepository
.
save
(
existingOrder
);
});
}
public
Mono
<
Void
>
deleteOrder
(
String
id
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment