Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
84eba79
antes de mudar config doctrine
Sep 6, 2022
4b7b582
restaura config app e database para padrao
Sep 6, 2022
73562ec
Adiciona rota de criacao, e delete de materias. Juntamente com boiler…
Sep 11, 2022
ef5653a
adiciona rota para criar, procurar e deletar estudantes. Bem como rep…
Sep 11, 2022
be4b05a
encerra entidades e relacoes entre elas v0.1
Sep 15, 2022
f5a7d16
teste
Sep 15, 2022
95fefe1
teste
Sep 15, 2022
64b122d
Merge pull request #1 from lzzhenrique/boilerplate-doctrine
lzzhenrique Sep 15, 2022
291a67c
add subject controller, and repository
Sep 15, 2022
c6b01e6
commit bomba atomica
Sep 21, 2022
f7ac8ed
antes do pivot para usar uma tabela de examAndAnswer
Sep 22, 2022
58f61e1
antes de alterar para arrayCollection
Sep 26, 2022
4bd10a7
cria rota de criacao e devolucao da prova
Sep 27, 2022
2522821
Merge pull request #2 from lzzhenrique/subject-route
lzzhenrique Sep 27, 2022
cc987e7
limpa arquivo de rotas web
Sep 27, 2022
13e0043
adiciona rota para receber respostas
Sep 27, 2022
5ed5c44
muda timezone da aplicacao para America/SP
Sep 27, 2022
edfb76c
cria controller para receber respostas
Sep 27, 2022
87e7329
define retorno da funcao getExamById para um Exam
Sep 27, 2022
abd73d2
cria validacao para nao processar provas com mais de uma hora de dife…
Sep 27, 2022
e6e9b69
modifica campo de score para float em vez de int
Sep 28, 2022
580b444
cria metodo para finalizar exame
Sep 28, 2022
46c46d5
cria metodo que pega questoes corretas por exam
Sep 28, 2022
a0935fa
cria metodo que pega registra resposta do aluno
Sep 28, 2022
1ce7390
cria metodo que pega conta as respostas corretas do aluno
Sep 28, 2022
5a1bbef
registra resposta do studen
Sep 28, 2022
43c2bdc
calcula resultado do exame
Sep 28, 2022
ab5867a
encerra exame
Sep 28, 2022
760cbc7
retorna snapshot da prova concluida
Sep 29, 2022
2887423
Merge pull request #3 from lzzhenrique/process-exam
lzzhenrique Sep 29, 2022
c5a4027
evita que uma questao possa ter mais de uma resposta correta
Sep 29, 2022
b3ff082
Merge pull request #4 from lzzhenrique/questionMustBeOneCorrectAnswer
lzzhenrique Sep 29, 2022
5c5c4e7
add tests to studentService
Oct 5, 2022
7c8bcf2
add tests to subjectService
Oct 5, 2022
a51cb37
renomeia variavel
Oct 5, 2022
652096e
adiciona testes ao service de questions
Oct 5, 2022
1626616
muda nome de testes em studen e subject test
Oct 5, 2022
384e73b
retira import inutil de answerRepository
Oct 5, 2022
250dc9b
modifica forma de validacao da request de answer
Oct 5, 2022
9af67d4
retira comentarios do test
Oct 5, 2022
5e50f57
adiciona testes ao service de answer
Oct 5, 2022
95abb85
muda forma de verificacao da request de examCreate
Oct 6, 2022
7c5eb54
typa retorno da funcao getById
Oct 6, 2022
7dc3239
retira funcao inutil
Oct 6, 2022
e63884a
assina retorno do metodo create Snapshot
Oct 6, 2022
9b0fcd5
retorna metodo getAnswers de Question
Oct 6, 2022
7ce0074
sobrepoe metodo createdAt para poder testalo
Oct 6, 2022
8c1bb93
litte bomb
Oct 6, 2022
d43e718
organiza cria testes para createExamService
Oct 6, 2022
7772d99
testa excecoes ao criar um exame
Oct 6, 2022
d325648
cria arquivo de para testar updateExamServiceTest
Oct 6, 2022
52690c6
renomeia nomes das classes de teste para melhor compreensao
Oct 6, 2022
d2242e9
garante que score nao pode ser nulo ou menor que zero
Oct 7, 2022
5e121d2
testa caso de sucesso em update exam
Oct 7, 2022
04c85a9
adiciona teste na exception de updateExamService
Oct 7, 2022
a5a0a94
adiciona teste de sucesso em SnapshotService
Oct 7, 2022
430928e
retira mock inutilizado do teste
Oct 14, 2022
7eba134
muda funcao de ordenacao para publica para poder testar
Oct 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY .docker/etc /etc

RUN chmod -v +x /usr/sbin/entrypoint.local; \
chmod -v +x /usr/sbin/update-application; \
mkdir /var/www/storage/proxies; \
# mkdir /var/www/storage/proxies; \
chmod 777 /var/www/bootstrap -Rf; \
chmod 777 /var/www/storage -Rf; \
chown apache.apache /var/www -Rf;
Expand Down
60 changes: 60 additions & 0 deletions app/Http/Controllers/AnswerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Http\Controllers;


use App\Models\Question;
use App\Repositorys\QuestionRepository;
use App\Services\AnswerService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Errors\ErrorHandler;

