Setup database schema
This commit is contained in:
@@ -18,7 +18,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'jakarta.validation:jakarta.validation-api:3.0.2'
|
||||
implementation 'org.hibernate.validator:hibernate-validator:8.0.0.Final'
|
||||
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.28'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package be.naaturel.letsmeet.configurations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppConfigurations {
|
||||
|
||||
@Value("${sec.cors.authorizedHots}")
|
||||
public String[] authorizedHosts;
|
||||
|
||||
@Value("${sec.cors.authorizedMethods}")
|
||||
public String[] authorizedMethods;
|
||||
|
||||
@Value("${sec.cors.authorizedHeader}")
|
||||
public String[] authorizedHeaders;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package be.naaturel.letsmeet.configurations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class AppSecurity {
|
||||
|
||||
private final AppConfigurations conf;
|
||||
|
||||
@Autowired
|
||||
public AppSecurity(AppConfigurations appConf) {
|
||||
this.conf = appConf;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
|
||||
return http
|
||||
.cors(cors -> {})
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests((requests) -> requests
|
||||
.requestMatchers("/**" ).permitAll()
|
||||
//.anyRequest().authenticated()
|
||||
)
|
||||
.formLogin((form) -> form
|
||||
.defaultSuccessUrl("/", true)
|
||||
.permitAll()
|
||||
)
|
||||
.logout(LogoutConfigurer::permitAll)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowedOrigins(Arrays.asList(conf.authorizedHosts));
|
||||
config.setAllowedMethods(Arrays.asList(conf.authorizedMethods));
|
||||
config.setAllowedHeaders(Arrays.asList(conf.authorizedHeaders));
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package be.naaturel.letsmeet.controllers;
|
||||
|
||||
import be.naaturel.letsmeet.models.Event;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class EventController {
|
||||
|
||||
@Autowired
|
||||
public EventController(){
|
||||
}
|
||||
|
||||
@PostMapping({"/create", "/create/"})
|
||||
public ResponseEntity<?> submit(@RequestBody Event e){
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@GetMapping({"/join", "/join/"})
|
||||
public ResponseEntity<?> leaderboard(){
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package be.naaturel.letsmeet.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static jakarta.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity(name = "Date")
|
||||
public class DateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
public String id;
|
||||
|
||||
@Column
|
||||
public String name;
|
||||
|
||||
@Column
|
||||
public long timeStamp;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="eventId", nullable=false)
|
||||
public EventEntity event;
|
||||
|
||||
@OneToMany(targetEntity= ParticipantEntity.class, cascade=ALL, mappedBy="id")
|
||||
public Set<ParticipantEntity> participants;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package be.naaturel.letsmeet.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static jakarta.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity(name = "Event")
|
||||
public class EventEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
public String id;
|
||||
|
||||
@Column
|
||||
@OneToMany(targetEntity= DateEntity.class, cascade=ALL, mappedBy="event")
|
||||
public Set<DateEntity> timeStamps;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package be.naaturel.letsmeet.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity(name = "Participant")
|
||||
public class ParticipantEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
public String id;
|
||||
|
||||
@Column
|
||||
public String name;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="dateId", nullable=false)
|
||||
public DateEntity date;
|
||||
|
||||
}
|
||||
7
back/src/main/java/be/naaturel/letsmeet/models/Date.java
Normal file
7
back/src/main/java/be/naaturel/letsmeet/models/Date.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package be.naaturel.letsmeet.models;
|
||||
|
||||
public class Date {
|
||||
|
||||
private long timestamp;
|
||||
|
||||
}
|
||||
12
back/src/main/java/be/naaturel/letsmeet/models/Event.java
Normal file
12
back/src/main/java/be/naaturel/letsmeet/models/Event.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package be.naaturel.letsmeet.models;
|
||||
|
||||
public class Event {
|
||||
|
||||
private String name;
|
||||
private long[] timestamp;
|
||||
|
||||
public Event(String name, long[] timestamp){
|
||||
this.name = name;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package be.naaturel.letsmeet.repositories;
|
||||
|
||||
public class EventRepo {
|
||||
}
|
||||
@@ -1 +1,20 @@
|
||||
#=============MAIN=============
|
||||
spring.application.name=letsmeet
|
||||
|
||||
#=============SERVER=============
|
||||
server.port=5000
|
||||
|
||||
#=============SECURITY=============
|
||||
sec.cors.authorizedHots=*
|
||||
sec.cors.authorizedMethods=GET,POST,PUT,DELETE,OPTION
|
||||
sec.cors.authorizedHeader=Authorization,Content-type
|
||||
|
||||
#=============DATABASE=============
|
||||
spring.datasource.url=jdbc:${DB_URL}
|
||||
spring.datasource.username=${DB_USER}
|
||||
spring.datasource.password=${DB_PASSWORD}
|
||||
|
||||
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.user.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
@@ -6,8 +6,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
@SpringBootTest
|
||||
class LetsmeetApplicationTests {
|
||||
|
||||
@Test
|
||||
/*@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user