Commit d25573e1 authored by Darrick Yong's avatar Darrick Yong

Merge branch 'backend2' into 'master'

Backend2

See merge request !15
parents 4be642aa 4222ee4a
FROM openjdk:11-jre-slim
COPY target/warehouse-0.0.1-SNAPSHOT.jar /usr/local/lib/warehouse.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/warehouse.jar"]
# BELOW IS FOR LOCAL TESTING
# FROM maven:3.6.0-jdk-11-slim AS build
# COPY src /home/app/src
# COPY pom.xml /home/app
# RUN mvn -f /home/app/pom.xml clean package -DskipTests
#
# FROM openjdk:11-jre-slim
# COPY --from=build /home/app/target/warehouse-0.0.1-SNAPSHOT.jar /usr/local/lib/warehouse.jar
# EXPOSE 8080
# ENTRYPOINT ["java","-jar","/usr/local/lib/warehouse.jar"]
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci
RUN npm install react-scripts@3.4.1 -g
COPY . ./
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
......@@ -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>
......
......@@ -2,13 +2,25 @@ 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;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
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();
}
}
......@@ -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
......
......@@ -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 -> {
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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment