Skip to content

Commit

Permalink
Merge branch 'dev' into feature/BE-591-backend-handle-image-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
alitpc25 authored Dec 24, 2023
2 parents d69b969 + db5d29b commit 23a14cc
Show file tree
Hide file tree
Showing 42 changed files with 840 additions and 578 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.groupa1.resq.controller;

import com.groupa1.resq.auth.UserDetailsImpl;
import com.groupa1.resq.request.CreateCommentRequest;
import com.groupa1.resq.request.CreateActionRequest;
import com.groupa1.resq.dto.ActionDto;
import com.groupa1.resq.request.UpdateActionRequest;
import com.groupa1.resq.response.ActionResponse;
import com.groupa1.resq.service.ActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -27,43 +30,68 @@ public class ActionController {

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/createAction")
public ResponseEntity<String> createAction(@RequestBody CreateActionRequest createActionRequest){
public ResponseEntity<Object> createAction(@RequestBody CreateActionRequest createActionRequest){
return actionService.createAction(createActionRequest);
}

@PreAuthorize("hasRole('RESPONDER') or hasRole('COORDINATOR')")
@GetMapping("/viewActions")
public ResponseEntity<List<ActionResponse>> viewActions(@RequestParam Long taskId) {
return actionService.viewActions( taskId);
@PreAuthorize("hasRole('COORDINATOR') or hasRole('RESPONDER')")
@GetMapping("/viewSingleAction")
public ResponseEntity<ActionDto> viewSingleAction(@RequestParam Long actionId) {
return actionService.viewSingleAction(actionId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@GetMapping("/updateAction")
public ResponseEntity<String> updateAction(@RequestBody UpdateActionRequest updateActionRequest, @RequestParam Long actionId){
return actionService.updateAction(actionId, updateActionRequest);
@PostMapping("/deleteAction")
public ResponseEntity<String> deleteAction(@RequestParam Long actionId) {
return actionService.deleteAction(actionId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@GetMapping("/deleteAction")
public ResponseEntity<String> deleteAction(@RequestParam Long actionId, @RequestParam Long taskId){
return actionService.deleteAction(actionId, taskId);
@PostMapping("/updateAction")
public ResponseEntity<String> updateAction(@RequestBody
UpdateActionRequest updateActionRequest, @RequestParam Long actionId) {
return actionService.updateAction(updateActionRequest, actionId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@GetMapping("/viewActionByFilter")
public ResponseEntity<List<ActionResponse>> viewActionByFilter(@RequestParam(required = false) Long taskId,
@RequestParam(required = false) Long verifierId,
@RequestParam(required = false) Boolean isCompleted,
@RequestParam(required = false) Boolean isVerified,
@RequestParam(required = false) LocalDateTime dueDate){
return actionService.viewActionByFilter(taskId, verifierId, isCompleted, isVerified, dueDate);


@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/completeAction")
public ResponseEntity<String> completeAction(@RequestParam Long actionId, Authentication authentication){
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
return actionService.completeAction(actionId, userId);
}
@PreAuthorize("hasRole('FACILITATOR')")
@PostMapping("/verifyAction")
public ResponseEntity<String> verifyAction(@RequestParam Long actionId, Authentication authentication){
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
return actionService.verifyAction(actionId, userId);
}

@PreAuthorize("hasRole('FACILITATOR')")
@GetMapping("/verifyAction")
public ResponseEntity<String> verifyAction(@RequestParam Long actionId, @RequestParam Long verifierId){
return actionService.verifyAction(actionId, verifierId);
@PostMapping("/commentAction")
public ResponseEntity<String> verifyAction(@RequestBody
CreateCommentRequest commentActionRequest){
return actionService.commentAction(commentActionRequest);
}

@PreAuthorize("hasRole('COORDINATOR') or hasRole('FACILITATOR')")
@GetMapping("/filterAction")
public ResponseEntity<List<ActionDto>> viewActionsByFilter(@RequestParam(required = false) Long verifierId,
@RequestParam(required = false) Boolean isCompleted,
@RequestParam(required = false) LocalDateTime latestDueDate,
@RequestParam(required = false) LocalDateTime earliestDueDate,
@RequestParam(required = false) Long taskId,
@RequestParam(required = false) Boolean isVerified){

return actionService.viewActionsByFilter(verifierId, isCompleted, latestDueDate, earliestDueDate, taskId, isVerified);
}






}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.groupa1.resq.controller;

import com.groupa1.resq.request.CreateFeedbackRequest;
import com.groupa1.resq.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

@Autowired
private FeedbackService feedbackService;

@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/giveFeedback")
public ResponseEntity<Object> giveFeedback(CreateFeedbackRequest feedback) {
return feedbackService.giveFeedback(feedback);
}


@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/deleteFeedback")
public ResponseEntity<String> deleteFeedback(@RequestParam Long feedbackId) {
return feedbackService.deleteFeedback(feedbackId);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.groupa1.resq.controller;

import com.groupa1.resq.entity.Need;
import com.groupa1.resq.entity.Notification;
import com.groupa1.resq.entity.enums.ENotificationEntityType;
import com.groupa1.resq.converter.NotificationConverter;
import com.groupa1.resq.dto.NotificationDto;
import com.groupa1.resq.entity.enums.ENotificationEntityType;
import com.groupa1.resq.service.NotificationService;
import com.groupa1.resq.util.NotificationMessages;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -43,7 +41,8 @@ public NotificationDto viewNotificationById(@RequestParam Long notificationId, @
@PostMapping("/sendNotification")
@PreAuthorize("hasRole('ADMIN')")
public void sendSystemNotification(@RequestParam String title, @RequestParam Long userId,
@RequestParam Long relatedEntityId, @RequestParam ENotificationEntityType notificationType) {
@RequestParam Long relatedEntityId, @RequestParam
ENotificationEntityType notificationType) {
String body = String.format(NotificationMessages.SYSTEM_MESSAGE, userId, relatedEntityId);
log.info("Sending notification with title: {}, body: {}, user id: {}, related entity id: {}, notification type: {}"
, title, body, userId, relatedEntityId, notificationType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.groupa1.resq.dto.ResourceDto;
import com.groupa1.resq.entity.enums.EResourceStatus;
import com.groupa1.resq.request.CreateResourceRequest;
import com.groupa1.resq.service.ResourceService;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -53,6 +54,7 @@ public ResponseEntity<String> deleteResource(@RequestParam Long resourceId) {
}



@PreAuthorize("hasRole('COORDINATOR') or hasRole('VICTIM') or hasRole('RESPONDER')")
@GetMapping("/filterByDistance")
public ResponseEntity<List<ResourceDto>> filterByDistance(@RequestParam
Expand All @@ -66,9 +68,10 @@ public ResponseEntity<List<ResourceDto>> filterByDistance(@RequestParam
public ResponseEntity<List<ResourceDto>> filterByCategory(@RequestParam(required = false) String categoryTreeId,
@RequestParam(required = false) BigDecimal longitude,
@RequestParam(required = false) BigDecimal latitude,
@RequestParam(required = false) Long userId) {
@RequestParam(required = false) Long userId,
@RequestParam(required = false) EResourceStatus status){
log.info("Filtering resources by category");
return resourceService.filterResource(latitude, longitude, categoryTreeId, userId);
return resourceService.filterResource(latitude, longitude, categoryTreeId, userId, status);
}

@PreAuthorize("hasRole('COORDINATOR') or hasRole('VICTIM') or hasRole('RESPONDER')")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.groupa1.resq.controller;

import com.groupa1.resq.auth.UserDetailsImpl;
import com.groupa1.resq.entity.enums.EStatus;
import com.groupa1.resq.entity.enums.EUrgency;
import com.groupa1.resq.request.AddResourceToTaskRequest;
import com.groupa1.resq.request.CreateTaskRequest;
import com.groupa1.resq.dto.TaskDto;
import com.groupa1.resq.request.UpdateTaskRequest;
import com.groupa1.resq.response.TaskResponse;
import com.groupa1.resq.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
Expand All @@ -29,35 +31,98 @@ public class TaskController {

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/createTask")
public ResponseEntity<String> createTask(@RequestBody CreateTaskRequest createTaskRequest) {
public ResponseEntity<Object> createTask(@RequestBody CreateTaskRequest createTaskRequest) {
return taskService.createTask(createTaskRequest);
}


@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/acceptTask")
public ResponseEntity<String> acceptTask(@RequestParam Long taskId, @RequestParam Long userId) {
public ResponseEntity<String> acceptTask(@RequestParam Long taskId, Authentication authentication){
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
return taskService.acceptTask(taskId, userId);
}

@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/declineTask")
public ResponseEntity<String> declineTask(@RequestParam Long taskId, Authentication authentication){
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
return taskService.declineTask(taskId, userId);
}
@PreAuthorize("hasRole('RESPONDER') or hasRole('COORDINATOR')")
@GetMapping("/viewSingleTask")
public ResponseEntity<TaskDto> viewSingleTask(@RequestParam Long taskId) {
return taskService.viewSingleTask(taskId);
}



@PreAuthorize("hasRole('RESPONDER') or hasRole('COORDINATOR')")
@GetMapping("/viewTasks")
public ResponseEntity<List<TaskResponse>> viewAllTasks(@RequestParam Long userId) {
return taskService.viewAllTasks(userId);
public ResponseEntity<List<TaskDto>> viewTasks(@RequestParam Long userId) {
return taskService.viewTasks(userId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/deleteTask")
public ResponseEntity<String> deleteTask(@RequestParam Long taskId) {
return taskService.deleteTask(taskId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/updateTask")
public ResponseEntity<String> updateTask(@RequestParam Long taskId, @RequestBody UpdateTaskRequest updateTaskRequest) {
return taskService.updateTask(taskId, updateTaskRequest);
public ResponseEntity<String> updateTask(@RequestBody
UpdateTaskRequest updateTaskRequest, @RequestParam Long taskId){
return taskService.updateTask(updateTaskRequest, taskId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/assignTask")
public ResponseEntity<String> assignTask(@RequestParam Long taskId, @RequestParam Long userId) {
return taskService.assignTask(taskId, userId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/unassignTask")
public ResponseEntity<String> unassignTask(@RequestParam Long taskId) {
return taskService.unassignTask(taskId);
}


@PreAuthorize("hasRole('RESPONDER')")
@PostMapping("/completeTask")
public ResponseEntity<String> completeTask(@RequestParam Long taskId, Authentication authentication) {
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
return taskService.completeTask(taskId, userId);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/addResources")
public ResponseEntity<String> addResources(@RequestBody AddResourceToTaskRequest addResourceToTaskRequest, Authentication authentication) {
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
log.info("Adding resources to task by coordinator with id: {}", userId);
return taskService.addResources(addResourceToTaskRequest);
}


@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/removeResources")
public ResponseEntity<String> removeResources(@RequestBody AddResourceToTaskRequest addResourceToTaskRequest, Authentication authentication) {
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
Long userId = userDetails.getId();
log.info("Adding resources to task by coordinator with id: {}", userId);
return taskService.removeResources(addResourceToTaskRequest);
}

@PreAuthorize("hasRole('COORDINATOR')")
@PostMapping("/viewTaskByFilter")
public ResponseEntity<List<TaskResponse>> viewTaskByFilter(@RequestParam Long assignerId, @RequestParam Long assigneeId,
@RequestParam EUrgency urgency, @RequestParam EStatus status) {
return taskService.viewTaskByFilter(assignerId, assigneeId, urgency, status);
public ResponseEntity<List<TaskDto>> viewTaskByFilter(@RequestParam(required = false) Long assignerId, @RequestParam(required = false) Long assigneeId,
@RequestParam(required = false) EUrgency urgency, @RequestParam(required = false) EStatus status) {
return taskService.viewTasksByFilter(assignerId, assigneeId, urgency, status);
}


Expand All @@ -66,4 +131,12 @@ public ResponseEntity<List<TaskResponse>> viewTaskByFilter(@RequestParam Long as











}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.groupa1.resq.converter;

import com.groupa1.resq.dto.ActionDto;
import com.groupa1.resq.entity.Action;
import org.springframework.stereotype.Service;

@Service
public class ActionConverter {

public ActionDto convertToDto(Action action){
ActionDto actionDto = new ActionDto();
actionDto.setId(action.getId());
actionDto.setTaskId(action.getTask().getId());
if (action.getVerifier() != null) {
actionDto.setVerifierId(action.getVerifier().getId());
}
actionDto.setDescription(action.getDescription());
actionDto.setCompleted(action.isCompleted());
actionDto.setStartLatitude(action.getStartLatitude());
actionDto.setStartLongitude(action.getStartLongitude());
actionDto.setEndLatitude(action.getEndLatitude());
actionDto.setEndLongitude(action.getEndLongitude());
actionDto.setDueDate(action.getDueDate());
actionDto.setCreatedDate(action.getCreatedAt());
return actionDto;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.groupa1.resq.converter;

import com.groupa1.resq.dto.FeedbackDto;
import com.groupa1.resq.entity.Feedback;
import org.springframework.stereotype.Service;

@Service
public class FeedbackConverter {

public FeedbackDto convertToDto(Feedback feedback){
FeedbackDto feedbackDto = new FeedbackDto();
feedbackDto.setId(feedback.getId());
feedbackDto.setTaskId(feedback.getTask().getId());
feedbackDto.setUserId(feedback.getCreator().getId());
feedbackDto.setMessage(feedback.getMessage());
feedbackDto.setCreatedDate(feedback.getCreatedAt());
return feedbackDto;
}
}
Loading

0 comments on commit 23a14cc

Please sign in to comment.