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
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
</dependencyManagement>
<properties>
<dropwizard.version>2.0.3</dropwizard.version>
<mainClass>org.example.TestApplication</mainClass>
<mainClass>org.example.DJ2Application</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>2.0.3</dropwizard.version>
<mainClass>org.example.TestApplication</mainClass>
<mainClass>org.example.DJ2Application</mainClass>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
import io.dropwizard.setup.Environment;
import io.federecio.dropwizard.swagger.SwaggerBundle;
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;
import org.example.controllers.DeliveryEmployeeController;
import org.example.controllers.SalesEmployeeController;
import org.example.controllers.TestController;
import org.example.daos.DeliveryEmployeeDao;
import org.example.daos.SalesEmployeeDao;
import org.example.daos.TestDao;
import org.example.services.DeliveryEmployeeService;
import org.example.services.SalesEmployeeService;
import org.example.services.TestService;

public class TestApplication extends Application<TestConfiguration> {
public class DJ2Application extends Application<TestConfiguration> {
public static void main(final String[] args) throws Exception {
new TestApplication().run(args);
new DJ2Application().run(args);
}
@Override
public String getName() {
Expand All @@ -32,6 +38,10 @@ public void run(final TestConfiguration configuration,
final Environment environment) {
environment.jersey()
.register(new TestController(new TestService(new TestDao())));
environment.jersey().register(new DeliveryEmployeeController(
new DeliveryEmployeeService(new DeliveryEmployeeDao())));
environment.jersey().register(new SalesEmployeeController(
new SalesEmployeeService(new SalesEmployeeDao())));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.example.controllers;

import io.swagger.annotations.Api;
import org.example.services.DeliveryEmployeeService;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.SQLException;



@Api("Delivery Employee API")
@Path("/api/DeliveryEmployees")
public class DeliveryEmployeeController {
DeliveryEmployeeService deliveryEmployeeService;

public DeliveryEmployeeController(
final DeliveryEmployeeService deliveryEmployeeService) {
this.deliveryEmployeeService = deliveryEmployeeService;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response testConnection() {
try {
return Response.ok()
.entity(deliveryEmployeeService.getAllDeliveryEmployees())
.build();
} catch (SQLException e) {
return Response.serverError().build();
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/example/controllers/SalesEmployeeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.example.controllers;

import io.swagger.annotations.Api;
import org.example.services.SalesEmployeeService;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.SQLException;

@Api("Delivery Employee API")
@Path("/api/SalesEmployees")
public class SalesEmployeeController {
SalesEmployeeService salesEmployeeService;

public SalesEmployeeController(
final SalesEmployeeService salesEmployeeService) {
this.salesEmployeeService = salesEmployeeService;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response testConnection() {
try {
return Response.ok()
.entity(salesEmployeeService.getAllSalesEmployees())
.build();
} catch (SQLException e) {
System.out.println(e);
return Response.serverError().build();
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/org/example/daos/DeliveryEmployeeDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.example.daos;

import org.example.models.DeliveryEmployee;

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

public class DeliveryEmployeeDao {

public List<DeliveryEmployee> getAllDeliveryEmployees()
throws SQLException {
List<DeliveryEmployee> deliveryEmployees = new ArrayList<>();

try (Connection connection = DatabaseConnector.getConnection()) {
Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(
"SELECT * FROM `DeliveryEmployees`;");

while (resultSet.next()) {
DeliveryEmployee deliveryEmployee = new DeliveryEmployee(
resultSet.getInt("id"),
resultSet.getString("name"),
resultSet.getDouble("salary"),
resultSet.getInt("bank_acc"),
resultSet.getString("ni")
);
deliveryEmployees.add(deliveryEmployee);
}
}

return deliveryEmployees;
}
}
40 changes: 40 additions & 0 deletions src/main/java/org/example/daos/SalesEmployeeDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.example.daos;

import org.example.models.SalesEmployee;

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

public class SalesEmployeeDao {

public List<SalesEmployee> getAllSalesEmployees()
throws SQLException {
List<SalesEmployee> salesEmployees = new ArrayList<>();

try (Connection connection = DatabaseConnector.getConnection()) {
Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(
"SELECT * FROM `SalesEmployees`;");

while (resultSet.next()) {
SalesEmployee salesEmployee = new SalesEmployee(
resultSet.getInt("id"),
resultSet.getString("name"),
resultSet.getDouble("salary"),
resultSet.getInt("bank_acc"),
resultSet.getString("ni"),
resultSet.getDouble("commissionRate")
);
salesEmployees.add(salesEmployee);
}
}

return salesEmployees;
}

}
59 changes: 59 additions & 0 deletions src/main/java/org/example/models/DeliveryEmployee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.example.models;

public class DeliveryEmployee {
private int id;
private String name;
private double salary;
private int bankAccount;
private String nI;

public DeliveryEmployee(final int id, final String name,
final double salary, final int bankAccount,
final String nI) {
this.setId(id);
this.setName(name);
this.setSalary(salary);
this.setBankAccount(bankAccount);
this.setnI(nI);
}

public int getId() {
return id;
}

public void setId(final int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public double getSalary() {
return salary;
}

public void setSalary(final double salary) {
this.salary = salary;
}

public int getBankAccount() {
return bankAccount;
}

public void setBankAccount(final int bankAccount) {
this.bankAccount = bankAccount;
}

public String getnI() {
return nI;
}

public void setnI(final String nI) {
this.nI = nI;
}
}
69 changes: 69 additions & 0 deletions src/main/java/org/example/models/SalesEmployee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.example.models;

public class SalesEmployee {

private int id;
private String name;
private double salary;
private int bankAccount;
private String nI;
private double commissionRate;

public SalesEmployee(final int id, final String name,
final double salary, final int bankAccount,
final String nI, final double commissionRate) {
this.setId(id);
this.setName(name);
this.setSalary(salary);
this.setBankAccount(bankAccount);
this.setnI(nI);
}

public int getId() {
return id;
}

public void setId(final int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public double getSalary() {
return salary;
}

public void setSalary(final double salary) {
this.salary = salary;
}

public int getBankAccount() {
return bankAccount;
}

public void setBankAccount(final int bankAccount) {
this.bankAccount = bankAccount;
}

public String getnI() {
return nI;
}

public void setnI(final String nI) {
this.nI = nI;
}

public double getCommissionRate() {
return commissionRate;
}

public void setCommissionRate(final double commissionRate) {
this.commissionRate = commissionRate;
}
}
23 changes: 23 additions & 0 deletions src/main/java/org/example/services/DeliveryEmployeeService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example.services;

import org.example.daos.DeliveryEmployeeDao;
import org.example.models.DeliveryEmployee;

import java.sql.SQLException;
import java.util.List;

public class DeliveryEmployeeService {

DeliveryEmployeeDao deliveryEmployeeDao;

public DeliveryEmployeeService(
final DeliveryEmployeeDao deliveryEmployeeDao) {
this.deliveryEmployeeDao = deliveryEmployeeDao;
}
public List<DeliveryEmployee> getAllDeliveryEmployees()
throws SQLException {
return deliveryEmployeeDao.getAllDeliveryEmployees();
}


}
23 changes: 23 additions & 0 deletions src/main/java/org/example/services/SalesEmployeeService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example.services;

import org.example.daos.SalesEmployeeDao;
import org.example.models.SalesEmployee;

import java.sql.SQLException;
import java.util.List;

public class SalesEmployeeService {

SalesEmployeeDao salesEmployeeDao;

public SalesEmployeeService(
final SalesEmployeeDao salesEmployeeDao) {
this.salesEmployeeDao = salesEmployeeDao;
}

public List<SalesEmployee> getAllSalesEmployees()
throws SQLException {
return salesEmployeeDao.getAllSalesEmployees();
}

}
Loading