-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from whuera/develop
Add new features for branch: develop
- Loading branch information
Showing
9 changed files
with
237 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Maven | ||
- task: PublishCodeCoverageResults@1 | ||
inputs: | ||
codeCoverageTool: 'JaCoCo' | ||
summaryFileLocation: '/site/cobertura/coverage.xml' | ||
# Build your Java project and run tests with Apache Maven. | ||
# Add steps that analyze code, save build artifacts, deploy, and more: | ||
# https://docs.microsoft.com/azure/devops/pipelines/languages/java | ||
|
||
trigger: | ||
- main | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
steps: | ||
- task: Maven@3 | ||
inputs: | ||
mavenPomFile: 'pom.xml' | ||
mavenOptions: '-Xmx3072m' | ||
javaHomeOption: 'JDKVersion' | ||
jdkVersionOption: '1.8' | ||
jdkArchitectureOption: 'x64' | ||
publishJUnitResults: true | ||
testResultsFiles: '**/surefire-reports/TEST-*.xml' | ||
goals: 'package' |
18 changes: 18 additions & 0 deletions
18
demoSpark/src/main/java/com/app/demoSpark/models/Products.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.app.demoSpark.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
/** The type Products. */ | ||
@AllArgsConstructor | ||
@Data | ||
public class Products { | ||
private double IdProduct; | ||
private String codProduct; | ||
private String nameProduct; | ||
private String descProduct; | ||
private String specificationsProduct; | ||
private int quantityProduct; | ||
private double costProduct; | ||
private String urlImageProduct; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
demoSpark/src/main/java/com/app/demoSpark/models/UserBasicData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.app.demoSpark.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
/** The type User basic data. */ | ||
@Data | ||
@AllArgsConstructor | ||
public class UserBasicData { | ||
private int IdUserData; | ||
private String typeIdentification; | ||
private String numberIdentification; | ||
private String genero; | ||
private int age; | ||
} |
14 changes: 14 additions & 0 deletions
14
demoSpark/src/main/java/com/app/demoSpark/service/ProductService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.app.demoSpark.service; | ||
|
||
import com.app.demoSpark.models.Products; | ||
|
||
import java.util.List; | ||
|
||
public interface ProductService { | ||
public void saveProduct(Products product); | ||
public List<Products> getProducts(); | ||
public Products getProductById (String codeProduct); | ||
public void editProduct(Products product); | ||
public void deleteProduct(String codeProduct); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
demoSpark/src/main/java/com/app/demoSpark/service/ProductServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.app.demoSpark.service; | ||
|
||
import com.app.demoSpark.models.Products; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** The type Product service. */ | ||
public class ProductServiceImpl implements ProductService { | ||
|
||
private Map<String, Products> productsMap = new HashMap<String, Products>(); | ||
|
||
/** Instantiates a new Product service. */ | ||
public ProductServiceImpl() { | ||
productsMap.put ("01", new Products (1,"PR-01", "DELL G3", "Laptop Dell G3 Gammer", "Intel Core I9, 16MB RAM, 1TG HDD, 15.6 Widescreen", 5, 1800, "")); | ||
productsMap.put ("02", new Products (1,"PR-02", "DELL G7", "Laptop Dell G7 Gammer", "Intel Core I9, 16MB RAM, 1TG HDD, 17.3 Widescreen", 5, 1800, "")); | ||
} | ||
|
||
@Override | ||
public void saveProduct (Products product) { | ||
productsMap.put (String.valueOf(product.getIdProduct ()), product) ; | ||
} | ||
|
||
@Override | ||
public List<Products> getProducts () { | ||
return new ArrayList<Products> (productsMap.values ()); | ||
} | ||
|
||
@Override | ||
public Products getProductById (String codeProduct) { | ||
return productsMap.get (codeProduct); | ||
} | ||
|
||
@Override | ||
public void editProduct (Products product) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteProduct (String codeProduct) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 16 additions & 10 deletions
26
demoSpark/src/main/java/com/app/demoSpark/service/UserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 73 additions & 31 deletions
104
demoSpark/src/main/java/com/app/demoSpark/sparkMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,105 @@ | ||
package com.app.demoSpark; | ||
|
||
import com.app.demoSpark.models.Products; | ||
import com.app.demoSpark.models.User; | ||
import com.app.demoSpark.service.ProductService; | ||
import com.app.demoSpark.service.ProductServiceImpl; | ||
import com.app.demoSpark.service.UserService; | ||
import com.app.demoSpark.service.UserServiceImpl; | ||
import com.google.gson.Gson; | ||
import static spark.Spark.delete; | ||
import static spark.Spark.get; | ||
import static spark.Spark.port; | ||
import static spark.Spark.put; | ||
import static spark.Spark.post; | ||
|
||
import java.util.List; | ||
|
||
import static spark.Spark.*; | ||
|
||
|
||
public class sparkMain { | ||
public static void main(String[] args) { | ||
public static void main (String[] args) { | ||
|
||
UserService userService = new UserServiceImpl (); | ||
UserService userService = new UserServiceImpl (); | ||
ProductService productService = new ProductServiceImpl (); | ||
|
||
//configure port | ||
port(8080); | ||
port (8080); | ||
|
||
get("/hello", (req, res)->"Hello, world!"); | ||
get ("/hello", (req, res) -> "Hello, world!"); | ||
|
||
get("/hello/:name", (req,res)->{ | ||
return "Hello, "+ req.params(":name") + "!!"; | ||
get ("/hello/:name", (req, res) -> { | ||
return "Hello, " + req.params (":name") + "!!"; | ||
}); | ||
|
||
post("/users/add", (req,res)-> { | ||
res.type("application/json"); | ||
|
||
User user = new Gson().fromJson(req.body(), User.class); | ||
options ("/*", | ||
(request, response) -> { | ||
String accessControlRequestHeaders = request | ||
.headers("Access-Control-Request-Headers"); | ||
if (accessControlRequestHeaders != null) { | ||
response.header("Access-Control-Allow-Headers", | ||
accessControlRequestHeaders); | ||
} | ||
String accessControlRequestMethod = request | ||
.headers("Access-Control-Request-Method"); | ||
if (accessControlRequestMethod != null) { | ||
response.header("Access-Control-Allow-Methods", | ||
accessControlRequestMethod); | ||
} | ||
return "OK"; | ||
}); | ||
before((request, response) -> response.header("Access-Control-Allow-Origin", "*")); | ||
|
||
post ("/users/add", (req, res) -> { | ||
res.type ("application/json"); | ||
|
||
User user = new Gson ().fromJson (req.body (), User.class); | ||
userService.addUSer (user); | ||
return new Gson().toJson(user); | ||
return new Gson ().toJson (user); | ||
}); | ||
|
||
get("/users", (req,res)-> { | ||
res.type("application/json"); | ||
return new Gson().toJson(userService.getUsers()); | ||
get ("/users", (req, res) -> { | ||
res.type ("application/json"); | ||
return new Gson ().toJson (userService.getUsers ()); | ||
}); | ||
|
||
delete("/users/delete/:id", (req,res) -> { | ||
res.type("application/json"); | ||
userService.deleteUserById(req.params(":id")); | ||
return new Gson().toJson("User deleted"); | ||
get ("/users/:id", (req, res) -> { | ||
res.type ("application/json"); | ||
return new Gson ().toJson (userService.getUserById (req.params (":id"))); | ||
}); | ||
|
||
put("/users/edit/:id", (req,res) -> { | ||
res.type("application/json"); | ||
User ue = new Gson().fromJson(req.body(), User.class); | ||
delete ("/users/delete/:id", (req, res) -> { | ||
res.type ("application/json"); | ||
userService.deleteUserById (req.params (":id")); | ||
return new Gson ().toJson ("User deleted"); | ||
}); | ||
|
||
User searchedUser = userService.getUserById(ue.getId()); | ||
if(searchedUser != null) { | ||
userService.editUser(ue); | ||
return new Gson().toJson(ue); | ||
put ("/users/edit/:id", (req, res) -> { | ||
res.type ("application/json"); | ||
User ue = new Gson ().fromJson (req.body (), User.class); | ||
|
||
User searchedUser = userService.getUserById (ue.getId ()); | ||
if (searchedUser != null) { | ||
userService.editUser (ue); | ||
return new Gson ().toJson (ue); | ||
} else { | ||
return new Gson().toJson("User not found or error in edit"); | ||
return new Gson ().toJson ("User not found or error in edit"); | ||
} | ||
|
||
}); | ||
|
||
get ("/products", (req, res) -> { | ||
res.type ("application/json"); | ||
List<Products> productsList = productService.getProducts (); | ||
if (productsList.size () > 0){ | ||
return new Gson ().toJson (productsList); | ||
} else { | ||
return new Gson ().toJson ("No existe productos en stock"); | ||
} | ||
}); | ||
/** | ||
* method from request by idProducts | ||
*/ | ||
get ("/products/:id", (req, res) -> { | ||
res.type ("application/json"); | ||
return new Gson ().toJson (productService.getProductById (req.params (":id"))); | ||
}); | ||
|
||
} | ||
} |