discovery done

This commit is contained in:
Nathan Billard 2024-11-30 12:57:55 +01:00
parent 878acabdf1
commit 15097f2def
13 changed files with 137 additions and 31 deletions

View file

@ -28,8 +28,13 @@
</scm> </scm>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@ -47,7 +52,27 @@
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>9.1.0</version> <version>9.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>
@ -57,5 +82,25 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project> </project>

View file

@ -2,9 +2,18 @@ package fr.insa_toulouse.mas.benevolat.ApproveService;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
public class ApproveServiceApplication { public class ApproveServiceApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ApproveServiceApplication.class, args); SpringApplication.run(ApproveServiceApplication.class, args);

View file

@ -60,10 +60,10 @@ public class Task {
return tasks; return tasks;
} }
static public void approveTask(int id) { static public void approveTask(int id, int adminId) {
try { try {
Statement statement = Task.connection.createStatement(); Statement statement = Task.connection.createStatement();
statement.addBatch("UPDATE task SET approved = true, isCompleted = false WHERE id = " + id + ";"); statement.addBatch("UPDATE task SET approved = true, isCompleted = false, assignedAdmin = " + adminId + " WHERE id = " + id + ";");
statement.executeBatch(); statement.executeBatch();
statement.close(); statement.close();
} catch (SQLException e) { } catch (SQLException e) {
@ -71,10 +71,10 @@ public class Task {
} }
} }
static public void disapproveTask(int id) { static public void disapproveTask(int id, int adminId) {
try { try {
Statement statement = Task.connection.createStatement(); Statement statement = Task.connection.createStatement();
statement.addBatch("UPDATE task SET approved = false, isCompleted = true WHERE id = " + id + ";"); statement.addBatch("UPDATE task SET approved = false, isCompleted = true, assignedAdmin = " + adminId + " WHERE id = " + id + ";");
statement.executeBatch(); statement.executeBatch();
statement.close(); statement.close();
} catch (SQLException e) { } catch (SQLException e) {

View file

@ -17,31 +17,29 @@ import fr.insa_toulouse.mas.benevolat.ApproveService.model.Task;
public class ApproveServiceRessource { public class ApproveServiceRessource {
//@Autowired @Autowired
//private RestTemplate restTemplate; private RestTemplate restTemplate;
@GetMapping("getTasks/{adminId}") @GetMapping("getTasks/{adminId}")
public ArrayList<Task> getTasks(@PathVariable("adminId") Integer id) { public ArrayList<Task> getTasks(@PathVariable("adminId") Integer id) {
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) { if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + id, Boolean.class)) {
return Task.getTasks(); return Task.getTasks();
//} }
//return null; return null;
} }
@PutMapping("approveTask/{adminId}/{taskId}") @PutMapping("approveTask/{adminId}/{taskId}")
public void approveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) { public void approveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) {
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) { if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + adminId, Boolean.class)) {
Task.approveTask(taskId); Task.approveTask(taskId, adminId);
//} }
//return null;
} }
@PutMapping("disapproveTask/{adminId}/{taskId}") @PutMapping("disapproveTask/{adminId}/{taskId}")
public void disapproveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) { public void disapproveTask(@PathVariable("adminId") Integer adminId, @PathVariable("taskId") Integer taskId) {
//if (restTemplate.getForObject("http://Authentification/auth/isAdmin/" + id, Boolean.class)) { if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + adminId, Boolean.class)) {
Task.disapproveTask(taskId); Task.disapproveTask(taskId, adminId);
//} }
//return null;
} }
} }

View file

@ -1,2 +1,3 @@
spring.application.name=ApproveService spring.application.name=ApproveService
server.port=8092 server.port=8092
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

View file

@ -28,8 +28,13 @@
</scm> </scm>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@ -46,8 +51,27 @@
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>9.1.0</version> <version>9.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>

View file

@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class AuthenticationApplication { public class AuthenticationApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AuthenticationApplication.class, args); SpringApplication.run(AuthenticationApplication.class, args);

View file

