discovery done
This commit is contained in:
parent
878acabdf1
commit
15097f2def
13 changed files with 137 additions and 31 deletions
|
@ -28,8 +28,13 @@
|
|||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
@ -47,7 +52,27 @@
|
|||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.1.0</version>
|
||||
</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>
|
||||
|
||||
<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>
|
||||
<plugins>
|
||||
|
@ -57,5 +82,25 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</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>
|
||||
|
|
|
@ -2,9 +2,18 @@ package fr.insa_toulouse.mas.benevolat.ApproveService;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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
|
||||
public class ApproveServiceApplication {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApproveServiceApplication.class, args);
|
||||
|
|
|
@ -60,10 +60,10 @@ public class Task {
|
|||
return tasks;
|
||||
}
|
||||
|
||||
static public void approveTask(int id) {
|
||||
static public void approveTask(int id, int adminId) {
|
||||
try {
|
||||
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.close();
|
||||
} 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 {
|
||||
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.close();
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -17,31 +17,29 @@ import fr.insa_toulouse.mas.benevolat.ApproveService.model.Task;
|
|||
public class ApproveServiceRessource {
|
||||
|
||||
|
||||
//@Autowired
|
||||
//private RestTemplate restTemplate;
|
||||
@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)) {
|
||||
if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + id, Boolean.class)) {
|
||||
return Task.getTasks();
|
||||
//}
|
||||
//return null;
|
||||
}
|
||||
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;
|
||||
if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + adminId, Boolean.class)) {
|
||||
Task.approveTask(taskId, adminId);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
if (restTemplate.getForObject("http://Authentication/auth/isAdmin/" + adminId, Boolean.class)) {
|
||||
Task.disapproveTask(taskId, adminId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
spring.application.name=ApproveService
|
||||
server.port=8092
|
||||
server.port=8092
|
||||
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
|
|
@ -28,8 +28,13 @@
|
|||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
@ -46,8 +51,27 @@
|
|||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.1.0</version>
|
||||
</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>
|
||||
<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>
|
||||
<plugins>
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
@SpringBootApplication
|
||||
public class AuthenticationApplication {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AuthenticationApplication.class, args);
|
||||
|
|
|
@ -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.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}")
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
spring.application.name=Authentication
|
||||
server.port=8091
|
||||
server.port=8091
|
||||
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
|
|
@ -28,8 +28,13 @@
|
|||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2024.0.0-M2</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
@ -56,6 +61,18 @@
|
|||
|
||||
|
||||
</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>
|
||||
<plugins>
|
||||
|
|
|
@ -20,16 +20,14 @@ 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 Adminid, @PathVariable("assignedHelper") int Helperid, @PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
|
||||
@PostMapping("propose/{assignedHelper}/{description}")
|
||||
public void addTask(@PathVariable("assignedHelper") int Helperid, @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 Adminid, @PathVariable("assignedHelper") int Helperid,
|
||||
@PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
|
||||
@PostMapping("request/{assignedRequester}/{description}")
|
||||
public void propTask(@PathVariable("assignedRequester") int Requesterid, @PathVariable("description") String Description) {
|
||||
task.saveTask(false, false, null, null, Requesterid, Description);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
@ -49,10 +49,9 @@ public class task {
|
|||
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);
|
||||
try {
|
||||
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.close();
|
||||
}catch(SQLException e){
|
||||
|
@ -66,7 +65,7 @@ public class task {
|
|||
Statement statement;
|
||||
try {
|
||||
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()) {
|
||||
unansweredTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"),
|
||||
res.getInt("assignedAdmin"), res.getInt("helper"),
|
||||
|
@ -84,7 +83,7 @@ public class task {
|
|||
Statement statement;
|
||||
try {
|
||||
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()) {
|
||||
unasignedTasks.add(new task(res.getInt("id"), res.getBoolean("isCompleted"), res.getBoolean("approved"),
|
||||
res.getInt("assignedAdmin"), res.getInt("helper"),
|
||||
|
@ -117,6 +116,8 @@ public class task {
|
|||
try {
|
||||
Statement statement = task.connection.createStatement();
|
||||
statement.addBatch("UPDATE task SET isCompleted = true WHERE id = " + id + ";");
|
||||
statement.executeBatch();
|
||||
statement.close();
|
||||
} catch(SQLException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -126,6 +127,8 @@ public class task {
|
|||
try {
|
||||
Statement statement = task.connection.createStatement();
|
||||
statement.addBatch("UPDATE task SET helper = " + helperid + " WHERE id = " + id + ";");
|
||||
statement.executeBatch();
|
||||
statement.close();
|
||||
} catch(SQLException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -134,7 +137,9 @@ public class task {
|
|||
static public void assignHelped(int id, int helpedid) {
|
||||
try {
|
||||
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){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
spring.application.name=taskCreator
|
||||
server.port=8093
|
||||
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
|
Loading…
Reference in a new issue