Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/return answer status #60

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions src/main/java/api/educai/controllers/ClassroomController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package api.educai.controllers;

import api.educai.dto.*;
import api.educai.dto.classroom.ClassroomInfoDTO;
import api.educai.dto.classroom.PatchClassroomTitleAndCourse;
import api.educai.dto.classroom.UserScoreDTO;
import api.educai.dto.classwork.ClassworkDTO;
import api.educai.dto.classwork.ClassworkUserDTO;
import api.educai.dto.post.PostDTO;
import api.educai.dto.user.ReportDTO;
import api.educai.dto.user.UserDTO;
import api.educai.entities.Classroom;
import api.educai.entities.Post;
import api.educai.services.ClassroomService;
import api.educai.services.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -21,7 +27,6 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.io.IOException;
import java.util.List;

import static org.springframework.http.ResponseEntity.*;
Expand Down Expand Up @@ -68,12 +73,21 @@ public ResponseEntity<List<UserDTO>> getClassroomParticipants(@PathVariable Obje
}

@Operation(summary = "Retorna atividades de uma sala de aula")
@Secured("ROLE_TEACHER")
@GetMapping("/{id}/classworks")
public ResponseEntity<List<ClassworkDTO>> getClassworksByClassroom(@PathVariable ObjectId id) {
List<ClassworkDTO> classworks = classroomService.getClassworks(id);
return classworks.isEmpty() ? status(204).build() : status(200).body(classworks);
}

@Operation(summary = "Retorna atividades de uma sala de aula com o status de resposta do usuário")
@Secured("ROLE_STUDENT")
@GetMapping("/{id}/classworks/{userId}")
public ResponseEntity<List<ClassworkUserDTO>> getClassworksByClassroom(@PathVariable ObjectId id, @PathVariable ObjectId userId) {
List<ClassworkUserDTO> classworks = classroomService.getClassworksByUser(id, userId);
return classworks.isEmpty() ? status(204).build() : status(200).body(classworks);
}