@ -3,9 +3,14 @@ package fr.insa_toulouse.mas.benevolat.Authentication.ressource;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; 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; import fr.insa_toulouse.mas.benevolat.Authentication.model.User;
@RestController
@RequestMapping("auth")
public class AuthentificationResource { public class AuthentificationResource {
@PostMapping("add/{name}/{password}/{isAdmin}") @PostMapping("add/{name}/{password}/{isAdmin}")

View file

@ -1,2 +1,3 @@
spring.application.name=Authentication spring.application.name=Authentication
server.port=8091 server.port=8091
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

View file

@ -28,8 +28,13 @@
</scm> </scm>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
@ -56,6 +61,18 @@
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>

View file

@ -20,16 +20,14 @@ import fr.insa.mas.taskCreator.model.task;
public class taskRessource { public class taskRessource {
@PostMapping("propose/{condition}/{approval}/{assignedAdmin}/{assignedHelper}/{assignedRequester}/{Description}") @PostMapping("propose/{assignedHelper}/{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) { public void addTask(@PathVariable("assignedHelper") int Helperid, @PathVariable("description") String Description) {
task.saveTask(false, false, null, Helperid, null, Description); task.saveTask(false, false, null, Helperid, null, Description);
} }
@PostMapping("request/{condition}/{approval}/{assignedAdmin}/{assignedHelper}/{assignedRequester}/{Description}") @PostMapping("request/{assignedRequester}/{description}")
public void propTask(@PathVariable("condition") Boolean condition, @PathVariable("approval") Boolean approval , public void propTask(@PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
@PathVariable("assignedAdmin") int Adminid, @PathVariable("assignedHelper") int Helperid,
@PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
task.saveTask(false, false, null, null, Requesterid, Description); task.saveTask(false, false, null, null, Requesterid, Description);
} }

View file

@ -31,7 +31,7 @@ public class task {
} }
} }
public task(int id, boolean condition, boolean approval, int assignedAdmin, int assignedHelper, public task(Integer id, boolean condition, boolean approval, int assignedAdmin, int assignedHelper,
int assignedRequester, String description) { int assignedRequester, String description) {
super(); super();
this.id = id; this.id = id;
@ -49,10 +49,9 @@ public class task {
Integer assignedHelper, Integer assignedRequester,String Description ) { Integer assignedHelper, Integer assignedRequester,String Description ) {
Random rand = new Random(); Random rand = new Random();
int id = rand.nextInt(500000); int id = rand.nextInt(500000);
task task = new task(id, condition, approval, assignedAdmin, assignedHelper, assignedRequester, Description);
try { try {
Statement statement = (Statement) task.connection.createStatement(); Statement statement = (Statement) task.connection.createStatement();
statement.addBatch("INSERT INTO task (id, approved, assignedAdmin, helper, helped, description, isCompleted) VALUES ("+ id +", \"" + task.approval + "\",\"" + task.assignedAdmin + "\",\"" + task.assignedHelper + "\"," + task.assignedRequester +"\", " + task.Description + " );"); statement.addBatch("INSERT INTO task (id, approved, assignedAdmin, helper, helped, description, isCompleted) VALUES ("+ id +", " + approval + "," + assignedAdmin + "," + assignedHelper + "," + assignedRequester +", " + Description + ", 0 );");
statement.executeBatch(); statement.executeBatch();
statement.close(); statement.close();
}catch(SQLException e){ }catch(SQLException e){
@ -66,7 +65,7 @@ public class task {
Statement statement; Statement statement;
try { try {
statement = task.connection.createStatement(); statement = task.connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * from task WHERE helped = NULL AND isCompleted = FALSE"); ResultSet res = statement.executeQuery("SELECT * from task WHERE helped IS NULL AND isCompleted = 0;");
while (res.next()) { while (res.next()) {
unansweredTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"), unansweredTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"),
res.getInt("assignedAdmin"), res.getInt("helper"), res.getInt("assignedAdmin"), res.getInt("helper"),
@ -84,7 +83,7 @@ public class task {
Statement statement; Statement statement;
try { try {
statement = task.connection.createStatement(); statement = task.connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * from task WHERE helper = NULL AND isCompleted = FALSE"); ResultSet res = statement.executeQuery("SELECT * from task WHERE helper IS NULL AND isCompleted = 0;");
while (res.next()) { while (res.next()) {
unasignedTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"), unasignedTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"),
res.getInt("assignedAdmin"), res.getInt("helper"), res.getInt("assignedAdmin"), res.getInt("helper"),
@ -117,6 +116,8 @@ public class task {
try { try {
Statement statement = task.connection.createStatement(); Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET isCompleted = true WHERE id = " + id + ";"); statement.addBatch("UPDATE task SET isCompleted = true WHERE id = " + id + ";");
statement.executeBatch();
statement.close();
} catch(SQLException e){ } catch(SQLException e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -126,6 +127,8 @@ public class task {
try { try {
Statement statement = task.connection.createStatement(); Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET helper = " + helperid + " WHERE id = " + id + ";"); statement.addBatch("UPDATE task SET helper = " + helperid + " WHERE id = " + id + ";");
statement.executeBatch();
statement.close();
} catch(SQLException e){ } catch(SQLException e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -134,7 +137,9 @@ public class task {
static public void assignHelped(int id, int helpedid) { static public void assignHelped(int id, int helpedid) {
try { try {
Statement statement = task.connection.createStatement(); Statement statement = task.connection.createStatement();
statement.addBatch("UPDATE task SET helper = " + helpedid + " WHERE id = " + id + ";"); statement.addBatch("UPDATE task SET helped = " + helpedid + " WHERE id = " + id + ";");
statement.executeBatch();
statement.close();
} catch(SQLException e){ } catch(SQLException e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -1 +1,3 @@
spring.application.name=taskCreator spring.application.name=taskCreator
server.port=8093
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/