class AnswerController extends Controller
{
protected QuestionRepository $questionRepository;
protected AnswerService $answerService;

public function __construct(AnswerService $answerService, QuestionRepository $questionRepository)
{
$this->answerService = $answerService;
$this->questionRepository = $questionRepository;
}

public function store(Request $request): JsonResponse
{
try{
$this->validateAnswerRequest($request->get('question_id'), $request->get('is_correct'));

$answer = $this->answerService
->create(
$request->get('answer'),
$request->get('question_id'),
$request->get('is_correct')
);

return response()->json([
'message' => 'The answer ' . $answer->getAnswer() . ' are created successfully'
]);

}catch (\Exception $e){
ErrorHandler::handleException($e);
}
}

private function validateAnswerRequest($questionId, $isCorrect)
{
/**
* @var Question $question
*/
$question = $this->questionRepository->getById($questionId);

if(!$question){
throw new \Exception("The question with id $questionId not exists");
}

if($isCorrect === true && $question->hasCorrectAnswer()){
throw new \Exception("The question already have a correct answer. The max amount of correct answers is 1");
}
}
}
51 changes: 51 additions & 0 deletions app/Http/Controllers/ExamController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\Controllers;


use App\Http\Errors\ErrorHandler;
use App\Services\ExamService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

class ExamController
{
protected ExamService $examService;

public function __construct(ExamService $examService)
{
$this->examService = $examService;
}

public function store(Request $request): JsonResponse
{
try{
$exam = $this->examService->create(
$request->get('student_id'),
$request->get('subject_id'),
$request->get('question_quantity')
);

return response()->json($exam);


}catch (\Exception $e){
ErrorHandler::handleException($e);
}
}

public function update(Request $request, $exam): JsonResponse
{
try{
$examResult = $this->examService->update(
$exam,
$request->get('answers'),
$request->get('finishedAt'),
);

return response()->json($examResult);
}catch (\Exception $e){
ErrorHandler::handleException($e);
}
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/QuestionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;


use App\Http\Errors\ErrorHandler;
use App\Models\Question;
use App\Repositorys\QuestionRepository;
use App\Services\QuestionService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class QuestionController extends Controller
{
protected QuestionService $questionService;

public function __construct(QuestionService $questionService)
{
$this->questionService = $questionService;
}

public function store(Request $request): JsonResponse
{
try {
$question = $this->questionService
->create(
$request->get('question'),
$request->get('subject')
);

return response()->json(
['message' => 'The question ' . $question->getQuestion() . ' are created successfully'
]);
} catch (\Exception $e) {
ErrorHandler::handleException($e);
}
}
}
36 changes: 36 additions & 0 deletions app/Http/Controllers/StudentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;


use App\Http\Errors\ErrorHandler;
use App\Repositorys\QuestionRepository;
use App\Repositorys\StudentRepository;
use App\Services\StudentService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class StudentController extends Controller
{
protected StudentService $studentService;

public function __construct(StudentService $studentService)
{
$this->studentService = $studentService;
}

public function store(Request $request): JsonResponse
{
try {
$student = $this->studentService
->create($request->get('name')
);

return response()->json([
'message' => 'The student ' . $student->getStudentName() . ' are created successfully'
]);
} catch (\Exception $e) {
ErrorHandler::handleException($e);
}
}
}
37 changes: 37 additions & 0 deletions app/Http/Controllers/SubjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers;

use App\Http\Errors\ErrorHandler;
use App\Models\Subject;
use App\Repositorys\SubjectRepository;
use App\Services\SubjectService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;


class SubjectController extends Controller
{
protected SubjectService $subjectService;

public function __construct(SubjectService $subjectService)
{
$this->subjectService = $subjectService;
}

public function store(Request $request): JsonResponse
{
try {
$subject = $this->subjectService
->create(
$request->get('subject')
);

return response()->json([
'message' => 'The subject ' . $subject->getSubject() . ' are created successfully'
]);
} catch (\Exception $e) {
ErrorHandler::handleException($e);
}
}
}
15 changes: 15 additions & 0 deletions app/Http/Errors/ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Errors;


class ErrorHandler
{
public static function handleException(\Exception $e)
{
var_dump('HANDLE EXCEPTION');
throw new \Exception(
$e->getMessage() . ' in ' . $e->getFile() . ' ' . $e->getLine()
);
}
}
1 change: 0 additions & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ class VerifyCsrfToken extends Middleware
* @var array<int, string>
*/
protected $except = [
//
];
}
54 changes: 54 additions & 0 deletions app/Models/Answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Models;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;

#[Entity]
#[Table(name:"answers")]
class Answer
{
#[Id, Column(type:"guid"), GeneratedValue(strategy: 'UUID')]
protected string $id;

#[Column(type:"string")]
public string $answer;

#[Column(type:"boolean")]
protected bool $is_correct;

#[ManyToOne(targetEntity: Question::class, cascade: ["persist"], inversedBy: "answers")]
protected Question $question;

public function __construct($answer, bool $is_correct, Question $question)
{
$this->answer = $answer;
$this->is_correct = $is_correct;
$this->question = $question;
}

public function getId(): string
{
return $this->id;
}

public function getAnswer(): string
{
return $this->answer;
}

public function isCorrect(): bool
{
return (bool)$this->is_correct;
}

public function getQuestionId(): string
{
return $this->question_id;
}
}
Loading