diff --git a/app/web/src/components/layout/header/Header.js b/app/web/src/components/layout/header/Header.js index 85a1eb8..d7005f7 100644 --- a/app/web/src/components/layout/header/Header.js +++ b/app/web/src/components/layout/header/Header.js @@ -11,6 +11,7 @@ const Header = ({ titleTxt, subtitleTxt }) => const dispatch = useDispatch(); const refUser = useRef(null); const open = useSelector(state => state.ui.userMenuOpen); + return { '& .MuiPaper-root': { bgcolor: 'gray.dark', - position: 'relative', + position: 'sticky', overflowX: 'hidden', height: '100vh', '&::-webkit-scrollbar': { diff --git a/app/web/src/components/pages/home/HomeController.js b/app/web/src/components/pages/home/HomeController.js index a5e7725..9c00c7f 100644 --- a/app/web/src/components/pages/home/HomeController.js +++ b/app/web/src/components/pages/home/HomeController.js @@ -10,7 +10,7 @@ const HomeController = () => const btoken = useSelector(state => state.user.btoken); const nav = useNavigate(); - const createTaskRedirect = () => nav('create/task?id=' + selectedTeam.id); + const createTaskRedirect = () => nav('tasks/create/' + selectedTeam.id); const handeValChange = (e, val, reason) => { @@ -20,7 +20,7 @@ const HomeController = () => dispatch(teamActions.setTeamStats(null)); dispatch(teamActions.setTeamTasks([])); } - } + }; const getCount = async (teamId) => { @@ -34,27 +34,12 @@ const HomeController = () => } }) .catch(e => dispatch(teamActions.setTeamStats(null))); - } - - const getTasks = async (teamId) => - { - axios.get('http://localhost:8080/tasks/team/' + (teamId ?? -1), - { headers: {"Authorization" : `Bearer ${btoken}`} }) - .then(res => - { - if (res.status === 200 && res.data.status) - { - dispatch(teamActions.setTeamTasks(res.data.data)) - } - }) - .catch(e => dispatch(teamActions.setTeamTasks([]))); - } + }; return { createTaskRedirect, handeValChange, - getCount, - getTasks + getCount } } diff --git a/app/web/src/components/ui/grid/Grid.js b/app/web/src/components/ui/grid/Grid.js index d60d7cf..5749a2e 100644 --- a/app/web/src/components/ui/grid/Grid.js +++ b/app/web/src/components/ui/grid/Grid.js @@ -1,209 +1,65 @@ import { useEffect, useState } from 'react'; -import { Box, Chip, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TablePagination } from '@mui/material'; +import { Paper, Table, TableBody, TableContainer, TableHead, TablePagination } from '@mui/material'; +import { useSelector } from 'react-redux'; +import GridController from "./GridController"; -import UserAvatar from '../avatar/UserAvatar'; -import { useSelector } from "react-redux"; - -const dummyData = [ // TODO: remove later - { user: { name: 'Marko Markovic', id: 221, src: 'https://randomuser.me/api/portraits/men/73.jpg' }, statusT: 1 }, - { user: { name: 'Janko Jankovic', id: 222 }, statusT: 2 }, - { user: { name: 'Jovana Jovanovic', id: 223, src: 'https://randomuser.me/api/portraits/women/31.jpg' }, statusT: 3 }, - { user: { name: 'Ljubo Kobas', id: 224 }, statusT: 0 }, - { user: { name: 'Jovan Jovanovic', id: 225 }, statusT: 3 }, - { user: { name: 'Petar Petrovic', id: 225 }, statusT: 3}, - { user: { name: 'Pero Peric', id: 225 }, statusT: 3 }, - { user: { name: 'Marko Markovic', id: 225 }, statusT: 1 }, - { user: { name: 'Nikola Nikola', id: 225 }, statusT: 2 }, - { user: { name: 'Test name', id: 225 }, statusT: 0 }, - { user: { name: 'Name shit', id: 225 }, statusT: 0 }, - { user: { name: 'Johan all', id: 225 }, statusT: 1 }, - { user: { name: 'Jovo Bar', id: 225 }, statusT: 3 }, - { user: { name: 'Marsal Peter', id: 225 }, statusT: 2 }, - { user: { name: 'Johna Hill', id: 225 }, statusT: 2 }, - { user: { name: 'Margaret Roby', id: 225 }, statusT: 3 } -]; - -const status = { - 0: { - name: 'Not started', - color: 'secondary' - }, - 1: { - name: 'In progress', - color: 'primary', - }, - 2: { - name: 'Review', - color: 'warning' - }, - 3: { - name: 'Done', - color: 'success' - } -}; - -const rowsPerPageOptions = [5, 10, 25]; - -export const checkGridType = (input) => -{ - if (!input || typeof input !== 'string') + const Grid = ({ gridType = 'tasks', teamId }) => { - return false - } - - const gridTypes = new Set([ - 'tasks', - 'teams', - 'users' - ]); - - return gridTypes.has(input); -}; - -export const getTableHeader = (type) => -{ - if (!checkGridType(type)) - { - return - } - - switch (type) - { - case 'tasks': - return - - Task - - - - Deadline - - - - Status - - - - Assigned to - - - - default: - break; - } -}; - -export const getTableRows = (type, rows) => -{ - if (!checkGridType(type)) - { - return - } - - return rows.map((row, i) => - - - + { + controller.getData(teamId); + }, [ teamId ]); + + const handleChangePage = (event, newPage) => + { + setPage(newPage); + }; + + const handleChangeRowsPerPage = event => + { + setRowsPerPage(parseInt(event.target.value, 10)); + setPage(0); + }; + + const data = useSelector(state => state.team.teamTasks); + + const slicedData = data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage); + + return - { row.title } - - - - - { row.deadline } - - - - - - - {/* TODO: when users URI is available change this*/} - - - - - { dummyData[i].user.name } - - - - - ); -} - -const Grid = ({ gridType = 'tasks' , teamId, controller}) => -{ - const [page, setPage] = useState(0); - const [rowsPerPage, setRowsPerPage] = useState(rowsPerPageOptions[0]); - - useEffect(() => - { - controller.getTasks(teamId); - }, [teamId]); - - const handleChangePage = (event, newPage) => { - setPage(newPage); - }; - const handleChangeRowsPerPage = event => { - setRowsPerPage(parseInt(event.target.value, 10)); - setPage(0); + + + { controller.getTableHeader(gridType) } + + + + { controller.getTableRows(gridType, slicedData) } + +
+ + + }; - const data = useSelector(state => state.team.teamTasks); - const slicedData = data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage); - - return - - - - { getTableHeader(gridType) } - - - - { getTableRows(gridType, slicedData) } - -
- - -
-}; - -export default Grid; \ No newline at end of file + export default Grid; \ No newline at end of file diff --git a/app/web/src/components/ui/grid/GridController.js b/app/web/src/components/ui/grid/GridController.js new file mode 100644 index 0000000..692e596 --- /dev/null +++ b/app/web/src/components/ui/grid/GridController.js @@ -0,0 +1,180 @@ +import axios from 'axios'; +import { teamActions } from '../../../store/slices/teamSlice'; +import { useDispatch, useSelector } from 'react-redux'; +import { Box, Chip, TableCell, TableRow } from '@mui/material'; +import UserAvatar from '../avatar/UserAvatar'; +import { useNavigate } from 'react-router-dom'; + +const HomeController = () => +{ + const nav = useNavigate(); + const dispatch = useDispatch(); + + const btoken = useSelector(state => state.user.btoken); + const status = useSelector(state => state.task.statusDefinition); + + + const getData = async (teamId) => + { + axios.get('http://localhost:8080/tasks/team/' + ( teamId ?? -1 ), + { headers: { 'Authorization': `Bearer ${ btoken }` } }) + .then(res => + { + if (res.status === 200 && res.data.status) + { + dispatch(teamActions.setTeamTasks(res.data.data)); + } + }) + .catch(e => dispatch(teamActions.setTeamTasks([]))); + }; + + const _handleClick = (id) => nav('tasks/' + id); + + const changeStatus = (e, id) => + { + e.stopPropagation(); + + axios.patch('http://localhost:8080/tasks/update/status/ow', + JSON.stringify({ id: id }), + { + headers: { + 'Authorization': `Bearer ${ btoken }`, + 'Content-Type': 'application/json' + } + }) + .then(res => + { + if (res.status === 200 && res.data.status) + { + dispatch(teamActions.setTaskStatus(res.data.data)); + } + }) + .catch(e => console.warn(e)); + } + + const _checkGridType = (input) => + { + if (!input || typeof input !== 'string') + { + return false + } + + const gridTypes = new Set([ + 'tasks', + 'teams', + 'users' + ]); + + return gridTypes.has(input); + }; + + const getTableHeader = (type) => + { + if (!_checkGridType(type)) + { + return + } + + switch (type) + { + case 'tasks': + return + + Task + + + + Deadline + + + + Status + + + + Assigned to + + + + default: + break; + } + }; + + const getTableRows = (type, rows) => + { + if (!_checkGridType(type)) + { + return + } + + return rows.map((row, i) => + { + const fullName = row.assagnedUser.fname + ' ' + row.assagnedUser.lname; + + return _handleClick(row?.id ?? -1)} + > + + { row.title } + + + + + { row.deadlineDate } + + + e.stopPropagation()}> + changeStatus(e, row?.id ?? -1)} + /> + + + + + + + + { fullName } + + + + + }); + } + + return { + getData, + getTableHeader, + getTableRows, + changeStatus + }; +}; + +export default HomeController; \ No newline at end of file diff --git a/app/web/src/store/slices/taskSlice.js b/app/web/src/store/slices/taskSlice.js new file mode 100644 index 0000000..f7ad828 --- /dev/null +++ b/app/web/src/store/slices/taskSlice.js @@ -0,0 +1,34 @@ +import { createSlice } from "@reduxjs/toolkit"; + +const initialState = { + statusDefinition: { + 0: { + name: 'Not started', + color: 'secondary' + }, + 1: { + name: 'In progress', + color: 'primary' + }, + 2: { + name: 'Review', + color: 'warning' + }, + 3: { + name: 'Done', + color: 'success' + } + } +}; + +const taskSlice = createSlice({ + name: 'task', + initialState, + reducers: { + + } +}); + +export default taskSlice; + +export const taskAction = taskSlice.actions; \ No newline at end of file diff --git a/app/web/src/store/slices/teamSlice.js b/app/web/src/store/slices/teamSlice.js index a7957a2..2e608f9 100644 --- a/app/web/src/store/slices/teamSlice.js +++ b/app/web/src/store/slices/teamSlice.js @@ -1,8 +1,8 @@ import { createSlice } from "@reduxjs/toolkit"; const initialState = { - teams: [{id: 200, label: 'Back-end team'}, {id: 100, label: 'Technical documentation team'}, {id: 300, label: 'Front-end team'}], - selectedTeam: {id: 100, label: 'Technical documentation team'}, + teams: [ { id: 200, label: 'Back-end team' }, { id: 100, label: 'Technical documentation team' }, { id: 300, label: 'Front-end team' } ], + selectedTeam: { id: 100, label: 'Technical documentation team' }, teamStats: null, teamTasks: [] }; @@ -34,6 +34,16 @@ const teamSlice = createSlice({ setSelectedTeam(state, action) { state.selectedTeam = action.payload; + }, + + setTaskStatus(state, action) + { + const index = state.teamTasks.findIndex(obj => obj.id === action.payload.id); + + if (index !== -1) + { + state.teamTasks[index].status = action.payload.status; + } } } }); diff --git a/app/web/src/store/store.js b/app/web/src/store/store.js index 0d290b5..147b6c5 100644 --- a/app/web/src/store/store.js +++ b/app/web/src/store/store.js @@ -1,13 +1,15 @@ import {configureStore} from '@reduxjs/toolkit'; import uiSlice from './slices/uiSlice'; import userSlice from './slices/userSlice'; -import teamSlice from "./slices/teamSlice"; +import teamSlice from './slices/teamSlice'; +import taskSlice from './slices/taskSlice'; const store = configureStore({ reducer: { ui: uiSlice.reducer, user: userSlice.reducer, - team: teamSlice.reducer + team: teamSlice.reducer, + task: taskSlice.reducer } }); diff --git a/db/script/init.sql b/db/script/init.sql index 5997ae5..19a64c3 100644 --- a/db/script/init.sql +++ b/db/script/init.sql @@ -138,6 +138,9 @@ CREATE TABLE IF NOT EXISTS user ( password VARCHAR(255) NOT NULL ); +-- special, admins, ... +INSERT INTO user (id, email, fname, lname, password) VALUES (-1,'admin','admin','admin','$2a$10$R.3fPs3S2Qrl/oVAi/.0geWQ7emUcysurOqDsaqk1vd0gmoRJUmuq'); + -- back end team INSERT INTO user (id, email, fname, lname, password) VALUES (100,'janko.jankovic@beDev.com','Janko','Jankovic','$2a$10$R.3fPs3S2Qrl/oVAi/.0geWQ7emUcysurOqDsaqk1vd0gmoRJUmuq'); INSERT INTO user (id, email, fname, lname, password) VALUES (200,'marko.markovic@beDev.com','Marko','Markovic','$2a$10$R.3fPs3S2Qrl/oVAi/.0geWQ7emUcysurOqDsaqk1vd0gmoRJUmuq'); diff --git a/service/src/main/java/com/dashnet/dashNet/Security/SecurityConfig.java b/service/src/main/java/com/dashnet/dashNet/Security/SecurityConfig.java index bbdbf84..fdf5015 100644 --- a/service/src/main/java/com/dashnet/dashNet/Security/SecurityConfig.java +++ b/service/src/main/java/com/dashnet/dashNet/Security/SecurityConfig.java @@ -63,7 +63,7 @@ CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(Arrays.asList("*")); - configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE")); configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "Accept")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); diff --git a/service/src/main/java/com/dashnet/dashNet/Task/Advices/TaskGenericAdvice.java b/service/src/main/java/com/dashnet/dashNet/Task/Advices/TaskGenericAdvice.java new file mode 100644 index 0000000..e7391c7 --- /dev/null +++ b/service/src/main/java/com/dashnet/dashNet/Task/Advices/TaskGenericAdvice.java @@ -0,0 +1,27 @@ +package com.dashnet.dashNet.Task.Advices; + +import com.dashnet.dashNet.Task.Exceptions.TaskGenericException; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import java.util.HashMap; +import java.util.Map; + +@ControllerAdvice +public class TaskGenericAdvice +{ + @ResponseBody + @ExceptionHandler(TaskGenericException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + Map taskGenericResponse(TaskGenericException ex) + { + Map a = new HashMap(); + a.put("status", 0); + a.put("info", ex.getMessage()); + + return a; + } +} diff --git a/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskGenericException.java b/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskGenericException.java new file mode 100644 index 0000000..75817ff --- /dev/null +++ b/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskGenericException.java @@ -0,0 +1,9 @@ +package com.dashnet.dashNet.Task.Exceptions; + +public class TaskGenericException extends RuntimeException +{ + public TaskGenericException(String msg) + { + super(msg.isEmpty() ? "Generic error!" : msg); + } +} diff --git a/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskNotFoundException.java b/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskNotFoundException.java index 94f8d75..67f79ff 100644 --- a/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskNotFoundException.java +++ b/service/src/main/java/com/dashnet/dashNet/Task/Exceptions/TaskNotFoundException.java @@ -2,7 +2,7 @@ public class TaskNotFoundException extends RuntimeException { - public TaskNotFoundException(int id) + public TaskNotFoundException(Long id) { super("Task with id " + id + " could not be found!"); } diff --git a/service/src/main/java/com/dashnet/dashNet/Task/Task.java b/service/src/main/java/com/dashnet/dashNet/Task/Task.java index 510a804..8692a9f 100644 --- a/service/src/main/java/com/dashnet/dashNet/Task/Task.java +++ b/service/src/main/java/com/dashnet/dashNet/Task/Task.java @@ -1,21 +1,26 @@ package com.dashnet.dashNet.Task; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import com.dashnet.dashNet.User.User; +import jakarta.persistence.*; import java.sql.Date; import java.util.Objects; @Entity +@Table(name = "task") public class Task { @Id - @GeneratedValue(strategy=GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") private Long id; + private Long creatorId; - private Long assagneId; + + @ManyToOne + @JoinColumn(name = "assagne_id") + private User assagnedUser; + private Long teamId; private Long commentTbId; private int status; @@ -44,14 +49,14 @@ public void setCreatorId(Long creatorId) this.creatorId = creatorId; } - public Long getAssagneId() + public User getAssagnedUser() { - return assagneId; + return assagnedUser; } - public void setAssagneId(Long assagneId) + public void setAssagnedUser(User assagnedUser) { - this.assagneId = assagneId; + this.assagnedUser = assagnedUser; } public Long getTeamId() @@ -124,37 +129,13 @@ public void setDescription(String description) this.description = description; } - Task () {} - - @Override - public boolean equals(Object o) + public Task() { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Task task = (Task) o; - return status == task.status && Objects.equals(id, task.id) && Objects.equals(creatorId, task.creatorId) && Objects.equals(assagneId, task.assagneId) && Objects.equals(teamId, task.teamId) && Objects.equals(commentTbId, task.commentTbId) && Objects.equals(createdDate, task.createdDate) && Objects.equals(deadlineDate, task.deadlineDate) && Objects.equals(title, task.title) && Objects.equals(description, task.description); } @Override public int hashCode() { - return Objects.hash(id, creatorId, assagneId, teamId, commentTbId, status, createdDate, deadlineDate, title, description); - } - - @Override - public String toString() - { - return "Task{" + - "id=" + id + - ", creatorId=" + creatorId + - ", assagneId=" + assagneId + - ", teamId=" + teamId + - ", commentTbId=" + commentTbId + - ", status=" + status + - ", createdDate=" + createdDate + - ", deadlineDate=" + deadlineDate + - ", title='" + title + '\'' + - ", description='" + description + '\'' + - '}'; + return Objects.hash(id, creatorId, assagnedUser.getId(), teamId, commentTbId, status, createdDate, deadlineDate, title, description); } } diff --git a/service/src/main/java/com/dashnet/dashNet/Task/TaskController.java b/service/src/main/java/com/dashnet/dashNet/Task/TaskController.java index e9f2e8b..4a65d7c 100644 --- a/service/src/main/java/com/dashnet/dashNet/Task/TaskController.java +++ b/service/src/main/java/com/dashnet/dashNet/Task/TaskController.java @@ -1,5 +1,6 @@ package com.dashnet.dashNet.Task; +import com.dashnet.dashNet.Task.Exceptions.TaskGenericException; import com.dashnet.dashNet.Task.Exceptions.TaskNotFoundException; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -9,7 +10,6 @@ import java.util.Map; @RestController -@CrossOrigin(origins = "*") @RequestMapping("/tasks") public class TaskController { @@ -43,7 +43,7 @@ public ResponseEntity> getTeamTaskCount(@PathVariable Long t } @GetMapping(path = "/{id}") - public ResponseEntity> getOne(@PathVariable int id) + public ResponseEntity> getOne(@PathVariable Long id) { Task a = taskRepository .findById(id) @@ -58,9 +58,12 @@ public ResponseEntity> getByTeam(@PathVariable Long teamId) List a = taskRepository .findByTeamId(teamId); - return !a.isEmpty() - ? taskService.returnOkResponse(false, "", 1, true, a) - : taskService.returnOkResponse(true, "No tasks found for selected team!", 0, false, null); + if(a.isEmpty()) + { + throw new TaskGenericException("No tasks found for selected team!"); + } + + return taskService.returnOkResponse(false, "", 1, true, a); } @GetMapping("title/{param}") @@ -84,20 +87,20 @@ public ResponseEntity> createTask(@RequestParam HashMap> deleteTask(@RequestParam int id) + public @ResponseBody ResponseEntity> deleteTask(@RequestBody Task ob) { - if (!taskRepository.existsById(id)) + if (!taskRepository.existsById(ob.getId())) { - return taskService.returnOkResponse(true, "Task with id:" + id + " is not found!", 0, false, null); + throw new TaskNotFoundException(ob.getId()); } - taskRepository.deleteById(id); + taskRepository.deleteById(ob.getId()); return taskService.returnOkResponse(true, "Task deleted successfully!", 1, false, null); } @PutMapping("/update") - public ResponseEntity> updateTask(Task nTask, @RequestParam int id) + public ResponseEntity> updateTask(Task nTask, @RequestParam Long id) { return taskRepository .findById(id) @@ -109,6 +112,22 @@ public ResponseEntity> updateTask(Task nTask, @RequestParam return taskService.returnOkResponse(true, "Task updated successfully!", 1, true, nTask.getId()); }) - .orElse(taskService.returnOkResponse(false, "Can't find task with id: " + id + "!", 0, false, null)); + .orElseThrow(() -> new TaskNotFoundException(id)); + } + + @PatchMapping("update/status/ow") + public ResponseEntity> updateOneWay(@RequestBody Task ob) + { + return taskRepository + .findById(ob.getId()) + .map(tsk -> + { + tsk.setStatus(tsk.getStatus() >= 3 ? 0 : tsk.getStatus() + 1); + + taskRepository.save(tsk); + + return taskService.returnOkResponse(true, "Task status changed successfully!", 1, true, tsk); + }) + .orElseThrow(() -> new TaskNotFoundException(ob.getId())); } } \ No newline at end of file diff --git a/service/src/main/java/com/dashnet/dashNet/Task/TaskRepository.java b/service/src/main/java/com/dashnet/dashNet/Task/TaskRepository.java index 3590b66..9136255 100644 --- a/service/src/main/java/com/dashnet/dashNet/Task/TaskRepository.java +++ b/service/src/main/java/com/dashnet/dashNet/Task/TaskRepository.java @@ -4,7 +4,7 @@ import java.util.List; -public interface TaskRepository extends CrudRepository { +public interface TaskRepository extends CrudRepository { List findByTitleContaining(String title); List findByDescriptionContaining(String description); List findByTeamId(Long teamid); diff --git a/service/src/main/java/com/dashnet/dashNet/Task/TaskService.java b/service/src/main/java/com/dashnet/dashNet/Task/TaskService.java index 70f04e2..525896a 100644 --- a/service/src/main/java/com/dashnet/dashNet/Task/TaskService.java +++ b/service/src/main/java/com/dashnet/dashNet/Task/TaskService.java @@ -15,7 +15,7 @@ protected Task createTask(HashMap ReqMap) { Task t = new Task(); - t.setAssagneId(Long.valueOf(ReqMap.getOrDefault("assagneid", "0"))); +// t.setAssagneId(Long.valueOf(ReqMap.getOrDefault("assagneid", "0"))); t.setCommentTbId(0L); // TODO: to be created t.setDescription(ReqMap.getOrDefault("description", "empty description")); t.setTitle(ReqMap.getOrDefault("title", "empty title")); diff --git a/service/src/main/java/com/dashnet/dashNet/User/User.java b/service/src/main/java/com/dashnet/dashNet/User/User.java index c13054d..d38468d 100644 --- a/service/src/main/java/com/dashnet/dashNet/User/User.java +++ b/service/src/main/java/com/dashnet/dashNet/User/User.java @@ -1,16 +1,27 @@ package com.dashnet.dashNet.User; +import com.dashnet.dashNet.Task.Task; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.util.Set; + @SuppressWarnings("unused") @Entity @JsonInclude(JsonInclude.Include.NON_NULL) +@Table(name = "user") public class User { + @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Integer id; + @Column(name = "id") + private Long id; + + @OneToMany(mappedBy = "assagnedUser") + private Set tasks; + @NotNull(message = "First Name is required") private String fname; @NotNull(message = "Last Name is required") @@ -19,10 +30,10 @@ public class User { private String email; @NotNull(message = "Password is required") private String password; - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } public String getFname() { diff --git a/service/src/main/java/com/dashnet/dashNet/User/UserController.java b/service/src/main/java/com/dashnet/dashNet/User/UserController.java index 7ec0d76..a21cafc 100644 --- a/service/src/main/java/com/dashnet/dashNet/User/UserController.java +++ b/service/src/main/java/com/dashnet/dashNet/User/UserController.java @@ -21,7 +21,7 @@ public UserController(UserService userService) { } @GetMapping(path="{userId}") - public @ResponseBody ResponseEntity getUser(@PathVariable("userId") Integer userId) { + public @ResponseBody ResponseEntity getUser(@PathVariable("userId") Long userId) { return userService.getUser(userId); } @@ -41,12 +41,12 @@ public ResponseEntity loginUser(@RequestBody User user) { } @DeleteMapping(path = "{userId}") - public ResponseEntity deleteUser(@PathVariable("userId") Integer userId) { + public ResponseEntity deleteUser(@PathVariable("userId") Long userId) { return userService.deleteUser(userId); } @PutMapping(path= "{userId}") - public @ResponseBody ResponseEntity updateUser(@PathVariable("userId") Integer userId, @RequestBody User user) { + public @ResponseBody ResponseEntity updateUser(@PathVariable("userId") Long userId, @RequestBody User user) { return userService.updateUser(userId, user); } } \ No newline at end of file diff --git a/service/src/main/java/com/dashnet/dashNet/User/UserRepository.java b/service/src/main/java/com/dashnet/dashNet/User/UserRepository.java index 2cace67..5e5798d 100644 --- a/service/src/main/java/com/dashnet/dashNet/User/UserRepository.java +++ b/service/src/main/java/com/dashnet/dashNet/User/UserRepository.java @@ -6,9 +6,9 @@ import java.util.List; @Repository -public interface UserRepository extends CrudRepository { +public interface UserRepository extends CrudRepository { List findAll(); - User findUserById(Integer id); + User findUserById(Long id); User findUserByEmail(String email); } \ No newline at end of file diff --git a/service/src/main/java/com/dashnet/dashNet/User/UserService.java b/service/src/main/java/com/dashnet/dashNet/User/UserService.java index 850e2e1..3e7fa8d 100644 --- a/service/src/main/java/com/dashnet/dashNet/User/UserService.java +++ b/service/src/main/java/com/dashnet/dashNet/User/UserService.java @@ -31,7 +31,7 @@ public ResponseEntity getUsers() { } - public ResponseEntity getUser(Integer userId) { + public ResponseEntity getUser(Long userId) { User userById = userRepository.findUserById(userId); if (userById == null) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new UserResponse("User does not exist.", 0)); @@ -99,7 +99,7 @@ public ResponseEntity login(User user) { return ResponseEntity.status(HttpStatus.OK).body(new UserResponse("Successfully logged in", token, userByEmail, 1)); } - public ResponseEntity deleteUser(Integer userId) { + public ResponseEntity deleteUser(Long userId) { boolean exists = userRepository.existsById(userId); if (!exists) @@ -111,7 +111,7 @@ public ResponseEntity deleteUser(Integer userId) { } - public ResponseEntity updateUser(Integer userId, User user) { + public ResponseEntity updateUser(Long userId, User user) { User userById = userRepository.findUserById(userId); if (userById == null) {