microservices user interaction w/ tasks

This commit is contained in:
Juanito Cameros 2024-11-29 16:33:14 +01:00
parent 8bfd440104
commit 878acabdf1
3 changed files with 128 additions and 12 deletions

View file

@ -3,18 +3,14 @@ package fr.insa_toulouse.mas.benevolat.Authentication.ressource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fr.insa_toulouse.mas.benevolat.Authentication.model.User;
@RestController
@RequestMapping("auth")
public class AuthentificationResource {
@PostMapping("add/{name}/{password}/{isAdmin}")
public void addUser(@PathVariable("name") String name, @PathVariable("password") String password, @PathVariable("isAdmin") Integer isAdmin) {
User.saveUser(name,password,isAdmin != 0);
public void addUser(@PathVariable("name") String name, @PathVariable("password") String password, @PathVariable("isAdmin") Boolean isAdmin) {
User.saveUser(name,password,isAdmin);
}
@GetMapping("connect/{name}/{password}")

View file

@ -1,8 +1,12 @@
package fr.insa.mas.taskCreator.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -17,14 +21,48 @@ import fr.insa.mas.taskCreator.model.task;
public class taskRessource {
@PostMapping("propose/{condition}/{approval}/{assignedAdmin}/{assignedHelper}/{assignedRequester}/{Description}")
public void addTask(@PathVariable("condition") Boolean condition, , @PathVariable("approval") Boolean approval , @PathVariable("assignedAdmin") int User.id, @PathVariable("assignedHelper") int User.id, @PathVariable("assignedRequester") int User, @PathVariable("assignedRequester") String Description) {
task.saveTask(false, false, Null, id, Null, Description);
public void addTask(@PathVariable("condition") Boolean condition, @PathVariable("approval") Boolean approval , @PathVariable("assignedAdmin") int Adminid, @PathVariable("assignedHelper") int Helperid, @PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
task.saveTask(false, false, null, Helperid, null, Description);
}
@PostMapping("request/{condition}/{approval}/{assignedAdmin}/{assignedHelper}/{assignedRequester}/{Description}")
public void propTask(@PathVariable("condition") Boolean condition, , @PathVariable("approval") Boolean approval , @PathVariable("assignedAdmin") int User.id, @PathVariable("assignedHelper") int User.id, @PathVariable("assignedRequester") int User, @PathVariable("assignedRequester") String Description) {
task.saveTask(false, false, Null, id, Null, Description);
public void propTask(@PathVariable("condition") Boolean condition, @PathVariable("approval") Boolean approval ,
@PathVariable("assignedAdmin") int Adminid, @PathVariable("assignedHelper") int Helperid,
@PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
task.saveTask(false, false, null, null, Requesterid, Description);
}
@GetMapping("getTasks/unanswered")
public ArrayList<task> getUnansweredTasks() {
return task.getUnansweredTasks();
}
@GetMapping("getTasks/unasigned")
public ArrayList<task> getUnasignedTasks() {
return task.getUnsignedTasks();
}
@GetMapping("getTasks/uncompleted")
public ArrayList<task> getUncompletedTasks() {
return task.getUncomplitedTasks();
}
@PutMapping("completeTask/{taskId}")
public void completeTask(@PathVariable("taskId") Integer taskId) {
task.completeTask(taskId);
}
@PutMapping("assignHelper/{taskId}/{helperId}")
public void assignHelper(@PathVariable("taskId") Integer taskId, @PathVariable("helperId") Integer helperId) {
task.assignHelper(taskId, helperId);
}
@PutMapping("assignHelped/{taskId}/{helpedId}")
public void assignHelped(@PathVariable("taskId") Integer taskId, @PathVariable("helpedId") Integer helpedId) {
task.assignHelped(taskId, helpedId);
}
}

View file

@ -3,10 +3,14 @@ package fr.insa.mas.taskCreator.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;
import java.util.Random;
import org.springframework.scheduling.config.Task;
public class task {
private int id;
private boolean condition;
@ -41,8 +45,8 @@ public class task {
static public void saveTask(boolean condition, boolean approval, int assignedAdmin,
int assignedHelper, int assignedRequester,String Description ) {
static public void saveTask(boolean condition, boolean approval, Integer assignedAdmin,
Integer assignedHelper, Integer assignedRequester,String Description ) {
Random rand = new Random();
int id = rand.nextInt(500000);
task task = new task(id, condition, approval, assignedAdmin, assignedHelper, assignedRequester, Description);
@ -56,7 +60,85 @@ public class task {
}
}
static public ArrayList<task> getUnansweredTasks(){
ArrayList<task> unansweredTasks = new ArrayList<task>();
Statement statement;
try {
statement = task.connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * from task WHERE helped = NULL AND isCompleted = FALSE");
while (res.next()) {
unansweredTasks.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){
e.printStackTrace();
}
return unansweredTasks;
}
static public ArrayList<task> getUnsignedTasks(){
ArrayList<task> unasignedTasks = new ArrayList<task>();
Statement statement;
try {
statement = task.connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * from task WHERE helper = NULL AND isCompleted = FALSE");
while (res.next()) {
unasignedTasks.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){
e.printStackTrace();
}
return unasignedTasks;
}
static public ArrayList<task> getUncomplitedTasks(){
ArrayList<task> unComplitedTasks = new ArrayList<task>();
Statement statement;
try {
statement = task.connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * from task WHERE isCompleted = FALSE");
while (res.next()) {
unComplitedTasks.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){
e.printStackTrace();
}
return unComplitedTasks;
}
static public void completeTask(int id) {
try {
Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET isCompleted = true WHERE id = " + id + ";");
} catch(SQLException e){
throw new RuntimeException(e);
}
}
static public void assignHelper(int id, int helperid) {
try {
Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET helper = " + helperid + " WHERE id = " + id + ";");
} catch(SQLException e){
throw new RuntimeException(e);
}
}
static public void assignHelped(int id, int helpedid) {
try {
Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET helper = " + helpedid + " WHERE id = " + id + ";");
} catch(SQLException e){
throw new RuntimeException(e);
}
}
public int getId() {
return id;