@Operation(summary = "Retorna posts de uma sala de aula")
@GetMapping("/{id}/posts")
public ResponseEntity<List<PostDTO>> getPostsByClassroom(@PathVariable ObjectId id){
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/api/educai/controllers/ClassworkController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package api.educai.controllers;

import api.educai.dto.AnswerDTO;
import api.educai.dto.ClassworkDetailsDTO;
import api.educai.dto.answer.AnswerDTO;
import api.educai.dto.classwork.ClassworkDetailsDTO;
import api.educai.dto.answer.UserAnswerStatusDTO;
import api.educai.entities.Answer;
import api.educai.entities.Classwork;
import api.educai.services.ClassworkService;
Expand Down Expand Up @@ -49,6 +50,15 @@ public ResponseEntity<Void> addAnswer(
return status(201).build();
}

@Operation(summary = "Retorna uma lista de usuários e o status da resposta para uma atividade")
@Secured("ROLE_TEACHER")
@GetMapping("/{id}/answers/status")
public ResponseEntity<List<UserAnswerStatusDTO>> getUserAnswerStatus(
@PathVariable ObjectId id) {
List<UserAnswerStatusDTO> userAnswerStatusList = classworkService.getUserAnswerStatus(id);
return status(200).body(userAnswerStatusList);
}

@Operation(summary = "Retorna uma atividade via id")
@GetMapping("/{id}")
public ResponseEntity<ClassworkDetailsDTO> getClassworkById(@PathVariable ObjectId id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api.educai.controllers;

import api.educai.dto.WordDefinitionDTO;
import api.educai.dto.dictionary.WordDefinitionDTO;
import api.educai.services.DictionaryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/api/educai/controllers/PostController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package api.educai.controllers;

import api.educai.dto.NewPostDTO;
import api.educai.dto.PatchPost;
import api.educai.dto.PostDTO;
import api.educai.dto.post.NewPostDTO;
import api.educai.dto.post.PatchPost;
import api.educai.dto.post.PostDTO;
import api.educai.entities.Post;
import api.educai.services.PostService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/api/educai/controllers/UserController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package api.educai.controllers;

import api.educai.dto.UserDTO;
import api.educai.dto.ClassroomInfoDTO;
import api.educai.dto.AuthDTO;
import api.educai.dto.LoginDTO;
import api.educai.dto.PatchUserEmailAndName;
import api.educai.dto.TokenDTO;
import api.educai.dto.user.UserDTO;
import api.educai.dto.classroom.ClassroomInfoDTO;
import api.educai.dto.auth.AuthDTO;
import api.educai.dto.auth.LoginDTO;
import api.educai.dto.user.PatchUserEmailAndName;
import api.educai.dto.auth.TokenDTO;
import api.educai.entities.User;
import api.educai.services.UserService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -22,7 +22,6 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api.educai.dto;
package api.educai.dto.answer;

import api.educai.dto.classroom.ClassroomParticipantsDTO;
import api.educai.entities.Answer;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.answer;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.answer;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package api.educai.dto;
package api.educai.dto.answer;

import api.educai.entities.Option;
import lombok.Getter;

import java.util.ArrayList;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/api/educai/dto/answer/UserAnswerStatusDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package api.educai.dto.answer;

import api.educai.dto.user.UserDTO;
import lombok.Data;

@Data
public class UserAnswerStatusDTO {
private UserDTO user;
private boolean hasAnswered;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.auth;

public class AuthDTO {
private String token;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.auth;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.auth;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.auth;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.classroom;

public class AddStudentInClassroomDTO {
private String student_email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package api.educai.dto;
package api.educai.dto.classroom;

import api.educai.dto.classwork.ClassworkDTO;
import api.educai.dto.post.PostDTO;
import api.educai.dto.user.UserDTO;
import api.educai.entities.Classroom;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.classroom;

import api.educai.entities.User;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package api.educai.dto;
package api.educai.dto.classroom;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.educai.dto;
package api.educai.dto.classroom;

import lombok.Getter;
import org.bson.types.ObjectId;

@Getter
public class UserScoreDTO {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.classwork;

import api.educai.entities.Classwork;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api.educai.dto;
package api.educai.dto.classwork;

import api.educai.entities.Question;
import api.educai.dto.answer.QuestionDTO;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/api/educai/dto/classwork/ClassworkUserDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package api.educai.dto.classwork;

import api.educai.entities.Classwork;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@NoArgsConstructor
public class ClassworkUserDTO {

private String id;
@Size(max = 100)
private String title;
@NotNull
private LocalDate datePosting;
@NotNull
private LocalDate endDate;
@Size(max = 200)
private String description;
@NotNull
private Integer totalQuestions;
private boolean hasAnswered;

public ClassworkUserDTO(Classwork classwork) {
this.id = String.valueOf(classwork.getId());
this.title = classwork.getTitle();
this.datePosting = classwork.getDatePosting();
this.endDate = classwork.getEndDate();
this.description = classwork.getDescription();
this.totalQuestions = classwork.getQuestions().size();
this.hasAnswered = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.dictionary;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.dictionary;

import api.educai.utils.ListObject;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.dictionary;

import api.educai.utils.ListObject;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.post;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.post;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.post;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.user;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.user;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.user;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api.educai.dto;
package api.educai.dto.user;

import api.educai.dto.classroom.ClassroomInfoDTO;
import api.educai.entities.Classroom;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api.educai.dto;
package api.educai.dto.user;

import api.educai.dto.classroom.ClassroomInfoDTO;
import api.educai.entities.Classroom;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.user;

import api.educai.entities.User;
import api.educai.enums.Role;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.educai.dto;
package api.educai.dto.user;

import api.educai.entities.User;
import api.educai.enums.Role;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/api/educai/entities/Answer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api.educai.entities;

import api.educai.dto.QuestionAnswerDTO;
import api.educai.dto.answer.QuestionAnswerDTO;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.bson.types.ObjectId;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/api/educai/entities/TokenBlacklist.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api.educai.entities;

import api.educai.dto.InvalidTokenDTO;
import api.educai.dto.auth.InvalidTokenDTO;
import lombok.Data;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/api/educai/filter/TokenFilter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api.educai.filter;

import api.educai.dto.UserDetailsDTO;
import api.educai.dto.user.UserDetailsDTO;
import api.educai.enums.Role;
import api.educai.repositories.UserRespository;
import api.educai.services.token.Token;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/api/educai/repositories/AnswerRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface AnswerRepository extends MongoRepository <Answer, Long> {

Answer findById(ObjectId id);

boolean existsAnswerByUserIdAndClassworkId(ObjectId userId, ObjectId classworkId);

List<Answer> findAllByClassworkId(ObjectId classworkId);
}
Loading