Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.globant</groupId>
<artifactId>shoppingcart</artifactId>
<version>0.1</version>
<packaging>war</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>


<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/resources/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
10 changes: 10 additions & 0 deletions src/main/java/com/globant/config/AppConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.globant.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.globant")
public class AppConfiguration {

}
54 changes: 54 additions & 0 deletions src/main/java/com/globant/controller/ClientController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.globant.controller;

import com.globant.dto.ClientDTO;
import com.globant.service.ClientService;
import com.globant.service.CRUD;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class ClientController {

private final CRUD<ClientDTO> clientService;

@Autowired
public ClientController(ClientService clientService) {
this.clientService = clientService;
}

@RequestMapping(value = "/createClient", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ClientDTO create(ClientDTO clientDTO) {
validate(clientDTO);
return clientService.create(clientDTO);
}

@RequestMapping(value = "/retrieveClient", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ClientDTO read(int clientId) {
return clientService.read(clientId);
}

@RequestMapping(value = "/updateClient", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ClientDTO update(ClientDTO clientDTO) {
validate(clientDTO);
return clientService.update(clientDTO);
}

@RequestMapping(value = "/deleteClient", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public void delete(int clientId) {
clientService.delete(clientId);
}

@RequestMapping(value = "/retrieveClient", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<ClientDTO> readAll(List<Integer> clientIds) {
return clientService.readAll();
}

private void validate(ClientDTO clientDTO) {
if (clientDTO == null)
throw new IllegalArgumentException("object cannot be null");
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/globant/controller/ItemController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.globant.controller;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {
}
7 changes: 7 additions & 0 deletions src/main/java/com/globant/controller/OrderController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.globant.controller;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
}
7 changes: 7 additions & 0 deletions src/main/java/com/globant/controller/PaymentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.globant.controller;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class PaymentController {
}
144 changes: 144 additions & 0 deletions src/main/java/com/globant/dao/ClientDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@


package com.globant.dao;

import com.globant.db.DBConnection;
import com.globant.model.Client;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Repository
public class ClientDAO implements DataAccessObject<Client> {

private static final String CREATE = "INSERT INTO client(firstName, lastName, description) VALUES (?, ?, ?)";
private static final String READ = "SELECT * FROM client WHERE IdClient=?";
private static final String UPDATE = "UPDATE client SET firstName =?, lastName=?, description= ? WHERE idClient=?";
private static final String DELETE = "DELETE FROM client WHERE idClient=?";
private static final String READ_ALL = "SELECT * FROM client";

public Client create(Client client) {

try {
DBConnection dbConnection = DBConnection.getInstance ( );
Connection connection = dbConnection.getConnection ( );
PreparedStatement statement = connection.prepareStatement (CREATE);
statement.setString (1, client.getName ( ));
statement.setString (2, client.getSurname ( ));
statement.setString (3, client.getDescription ( ));

ResultSet resultset = statement.executeQuery ( );
String name = resultset.getString ("firsName");
String lastname = resultset.getString ("lastName");
String description = resultset.getString ("description");
int clientid = resultset.getInt ("idClient");


return new Client ( clientid,name, lastname, description);



} catch (SQLException e) {
System.out.print ("error: client could not be created "+e.getMessage());

}
return null;

}
public Client read( int id) {

try {
DBConnection dbConnection = DBConnection.getInstance ( );
Connection connection = dbConnection.getConnection ( );
PreparedStatement statement = connection.prepareStatement (READ);
statement.setInt (1, id);

ResultSet resultset = statement.executeQuery ( );
String name = resultset.getString ("firsName");
String lastname = resultset.getString ("lastName");
String description = resultset.getString ("description");
int clientid = resultset.getInt ("idClient");

return new Client (clientid, name, lastname, description);

} catch (SQLException e) {
System.out.print ("error: client not found "+e.getMessage());
}
return null;
}
public Client update( Client client){
try {
DBConnection dbConnection = DBConnection.getInstance ( );
Connection connection = dbConnection.getConnection ( );
PreparedStatement statement = connection.prepareStatement (UPDATE);
statement.setString (1, client.getName ( ));
statement.setString (2, client.getSurname ( ));
statement.setString (3, client.getDescription ( ));
statement.setInt (4,client.getId());

statement.executeQuery ( );
return client;

} catch (SQLException e) {
System.out.print ("error: client has not been updated"+e.getMessage());

}
return null;

}


public void delete ( int id ){
try {
DBConnection dbConnection = DBConnection.getInstance ( );
Connection connection = dbConnection.getConnection ( );
PreparedStatement statement = connection.prepareStatement (DELETE);
statement.setInt (1, id);

statement.executeQuery ( );

} catch (SQLException e) {
System.out.print ("error: client not found "+e.getMessage());

}
}
public List <Client> readAll(){

try {
DBConnection dbConnection = DBConnection.getInstance ( );
Connection connection = dbConnection.getConnection ( );
PreparedStatement statement = connection.prepareStatement (READ_ALL);
List<Client> clients = new ArrayList<Client>();

ResultSet resultset = statement.executeQuery ( );
while (resultset.next ()){
int idClient = resultset.getInt ("idClient");
String name = resultset.getString ("firsName");
String lastname = resultset.getString ("lastName");
String descrption = resultset.getString ("description");

Client client= new Client (idClient, name,lastname, descrption);



clients.add (client);
}


return clients;

} catch (SQLException e) {
System.out.print ("error: customers were not found"+e.getMessage());

}
return null;

}


}
11 changes: 11 additions & 0 deletions src/main/java/com/globant/dao/DataAccessObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.globant.dao;

import java.util.List;

public interface DataAccessObject<T>{
T create(T object);
T read(int id );
T update(T object);
void delete(int id);
List<T> readAll();
}
29 changes: 29 additions & 0 deletions src/main/java/com/globant/dao/ItemDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.globant.dao;

import com.globant.model.Item;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ItemDAO implements DataAccessObject<Item> {
public Item create( Item object ) {
return null;
}

public Item read( int id ) {
return null;
}

public Item update( Item object ) {
return null;
}

public void delete( int id ) {

}

public List<Item> readAll() {
return null;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/globant/dao/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.globant.dao;

import com.globant.model.Client;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderDAO implements DataAccessObject<Client> {
public Client create( Client object ) {
return null;
}

public Client read( int id ) {
return null;
}

public Client update( Client object ) {
return null;
}

public void delete( int id ) {

}

public List<Client> readAll() {
return null;
}
}
Loading