Admin can get tasks, approve and/or disapprove them
This commit is contained in:
parent
b6d2a3a852
commit
8bfd440104
5 changed files with 187 additions and 10 deletions
|
@ -40,6 +40,13 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>9.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package fr.insa_toulouse.mas.benevolat.ApproveService.model;
|
|
||||||
|
|
||||||
public class ApproveServiceModel {
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
package fr.insa_toulouse.mas.benevolat.ApproveService.model;
|
||||||
|
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class Task {
|
||||||
|
private int id;
|
||||||
|
private boolean condition;
|
||||||
|
private boolean approval;
|
||||||
|
private int assignedAdmin ;
|
||||||
|
private int assignedHelper;
|
||||||
|
private int assignedRequester;
|
||||||
|
private String Description;
|
||||||
|
|
||||||
|
static HashMap<Integer, Task> tasks = new HashMap<Integer, Task>();
|
||||||
|
static Connection connection;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Task.connection = DriverManager.getConnection("jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_052?user=projet_gei_052&password=ohc1Eet7 ");
|
||||||
|
} catch(SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task(int id, boolean condition, boolean approval, int assignedAdmin, int assignedHelper,
|
||||||
|
int assignedRequester, String description) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.condition = condition;
|
||||||
|
this.approval = approval;
|
||||||
|
this.assignedAdmin = assignedAdmin;
|
||||||
|
this.assignedHelper = assignedHelper;
|
||||||
|
this.assignedRequester = assignedRequester;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public ArrayList<Task> getTasks() {
|
||||||
|
|
||||||
|
ArrayList<Task> tasks = new ArrayList<Task>();
|
||||||
|
Statement statement;
|
||||||
|
try {
|
||||||
|
statement = Task.connection.createStatement();
|
||||||
|
ResultSet res = statement.executeQuery("SELECT * FROM task WHERE isCompleted != True AND approved != True;");
|
||||||
|
while (res.next()) {
|
||||||
|
tasks.add(new Task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"), res.getInt("assignedAdmin"),
|
||||||
|
res.getInt("helper"), res.getInt("helped"), res.getString("description")));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void approveTask(int id) {
|
||||||
|
try {
|
||||||
|
Statement statement = Task.connection.createStatement();
|
||||||
|
statement.addBatch("UPDATE task SET approved = true, isCompleted = false WHERE id = " + id + ";");
|
||||||
|
statement.executeBatch();
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void disapproveTask(int id) {
|
||||||
|
try {
|
||||||
|
Statement statement = Task.connection.createStatement();
|
||||||
|
statement.addBatch("UPDATE task SET approved = false, isCompleted = true WHERE id = " + id + ";");
|
||||||
|
statement.executeBatch();
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCondition() {
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCondition(boolean condition) {
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isApproval() {
|
||||||
|
return approval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApproval(boolean approval) {
|
||||||
|
this.approval = approval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssignedAdmin() {
|
||||||
|
return assignedAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignedAdmin(int assignedAdmin) {
|
||||||
|
this.assignedAdmin = assignedAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssignedHelper() {
|
||||||
|
return assignedHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignedHelper(int assignedHelper) {
|
||||||
|
this.assignedHelper = assignedHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssignedRequester() {
|
||||||
|
return assignedRequester;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignedRequester(int assignedRequester) {
|
||||||
|
this.assignedRequester = assignedRequester;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,47 @@
|
||||||
package fr.insa_toulouse.mas.benevolat.ApproveService.ressource;
|
package fr.insa_toulouse.mas.benevolat.ApproveService.ressource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import fr.insa_toulouse.mas.benevolat.ApproveService.model.Task;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("approve")
|
@RequestMapping("approve")
|
||||||
public class ApproveServiceRessource {
|
public class ApproveServiceRessource {
|
||||||
@GetMapping("getTasks/{id}")
|
|
||||||
|
|
||||||
|
//@Autowired
|
||||||
|
//private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@GetMapping("getTasks/{adminId}")
|
||||||
|
public ArrayList<Task> getTasks(@PathVariable("adminId") Integer id) {
|
||||||
|
|
||||||
|
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) {
|
||||||
|
return Task.getTasks();
|
||||||
|
//}
|
||||||
|
//return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("approveTask/{adminId}/{taskId}")
|
||||||
|
public void approveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) {
|
||||||
|
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) {
|
||||||
|
Task.approveTask(taskId);
|
||||||
|
//}
|
||||||
|
//return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("disapproveTask/{adminId}/{taskId}")
|
||||||
|
public void disapproveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) {
|
||||||
|
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) {
|
||||||
|
Task.disapproveTask(taskId);
|
||||||
|
//}
|
||||||
|
//return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,6 @@ public class User {
|
||||||
try {
|
try {
|
||||||
Statement statement = User.connection.createStatement();
|
Statement statement = User.connection.createStatement();
|
||||||
ResultSet res = statement.executeQuery("Select isAdmin FROM user WHERE id = " + id + ";");
|
ResultSet res = statement.executeQuery("Select isAdmin FROM user WHERE id = " + id + ";");
|
||||||
System.out.println("Select isAdmin FROM user WHERE id = " + id + ";");
|
|
||||||
System.out.println("number of rows = " + res.getRow());
|
|
||||||
//result = res.getBoolean("isAdmin");
|
|
||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
result = res.getBoolean("isAdmin");
|
result = res.getBoolean("isAdmin");
|
||||||
}
|
}
|
||||||
|
@ -79,7 +76,6 @@ public class User {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return User.users.get(id).isAdmin;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue