Skip to content

Commit

Permalink
Fixed issue where non existant tasks can get assigned to projects
Browse files Browse the repository at this point in the history
  • Loading branch information
pacholoamit committed Jul 2, 2022
1 parent 5efeb67 commit b185666
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/pkg/dto/project.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type Project struct {
ID uint
CreatedAt time.Time
UpdatedAt time.Time
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Name string `json:"name" form:"name" validate:"required"`
Description string `json:"description" form:"description"`
}

type Projects []Project
9 changes: 9 additions & 0 deletions api/pkg/repositories/project.repositories.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package repositories

import (
"errors"
"fmt"

"github.com/pacholoamit/GO-TASK-MGR/pkg/dto"
Expand Down Expand Up @@ -61,10 +62,18 @@ func (project) AssignTaskToProject(taskId int, projectId int) (string, error) {
return "", err
}

if taskModel.ID == 0 {
return "", errors.New("task ID not found")
}

if err := db.Clauses(clause.Returning{}).Find(&projectModel, projectId).Error; err != nil {
return "", err
}

if projectModel.ID == 0 {
return "", errors.New("project ID not found")
}

db.Model(&projectModel).Association("Tasks").Append(&taskModel)

return fmt.Sprintf("Successfully assigned task %v to project %v", taskId, projectId), nil
Expand Down
16 changes: 7 additions & 9 deletions web/pages/projects/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Loader,
Stack,
Title,
Text,
useMantineTheme,
} from "@mantine/core";
import { useRouter } from "next/router";
Expand Down Expand Up @@ -36,10 +37,6 @@ export default function ProjectPage() {
} = useGetAllTasksByProject({ projectId: query.id });
const theme = useMantineTheme();

console.log(query.id);
const secondaryColor =
theme.colorScheme === "dark" ? theme.colors.dark[1] : theme.colors.gray[7];

if (projectIsLoading || tasksIsLoading)
return (
<Center>
Expand All @@ -58,11 +55,12 @@ export default function ProjectPage() {
/>
<Grid>
{taskData?.map((task) => (
<Grid.Col key={task.ID} span={3}>
<Card shadow="lg" p="lg">
<Card.Section>
<Title order={6}> {task.title}</Title>
</Card.Section>
<Grid.Col key={task.ID} span={2}>
<Card shadow="lg" p="lg" sx={{ height: 150 }}>
<Stack>
<Title order={4}> {task.title}</Title>
<Text lineClamp={2}>{task.description}</Text>
</Stack>
</Card>
</Grid.Col>
))}
Expand Down

0 comments on commit b185666

Please sign in to comment.