Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.
Open
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
13 changes: 7 additions & 6 deletions src/main/java/com/projecty/projectyweb/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.projecty.projectyweb.user.UserService;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

Expand All @@ -23,25 +24,25 @@ public ChatController(ChatService chatService, UserService userService) {
}

@GetMapping("/{username}")
public Page<ChatMessage> getChatMessages(
public ResponseEntity<Page<ChatMessage>> getChatMessages(
@PathVariable("username") String username,
@RequestParam(required = false, defaultValue = "0") Integer offset,
@RequestParam(required = false, defaultValue = "10") Integer limit) {
Optional<User> optionalRecipient = userService.findByByUsername(username);
if (optionalRecipient.isPresent()) {
chatService.setAllReadForChat(optionalRecipient.get());
return chatService.findByRecipientAndSenderOrderById(optionalRecipient.get(), offset, limit);
return new ResponseEntity<>(chatService.findByRecipientAndSenderOrderById(optionalRecipient.get(), offset, limit), HttpStatus.OK);
}
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}

@GetMapping("")
public List<ChatHistoryData> getChatHistory() {
return chatService.getChatHistory();
public ResponseEntity<List<ChatHistoryData>> getChatHistory() {
return new ResponseEntity<>(chatService.getChatHistory(), HttpStatus.OK);
}

@GetMapping("unreadChatMessageCount")
public int getUnreadChatMessageCount() {
return chatService.getUnreadChatMessageCount();
public ResponseEntity<Integer> getUnreadChatMessageCount() {
return new ResponseEntity<>(chatService.getUnreadChatMessageCount(), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public MessageController(UserService userService, MessageRepository messageRepos
}

@GetMapping
public Page<Message> getPageOfMessages(
public ResponseEntity<Page<Message>> getPageOfMessages(
@RequestParam(defaultValue = "ALL") MessageType type,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "25") int itemsPerPage
) {
return messageService.getPageOfMessagesForCurrentUser(type, page, itemsPerPage);
return new ResponseEntity<>(messageService.getPageOfMessagesForCurrentUser(type, page, itemsPerPage), HttpStatus.OK);
}

@PostMapping
public Message sendMessagePost(
public ResponseEntity<Message> sendMessagePost(
@RequestParam String recipientUsername,
@RequestParam String title,
@RequestParam String text,
Expand All @@ -59,7 +59,7 @@ public Message sendMessagePost(
.text(text)
.recipientUsername(recipientUsername)
.build();
return messageService.sendMessage(message, multipartFiles);
return new ResponseEntity<>(messageService.sendMessage(message, multipartFiles), HttpStatus.OK);
}

@GetMapping("/{messageId}")
Expand All @@ -80,12 +80,12 @@ public ResponseEntity<Message> viewMessage(
}

@GetMapping("getUnreadMessageCount")
public int getUnreadMessageCount() {
return messageService.getUnreadMessageCountForCurrentUser();
public ResponseEntity<Integer> getUnreadMessageCount() {
return new ResponseEntity<>(messageService.getUnreadMessageCountForCurrentUser(), HttpStatus.OK);
}

@PostMapping("{replyToMessageId}/reply")
public Message replyToMessage(
public ResponseEntity<Message> replyToMessage(
@PathVariable Long replyToMessageId,
@RequestParam String title,
@RequestParam String text,
Expand All @@ -96,7 +96,7 @@ public Message replyToMessage(
.title(title)
.text(text)
.build();
return messageService.reply(replyToMessageId, message, multipartFiles);
return new ResponseEntity<>(messageService.reply(replyToMessageId, message, multipartFiles), HttpStatus.OK);
}

@DeleteMapping(value = "{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.projecty.projectyweb.notifications;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

Expand All @@ -21,13 +22,13 @@ public NotificationController(NotificationService notificationService, Notificat
}

@GetMapping
public List<Notification> getNotifications() {
return notificationService.getNotifications();
public ResponseEntity<List<Notification>> getNotifications() {
return new ResponseEntity<>(notificationService.getNotifications(), HttpStatus.OK);
}

@GetMapping("unseenCount")
public Long getUnseenNotificationsCount() {
return notificationService.getUnseenNotificationCount();
public ResponseEntity<Long> getUnseenNotificationsCount() {
return new ResponseEntity<>(notificationService.getUnseenNotificationCount(), HttpStatus.OK);
}

@DeleteMapping("{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.projecty.projectyweb.project.role.dto.ProjectRoleData;
import com.projecty.projectyweb.user.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -42,20 +43,20 @@ public ProjectController(ProjectService projectService, ProjectRepository projec
}

@GetMapping("")
public ProjectsData myProjects() {
return projectService.getProjectsForCurrentUser();
public ResponseEntity<ProjectsData> myProjects() {
return new ResponseEntity<>(projectService.getProjectsForCurrentUser(), HttpStatus.OK);
}

@PostMapping("")
public Project addProjectPost(
public ResponseEntity<Project> addProjectPost(
@Valid @RequestBody Project project,
BindingResult bindingResult
) throws BindException {
projectValidator.validate(project, bindingResult);
if (bindingResult.hasErrors()) {
throw new BindException(bindingResult);
}
return projectService.createNewProjectAndSave(project, project.getUsernames());
return new ResponseEntity<>(projectService.createNewProjectAndSave(project, project.getUsernames()), HttpStatus.OK);
}

@DeleteMapping("/{projectId}")
Expand All @@ -67,20 +68,20 @@ public void deleteProject(@PathVariable Long projectId) {

@PostMapping("/{projectId}/roles")
@EditPermission
public List<ProjectRole> addUsersToExistingProjectPost(
public ResponseEntity<List<ProjectRole>> addUsersToExistingProjectPost(
@PathVariable Long projectId,
@RequestBody List<String> usernames) {
Project project = projectRepository.findById(projectId).get();
return projectService.addProjectRolesByUsernames(project, usernames);
return new ResponseEntity<>(projectService.addProjectRolesByUsernames(project, usernames), HttpStatus.OK);
}

@GetMapping(value = "/{projectId}", params = "roles")
@EditPermission
public ProjectData getProjectWithProjectRoles(
public ResponseEntity<ProjectData> getProjectWithProjectRoles(
@PathVariable Long projectId
) {
Optional<Project> optionalProject = projectRepository.findById(projectId);
return projectService.getProjectData(optionalProject.get());
return new ResponseEntity<>(projectService.getProjectData(optionalProject.get()), HttpStatus.OK);
}

@PostMapping("/{projectId}/leave")
Expand All @@ -91,36 +92,36 @@ public void leaveProject(@PathVariable Long projectId) {
}

@PatchMapping("/{projectId}")
public Project patchProject(
public ResponseEntity<Project> patchProject(
@PathVariable("projectId") Long projectId,
@RequestBody Project patchedProject
) {
Optional<Project> optionalProject = projectRepository.findById(projectId);
if (optionalProject.isPresent() && projectService.hasCurrentUserPermissionToEdit(optionalProject.get())) {
return projectService.patchProject(optionalProject.get(), patchedProject);
return new ResponseEntity<>(projectService.patchProject(optionalProject.get(), patchedProject), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}

@GetMapping("/{projectId}")
public Project getProjectData(
public ResponseEntity<Project> getProjectData(
@PathVariable Long projectId
) {
Optional<Project> optionalProject = projectRepository.findById(projectId);
if (optionalProject.isPresent() && projectService.hasCurrentUserPermissionToEdit(optionalProject.get())) {
return optionalProject.get();
return new ResponseEntity<>(optionalProject.get(), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}

@GetMapping("/{projectId}/projectRole")
@AnyPermission
public ProjectRoleData getProjectRoleForCurrentUserByProjectId(@PathVariable Long projectId) {
public ResponseEntity<ProjectRoleData> getProjectRoleForCurrentUserByProjectId(@PathVariable Long projectId) {
ProjectRoleData projectRoleData = projectService.getProjectRoleForCurrentUserByProjectId(projectId);
if (projectRoleData != null) {
return projectRoleData;
return new ResponseEntity<>(projectRoleData, HttpStatus.OK);
}
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.projecty.projectyweb.user.User;
import com.projecty.projectyweb.user.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

Expand Down Expand Up @@ -39,14 +40,14 @@ public void deleteUserPost(

@PatchMapping("/{roleId}")
@EditPermission
public ProjectRole changeRolePatch(
public ResponseEntity<ProjectRole> changeRolePatch(
@PathVariable Long roleId,
@RequestBody ProjectRole patchedProjectRole
) {
Optional<ProjectRole> optionalRole = projectRoleRepository.findById(roleId);
User current = userService.getCurrentUser();
if (optionalRole.isPresent() && !optionalRole.get().getUser().equals(current)) {
return projectRoleService.patchProjectRole(optionalRole.get(), patchedProjectRole);
return new ResponseEntity<>(projectRoleService.patchProjectRole(optionalRole.get(), patchedProjectRole), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.projecty.projectyweb.settings;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -12,12 +14,12 @@ public SettingsController(SettingsService settingsService) {
}

@GetMapping
public Settings getSettings() {
return settingsService.getSettingsForCurrentUser();
public ResponseEntity<Settings> getSettings() {
return new ResponseEntity<>(settingsService.getSettingsForCurrentUser(), HttpStatus.OK);
}

@PatchMapping
public Settings patchSettings(@RequestBody Settings patchedSettings) {
return settingsService.patchSettings(patchedSettings);
public ResponseEntity<Settings> patchSettings(@RequestBody Settings patchedSettings) {
return new ResponseEntity<>(settingsService.patchSettings(patchedSettings), HttpStatus.OK);
}
}
25 changes: 13 additions & 12 deletions src/main/java/com/projecty/projectyweb/task/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.projecty.projectyweb.task.dto.TaskData;
import com.projecty.projectyweb.user.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
Expand Down Expand Up @@ -37,7 +38,7 @@ public TaskController(ProjectRepository projectRepository, ProjectService projec
}

@PostMapping("/project/{projectId}")
public Task addTaskPost(
public ResponseEntity<Task> addTaskPost(
@PathVariable Long projectId,
@RequestBody Task task,
BindingResult bindingResult
Expand All @@ -48,19 +49,19 @@ public Task addTaskPost(
if (bindingResult.hasErrors()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
} else if (optionalProject.isPresent() && projectService.hasCurrentUserPermissionToEdit(optionalProject.get())) {
return taskService.addTaskToProject(task, optionalProject.get());
return new ResponseEntity<>(taskService.addTaskToProject(task, optionalProject.get()), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}

@GetMapping("/project/{projectId}")
public ProjectTasksData getProjectTaskData(
public ResponseEntity<ProjectTasksData> getProjectTaskData(
@PathVariable Long projectId
) {
Optional<Project> optionalProject = projectRepository.findById(projectId);
Project project = optionalProject.get();
return taskService.getProjectTasksData(project);
return new ResponseEntity<>(taskService.getProjectTasksData(project), HttpStatus.OK);
}

@DeleteMapping("/{taskId}")
Expand All @@ -74,15 +75,15 @@ public void deleteTask(

@GetMapping("/{taskId}")
@EditPermission
public TaskData getTask(
public ResponseEntity<TaskData> getTask(
@PathVariable Long taskId
) {
Optional<Task> optionalTask = taskRepository.findById(taskId);
return taskService.getTaskData(optionalTask.get());
return new ResponseEntity<>(taskService.getTaskData(optionalTask.get()), HttpStatus.OK);
}

@PatchMapping("/{taskId}")
public Task editTaskDetailsPatch(
public ResponseEntity<Task> editTaskDetailsPatch(
@PathVariable Long taskId,
@RequestBody Task task
) throws BindException {
Expand All @@ -96,21 +97,21 @@ public Task editTaskDetailsPatch(
if (result.hasErrors()) {
throw new BindException(result);
}
return taskRepository.save(newTaskCandidate);
return new ResponseEntity<>(taskRepository.save(newTaskCandidate), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}

@PostMapping("/{taskId}/assign")
@EditPermission
public User assignUserPost(
public ResponseEntity<User> assignUserPost(
@PathVariable Long taskId,
@RequestBody String username
) {
Optional<Task> optionalTask = taskRepository.findById(taskId);
Task task = optionalTask.get();
return taskService.assignUserByUsername(task, username);
return new ResponseEntity<>(taskService.assignUserByUsername(task, username), HttpStatus.OK);
}

@DeleteMapping("/{taskId}/assign/{username}")
Expand All @@ -124,7 +125,7 @@ public void removeAssignment(
}

@GetMapping("assigned")
public List<Task> getUndoneAssignedTasksForCurrentUser() {
return taskService.getUndoneAssignedTasksForCurrentUser();
public ResponseEntity<List<Task>> getUndoneAssignedTasksForCurrentUser() {
return new ResponseEntity<>(taskService.getUndoneAssignedTasksForCurrentUser(), HttpStatus.OK);
}
}
Loading