Skip to content

Commit

Permalink
Merge pull request #15 from AlexisClone/master
Browse files Browse the repository at this point in the history
BF7 - Authentification
  • Loading branch information
frjaunatre_sodius authored Jan 9, 2020
2 parents 74de028 + bd27971 commit 1f0a1c8
Show file tree
Hide file tree
Showing 26 changed files with 277 additions and 75 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@ This project aims at providing the backend services to be used to support a spor
## Default testing data
Testing data is declared in `import.sql`.

To load data on first start or to reset data with defaults, change `spring.jpa.hibernate.ddl-auto` property value (in `application.properties`) with either `create` or `create-drop`.
To load data on first start or to reset data with defaults, change `spring.jpa.hibernate.ddl-auto` property value (in `application.properties`) with either `create` or `create-drop`.

## Installation

### Requirements

- Java
- Meaven

### Installation

1. Clone or Download this repository.
2. Enter the repository.
3. Run server : `mvn spring-boot:run`
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
<scope>runtime</scope>
</dependency>

<!-- H2 CONSOLE -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- For Working with Json Web Tokens (JWT) -->

<!-- For Working with Json Web Tokens (JWT) -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ public static void main(String[] args) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected PasswordEncoder getPasswordEncoder() {

@Override
protected void configure(HttpSecurity http) throws Exception {

// H2 web console need this
http.headers().frameOptions().sameOrigin();

//@formatter:off
http
.cors()
Expand Down Expand Up @@ -80,6 +84,9 @@ protected void configure(HttpSecurity http) throws Exception {
.permitAll()
.antMatchers("/user/checkUsernameAvailability", "/user/checkEmailAvailability")
.permitAll()
// TODO remove H2 console public access
.antMatchers("/h2-console/**")
.permitAll()
.antMatchers(HttpMethod.GET, "/groups/**", "/users/**")
.permitAll()
.anyRequest()
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/fr/kungfunantes/backend/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
resolver = EntityIdResolver.class,
scope = Account.class)
public class Account {

public enum AccountPrivilege {
TEACHER,
NONE
Expand All @@ -32,10 +33,6 @@ public enum AccountPrivilege {
@Enumerated(EnumType.STRING)
private AccountPrivilege privilege;

@Repository
public static interface AccountRepository extends JpaRepository<Account, Long> {
}

public Long getId() {
return id;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fr/kungfunantes/backend/model/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ public void setId(Long id) {
this.id = id;
}

public String getFirstname() {
public String getFirstName() {
return firstname;
}

public void setFirstname(String firstname) {
public void setFirstName(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
public String getLastName() {
return lastname;
}

public void setLastname(String lastname) {
public void setLastName(String lastname) {
this.lastname = lastname;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package fr.kungfunantes.backend.model.criteria;

import io.swagger.annotations.ApiModel;
import fr.kungfunantes.backend.model.exercise.taolu.Taolu;
import fr.kungfunantes.backend.model.exercise.ExerciseCriteria;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import java.util.List;

@Entity
@ApiModel
Expand All @@ -15,6 +18,9 @@ public class Criteria {
private Long id;
private String name;

@OneToMany
List<ExerciseCriteria> exerciseCriteria;

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ public Category getCategory() {
public void setCategory(Category category) {
this.category = category;
}

public abstract String getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.kungfunantes.backend.model.exercise;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import io.swagger.annotations.ApiModel;

import fr.kungfunantes.backend.model.exercise.taolu.Taolu;
import fr.kungfunantes.backend.model.criteria.Criteria;

@Entity
@ApiModel
public class ExerciseCriteria {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@ManyToOne
@JoinColumn(name = "exerciseId")
Taolu taolu;

@ManyToOne
@JoinColumn(name = "criteriaId")
Criteria criteria;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.kungfunantes.backend.model.exercise;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import io.swagger.annotations.ApiModel;

import fr.kungfunantes.backend.model.exercise.fight.Fight;
import fr.kungfunantes.backend.model.round.Round;

@Entity
@ApiModel
public class ExerciseRound {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@ManyToOne
@JoinColumn(name = "exerciseId")
Fight fight;

@ManyToOne
@JoinColumn(name = "roundId")
Round round;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package fr.kungfunantes.backend.model.exercise.fight;

import fr.kungfunantes.backend.model.exercise.ExerciseRound;
import fr.kungfunantes.backend.model.exercise.Exercise;
import fr.kungfunantes.backend.model.round.Round;
import io.swagger.annotations.ApiModel;

import javax.persistence.*;
import java.util.Set;
import java.util.List;

@Entity
@ApiModel
@DiscriminatorValue(value = "FIGHT")
public class Fight extends Exercise {
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "exercise_round",
joinColumns = @JoinColumn(name = "exerciseId"),
inverseJoinColumns = @JoinColumn(name = "roundId")
)
private Set<Round> rounds;
@OneToMany
List<ExerciseRound> exerciseRound;

public Set<Round> getRounds() {
return rounds;
}

public void setRounds(Set<Round> rounds) {
this.rounds = rounds;
public String getType() {
return "FIGHT";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public MeasurementUnit getMeasurementUnit() {
public void setMeasurementUnit(MeasurementUnit measurementUnit) {
this.measurementUnit = measurementUnit;
}

public String getType() {
return "PHYSICAL";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

import fr.kungfunantes.backend.model.criteria.Criteria;
import fr.kungfunantes.backend.model.exercise.Exercise;
import fr.kungfunantes.backend.model.exercise.ExerciseCriteria;
import io.swagger.annotations.ApiModel;

import javax.persistence.*;
import java.util.Set;
import java.util.List;

@Entity
@ApiModel
@DiscriminatorValue(value = "TAOLU")
public class Taolu extends Exercise {
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "exercise_criteria",
joinColumns = @JoinColumn(name = "exerciseId"),
inverseJoinColumns = @JoinColumn(name = "criteriaId")
)
private Set<Criteria> criterion;
@OneToMany
List<ExerciseCriteria> exerciseCriteria;

public Set<Criteria> getCriterion() {
return criterion;
}

public void setCriterion(Set<Criteria> criterion) {
this.criterion = criterion;
public String getType() {
return "TAOLU";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public String getQuestion() {
public void setQuestion(String question) {
this.question = question;
}

public String getType() {
return "THEORETICAL";
}
}
5 changes: 5 additions & 0 deletions src/main/java/fr/kungfunantes/backend/model/round/Round.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.kungfunantes.backend.model.round;

import fr.kungfunantes.backend.model.criteria.Criteria;
import fr.kungfunantes.backend.model.exercise.ExerciseRound;
import io.swagger.annotations.ApiModel;

import javax.persistence.*;
import java.util.List;
import java.util.Set;

@Entity
Expand All @@ -13,6 +15,9 @@ public class Round {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany
List<ExerciseRound> exerciseRound;

@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "round_criteria",
joinColumns = @JoinColumn(name = "roundId"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.kungfunantes.backend.repository;

import fr.kungfunantes.backend.model.criteria.Criteria;
import fr.kungfunantes.backend.model.exercise.Exercise;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;

@Repository
public interface ExerciseCriteriaRepository extends JpaRepository<Exercise, Long>{
@Modifying
@Query("delete from ExerciseCriteria where exerciseId = :idDelete")
public void deleteById(@Param("idDelete") Long idDelete);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

import fr.kungfunantes.backend.model.exercise.Exercise;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ExerciseRepository extends JpaRepository<Exercise, Long>{
@Modifying
@Query("delete from Exercise where id = :idDelete")
public void deleteById(@Param("idDelete") Long idDelete);

Optional<Exercise> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.kungfunantes.backend.repository;

import fr.kungfunantes.backend.model.round.Round;
import fr.kungfunantes.backend.model.exercise.Exercise;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;

@Repository
public interface ExerciseRoundRepository extends JpaRepository<Exercise, Long>{
@Modifying
@Query("delete from ExerciseRound where exerciseId = :idDelete")
public void deleteById(@Param("idDelete") Long idDelete);
}
Loading

0 comments on commit 1f0a1c8

Please sign in to comment.