Added init.sql. Added 'get_roles' REST api.

This commit is contained in:
Yohan Boujon 2024-12-20 09:47:01 +01:00
parent 69a48d949f
commit 5e5c599338
7 changed files with 127 additions and 0 deletions

5
db/init.sql Normal file
View file

@ -0,0 +1,5 @@
INSERT INTO `service-architecture`.roles (id, name)
VALUES
(1, 'user'),
(2, 'volunteer'),
(3, 'admin');

View file

@ -12,6 +12,7 @@
<module>volunteer-service</module> <module>volunteer-service</module>
<module>feedback-service</module> <module>feedback-service</module>
<module>administration-service</module> <module>administration-service</module>
<module>role-service</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>

View file

@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>insa.application.helpapp</groupId>
<artifactId>helpapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>role-service</artifactId>
<dependencies>
<!-- Dépendance pour créer un service REST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Plugin Maven pour Spring Boot -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.4</version>
</plugin>
<!-- Plugin pour configurer le compilateur -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,30 @@
package insa.application.helpapp.rest;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "roles", schema = "service-architecture")
public class Role {
@Id
private int id;
private String name;
// Getters and Setters
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View file

@ -0,0 +1,6 @@
package insa.application.helpapp.rest;
import org.springframework.data.jpa.repository.JpaRepository;
public interface RoleRepository extends JpaRepository<Role, Integer> {
}

View file

@ -0,0 +1,28 @@
package insa.application.helpapp.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@SpringBootApplication
@RestController
public class RoleServiceApplication {
@Autowired
private RoleRepository roleRepository;
public static void main(String[] args) {
SpringApplication.run(RoleServiceApplication.class, args);
}
@GetMapping("/get_roles")
public List<Role> getRoles() {
return roleRepository.findAll();
}
}

View file

@ -0,0 +1,7 @@
server.port=8089
spring.datasource.url=jdbc:mysql://localhost:3306/service-architecture
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect