backend-api #6
@ -1,33 +1,35 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '3.4.2'
|
id 'org.springframework.boot' version '3.4.2'
|
||||||
id 'io.spring.dependency-management' version '1.1.7'
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'enseirb'
|
group = 'enseirb'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion = JavaLanguageVersion.of(21)
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
|
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
|
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
|
||||||
implementation 'org.postgresql:postgresql'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.16.0'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.16.0'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
implementation 'org.postgresql:postgresql'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package enseirb.myinpulse.service.database;
|
||||||
|
|
||||||
|
public class AdministratorService {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package enseirb.myinpulse.service.database;
|
||||||
|
|
||||||
|
public class UserService {
|
||||||
|
}
|
@ -1,38 +0,0 @@
|
|||||||
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
|
|
||||||
|
|
||||||
import enseirb.myinpulse.model.Administrator;
|
|
||||||
import enseirb.myinpulse.repository.AdministratorRepository;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class AdministratorController {
|
|
||||||
|
|
||||||
@Autowired AdministratorRepository administratorRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Administrator")
|
|
||||||
@ResponseBody
|
|
||||||
public Iterable<Administrator> allAdministrators() {
|
|
||||||
return this.administratorRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/Administrator/{id}")
|
|
||||||
public Administrator getAdministratorById(@PathVariable Long id) {
|
|
||||||
Optional<Administrator> administrator = this.administratorRepository.findById(id);
|
|
||||||
if (administrator.isEmpty()) {
|
|
||||||
throw new ResponseStatusException(
|
|
||||||
HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas");
|
|
||||||
}
|
|
||||||
return administrator.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/Administrateurs")
|
|
||||||
public Administrator addAdministrator(@RequestBody Administrator administrator) {
|
|
||||||
return this.administratorRepository.save(administrator);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
|
|
||||||
|
|
||||||
import enseirb.myinpulse.model.User;
|
|
||||||
import enseirb.myinpulse.repository.UserRepository;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
@Autowired UserRepository userRepository;
|
|
||||||
|
|
||||||
@GetMapping("/User")
|
|
||||||
@ResponseBody
|
|
||||||
public Iterable<User> allUsers() {
|
|
||||||
return this.userRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/User/{id}")
|
|
||||||
public User getUserById(@PathVariable Long id) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
if (user.isEmpty()) {
|
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
|
|
||||||
}
|
|
||||||
return user.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/User")
|
|
||||||
public User addUser(@RequestBody User user) {
|
|
||||||
return this.userRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/User/{id}")
|
|
||||||
public User updateUser(
|
|
||||||
@PathVariable Long id,
|
|
||||||
String userSurname,
|
|
||||||
String userName,
|
|
||||||
String mainMail,
|
|
||||||
String secondaryMail,
|
|
||||||
String phoneNumber) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
if (user.isEmpty()) {
|
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
|
|
||||||
}
|
|
||||||
if (userName != null) {
|
|
||||||
user.get().setUserName(userName);
|
|
||||||
}
|
|
||||||
if (userSurname != null) {
|
|
||||||
user.get().setUserSurname(userSurname);
|
|
||||||
}
|
|
||||||
if (mainMail != null) {
|
|
||||||
user.get().setMainMail(mainMail);
|
|
||||||
}
|
|
||||||
if (secondaryMail != null) {
|
|
||||||
user.get().setSecondaryMail(secondaryMail);
|
|
||||||
}
|
|
||||||
if (phoneNumber != null) {
|
|
||||||
user.get().setPhoneNumber(phoneNumber);
|
|
||||||
}
|
|
||||||
return this.userRepository.save(user.get());
|
|
||||||
}
|
|
||||||
}
|
|
14
MyINPulse-back/src/main/resources/log4j2.xml
Normal file
14
MyINPulse-back/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="INFO">
|
||||||
|
<Appenders>
|
||||||
|
<Console name="console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
|
</Console>
|
||||||
|
</Appenders>
|
||||||
|
|
||||||
|
<Loggers>
|
||||||
|
<Root level="trace">
|
||||||
|
<AppenderRef ref="console"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
Loading…
x
Reference in New Issue
Block a user