parent
bac009af8f
commit
bb19bca946
|
@ -1,5 +1,6 @@
|
||||||
package fr.itsonus.bousoleplussbackend.models;
|
package fr.itsonus.bousoleplussbackend.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -44,6 +45,7 @@ public class Axe {
|
||||||
|
|
||||||
@OneToMany(mappedBy = "axe")
|
@OneToMany(mappedBy = "axe")
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
|
@JsonIgnore
|
||||||
private Set<Question> questions;
|
private Set<Question> questions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class Question {
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "axe_id")
|
@JoinColumn(name = "axe_id")
|
||||||
@JsonIgnore
|
@ToString.Exclude
|
||||||
private Axe axe;
|
private Axe axe;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ -42,7 +42,6 @@ public class Question {
|
||||||
@Size(max = 200)
|
@Size(max = 200)
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Size(max = 500)
|
@Size(max = 500)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package fr.itsonus.bousoleplussbackend.projections;
|
|
||||||
|
|
||||||
import fr.itsonus.bousoleplussbackend.models.Axe;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.data.rest.core.config.Projection;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Projection(name = "axeWithQuestion", types = {Axe.class})
|
|
||||||
public interface AxeWithQuestion {
|
|
||||||
|
|
||||||
Integer getIdentifier();
|
|
||||||
|
|
||||||
String getShortTitle();
|
|
||||||
|
|
||||||
String getTitle();
|
|
||||||
|
|
||||||
String getDescription();
|
|
||||||
|
|
||||||
String getColor();
|
|
||||||
|
|
||||||
@Value("#{target.getQuestions()}")
|
|
||||||
List<QuestionProj> getQuestions();
|
|
||||||
}
|
|
|
@ -1,16 +1,11 @@
|
||||||
package fr.itsonus.bousoleplussbackend.repositories;
|
package fr.itsonus.bousoleplussbackend.repositories;
|
||||||
|
|
||||||
import fr.itsonus.bousoleplussbackend.models.Axe;
|
import fr.itsonus.bousoleplussbackend.models.Axe;
|
||||||
import fr.itsonus.bousoleplussbackend.projections.AxeWithQuestion;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
|
||||||
|
|
||||||
@RepositoryRestResource(excerptProjection = AxeWithQuestion.class)
|
@RepositoryRestResource
|
||||||
public interface AxeRepository extends CrudRepository<Axe, Long> {
|
public interface AxeRepository extends CrudRepository<Axe, Long>, JpaSpecificationExecutor<Axe> {
|
||||||
|
|
||||||
@RestResource(path = "me", rel = "me")
|
|
||||||
@Query("SELECT DISTINCT a FROM Axe a INNER JOIN a.questions as q WHERE q.userId = ?#{principal.id}")
|
|
||||||
Iterable<Axe> findAllWithQuestionsOfCurrentUser();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
import org.springframework.data.rest.core.annotation.RestResource;
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@RepositoryRestResource
|
@RepositoryRestResource
|
||||||
public interface QuestionRepository extends CrudRepository<Question, Long> {
|
public interface QuestionRepository extends CrudRepository<Question, Long> {
|
||||||
|
@ -14,4 +13,5 @@ public interface QuestionRepository extends CrudRepository<Question, Long> {
|
||||||
@RestResource(path="byAxeId", rel="byAxeId")
|
@RestResource(path="byAxeId", rel="byAxeId")
|
||||||
@Query("SELECT q FROM Question q JOIN q.axe a WHERE q.axe.id = :id AND user_id = ?#{principal.id}")
|
@Query("SELECT q FROM Question q JOIN q.axe a WHERE q.axe.id = :id AND user_id = ?#{principal.id}")
|
||||||
Iterable<Question> findAllByAxeId(@Param("id") final Long id);
|
Iterable<Question> findAllByAxeId(@Param("id") final Long id);
|
||||||
|
|
||||||
}
|
}
|
|
@ -44,7 +44,7 @@
|
||||||
import {AxiosResponse} from "axios";
|
import {AxiosResponse} from "axios";
|
||||||
import {Component, Vue} from "nuxt-property-decorator";
|
import {Component, Vue} from "nuxt-property-decorator";
|
||||||
import {RepositoryFactory} from "~/repositories/RepositoryFactory";
|
import {RepositoryFactory} from "~/repositories/RepositoryFactory";
|
||||||
import {AxeWithQuestions} from "~/repositories/models/axe.model";
|
import {Axe} from "~/repositories/models/axe.model";
|
||||||
import {RestResponse} from "~/repositories/models/rest-response.model";
|
import {RestResponse} from "~/repositories/models/rest-response.model";
|
||||||
import {Question} from "~/repositories/models/question.model";
|
import {Question} from "~/repositories/models/question.model";
|
||||||
import {Quiz} from "~/repositories/models/quiz.model";
|
import {Quiz} from "~/repositories/models/quiz.model";
|
||||||
|
@ -54,9 +54,10 @@ import {quizStore} from "~/utils/store-accessor";
|
||||||
export default class Login extends Vue {
|
export default class Login extends Vue {
|
||||||
|
|
||||||
readonly axeRepository = RepositoryFactory.get("axe");
|
readonly axeRepository = RepositoryFactory.get("axe");
|
||||||
|
readonly questionRepository = RepositoryFactory.get("question");
|
||||||
|
|
||||||
private axes: AxeWithQuestions[] = [];
|
private axes: Axe[] = [];
|
||||||
private currentAxe?: AxeWithQuestions | undefined;
|
private currentAxe?: Axe | undefined;
|
||||||
private currentAxeIdentifier = 1;
|
private currentAxeIdentifier = 1;
|
||||||
private questions: Map<number, Question[]> = new Map<number, []>();
|
private questions: Map<number, Question[]> = new Map<number, []>();
|
||||||
private loading = true;
|
private loading = true;
|
||||||
|
@ -67,17 +68,28 @@ export default class Login extends Vue {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.axeRepository
|
this.axeRepository
|
||||||
.findAll()
|
.findAll()
|
||||||
.then((response: AxiosResponse<RestResponse<AxeWithQuestions>>) => {
|
.then((response: AxiosResponse<RestResponse<Axe>>) => {
|
||||||
this.axes = response.data._embedded.axes;
|
this.axes = response.data._embedded.axes;
|
||||||
|
const promises: any[] = [];
|
||||||
this.axes.forEach(axe => {
|
this.axes.forEach(axe => {
|
||||||
this.questions.set(axe.identifier, axe.questions);
|
promises.push(
|
||||||
|
this.questionRepository
|
||||||
|
.findAllByAxeId(axe.identifier)
|
||||||
|
.then((response: AxiosResponse<RestResponse<Question>>) => {
|
||||||
|
return {
|
||||||
|
axeId: axe.identifier,
|
||||||
|
questions: response.data._embedded.questions
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
Promise.all(promises).then((axeQuestions) => {
|
||||||
|
axeQuestions.forEach(axeQuestion => {
|
||||||
|
this.questions.set(axeQuestion.axeId, axeQuestion.questions)
|
||||||
|
});
|
||||||
|
quizStore.initialize(this.questions);
|
||||||
|
this.initializeState();
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
this.initializeState();
|
|
||||||
quizStore.initialize(this.questions);
|
|
||||||
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.loading = false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import AxeRepository from "./axeRepository";
|
import AxeRepository from "./axeRepository";
|
||||||
import QuestionRepository from "~/repositories/questionRepository";
|
|
||||||
import QuizRepository from "~/repositories/quizRepository";
|
import QuizRepository from "~/repositories/quizRepository";
|
||||||
|
import QuestionRepository from "~/repositories/questionRepository";
|
||||||
|
|
||||||
const repositories = {
|
const repositories = {
|
||||||
axe: AxeRepository,
|
axe: AxeRepository,
|
||||||
question: QuestionRepository,
|
|
||||||
quiz: QuizRepository,
|
quiz: QuizRepository,
|
||||||
|
question: QuestionRepository,
|
||||||
// other repositories ...
|
// other repositories ...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {RestResponse} from "~/repositories/models/rest-response.model";
|
import {RestResponse} from "~/repositories/models/rest-response.model";
|
||||||
import {$axios} from "~/utils/api";
|
import {$axios} from "~/utils/api";
|
||||||
import {AxeWithQuestions} from "~/repositories/models/axe.model";
|
import {Axe} from "~/repositories/models/axe.model";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
findAll() {
|
findAll() {
|
||||||
return $axios.get<RestResponse<AxeWithQuestions>>("/axes/search/me");
|
return $axios.get<RestResponse<Axe>>("/axes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
response.data._embedded.questions.forEach(question => {
|
response.data._embedded.questions.forEach(question => {
|
||||||
question.id = Number(question._links.self.href.split("/").reverse()[0]);
|
question.id = Number(question._links.self.href.split("/").reverse()[0]);
|
||||||
return question;
|
return question;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
});
|
});
|
||||||
return response;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue