From c14f47efc3f5c59188ef3823e92f3ee80149f1bd Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Fri, 7 Feb 2020 17:49:11 +0100 Subject: [PATCH] client API communication --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 2 +- Controllers/.DS_Store | Bin 6148 -> 0 bytes Controllers/ProjectsController.cs | 12 +++++++++ Data/AppDbContext.cs | 12 +++++---- Models/Project.cs | 2 +- Models/User.cs | 2 ++ client/src/components/ProgressBar.tsx | 7 ++--- client/src/components/TicketList.tsx | 10 ++----- client/src/controllers/ProjectController.tsx | 26 +++++++++++++++++-- client/src/pages/ProjectPage.tsx | 26 ++++++++++++------- client/src/pages/TicketPage.tsx | 7 +++-- client/src/pages/UserPage.tsx | 2 +- client/src/types/Project.ts | 11 +++++++- client/src/types/User.ts | 1 + client/src/utils/Constants.ts | 2 +- client/src/viewModels/ProjectVM.ts | 21 ++++++++++++--- 17 files changed, 103 insertions(+), 40 deletions(-) delete mode 100644 .DS_Store delete mode 100644 Controllers/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index dd6c1c5998c3bcfa6af67c6842b3ddbd87e073e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5Iwu5Ph3i$cQE-AYRSc^2n zZ)HH9U4{}fTw#_zzu`gO*R*9huiH6o`SbqG9fCI|KaX+d8_r4HJbKg51V4reZ0s%OpF0zz!>;%46tX55BoI06tenuBm2{_Tif48$U0r$`IMX(~}uT|8nqO{d+*xFTYwsOfN_ zGS`WfT|A+DAZ1{vmm}%_N1M<8X_8$T1IECgV!&nPw4CskVsBl$ vIq9{YdO{VExK44E!bxbwjFncrOASK1mkF_m*eTLNu^)jzgAK;Ok23HMK&ML0 diff --git a/.gitignore b/.gitignore index c13ec38..c977dd6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ obj/ .vs/ .vscode/ Migrations/ -app.db +app.db* .DS_Store \ No newline at end of file diff --git a/Controllers/.DS_Store b/Controllers/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0>> GetProjectMembers(int id) + { + var project = await _context.Projects.FindAsync(id); + + if (project == null) + { return NotFound(); } + + return project.GetMembers(); + } + // PUT: api/Projects/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. diff --git a/Data/AppDbContext.cs b/Data/AppDbContext.cs index a74eb96..c615c4f 100644 --- a/Data/AppDbContext.cs +++ b/Data/AppDbContext.cs @@ -16,10 +16,12 @@ namespace TicketManager.Data public DbSet Notes { get; set; } public DbSet Files { get; set; } - // protected override void OnModelCreating(ModelBuilder builder) - // { - // base.OnModelCreating(builder); - // builder.Entity().HasKey(t => new { t.ProjectId, t.UserId }); - // } + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + builder.Entity().HasKey(a => new { a.ProjectId, a.UserId }); + builder.Entity().HasOne(a => a.Project).WithMany(p => p.Assignments).HasForeignKey(a => a.ProjectId); + builder.Entity().HasOne(a => a.User).WithMany(u => u.Assignments).HasForeignKey(a => a.UserId); + } } } \ No newline at end of file diff --git a/Models/Project.cs b/Models/Project.cs index fa54cf9..639a85d 100644 --- a/Models/Project.cs +++ b/Models/Project.cs @@ -15,7 +15,7 @@ namespace TicketManager.Models { get { - return (float)this.Tickets. + return this.Tickets.Count() == 0 ? 0 : (float)this.Tickets. Where(t => t.Status == Status.Done).Count() / this.Tickets.Count() * 100; diff --git a/Models/User.cs b/Models/User.cs index 45ddd15..4284ae5 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -10,6 +10,8 @@ namespace TicketManager.Models public string LastName { get; set; } public string FullName => $"{FirstName} {LastName}"; public string Presentation { get; set; } + public string Email { get; set; } + public string Phone { get; set; } public DateTime Created_at { get; } = DateTime.Now; public byte[] Picture { get; set; } // public Role Role { get; set; } diff --git a/client/src/components/ProgressBar.tsx b/client/src/components/ProgressBar.tsx index 20d856b..a48c4ca 100644 --- a/client/src/components/ProgressBar.tsx +++ b/client/src/components/ProgressBar.tsx @@ -1,14 +1,11 @@ import React, { FC } from "react"; type ProgressBarProps = { - value?: number; + value: number; max?: number; }; -export const ProgressBar: FC = ({ - value = 60, - max = 100 -}) => { +export const ProgressBar: FC = ({ value, max = 100 }) => { return (
diff --git a/client/src/components/TicketList.tsx b/client/src/components/TicketList.tsx index b83d047..c6bb6f4 100644 --- a/client/src/components/TicketList.tsx +++ b/client/src/components/TicketList.tsx @@ -2,16 +2,10 @@ import React, { FC } from "react"; import { Ticket } from "../types/Ticket"; type TicketListProps = { - tickets?: Ticket[]; + tickets: Ticket[]; }; -export const TicketList: FC = ({ - tickets = [ - { Id: 1, Title: "Todo today" }, - { Id: 2, Title: "Todo tomorrow" }, - { Id: 5, Title: "Todo NOW!!!" } - ] -}) => { +export const TicketList: FC = ({ tickets }) => { return (
{tickets.map((t: Ticket) => ( diff --git a/client/src/controllers/ProjectController.tsx b/client/src/controllers/ProjectController.tsx index 4706d6c..c6d6bcf 100644 --- a/client/src/controllers/ProjectController.tsx +++ b/client/src/controllers/ProjectController.tsx @@ -1,6 +1,28 @@ -import React, { FC } from "react"; +import React, { FC, useState, useEffect } from "react"; +import { useParams } from "react-router-dom"; import { ProjectPage } from "../pages/ProjectPage"; +import ProjectVM from "../viewModels/ProjectVM"; +import { Constants } from "../utils/Constants"; +import { Project } from "../types/Project"; export const ProjectController: FC = () => { - return ; + const [project, setProject] = useState({}); + const [isLoading, setIsLoading] = useState(true); + const { id } = useParams(); + + const getProject: Function = (id: number) => { + fetch(`${Constants.getProjectURI}/${id}`) + .then(res => res.json()) + .catch(err => console.log(err)) + .then(data => setProject(data)) + .finally(() => setIsLoading(false)); + }; + + useEffect(() => { + getProject(id); + }, []); + + const viewModel = new ProjectVM(project as Project); + + return isLoading ?

Loading ...

: ; }; diff --git a/client/src/pages/ProjectPage.tsx b/client/src/pages/ProjectPage.tsx index a90127a..deda354 100644 --- a/client/src/pages/ProjectPage.tsx +++ b/client/src/pages/ProjectPage.tsx @@ -3,21 +3,27 @@ import { Header } from "../components/Header"; import { AvatarList } from "../components/AvatarList"; import { ProgressBar } from "../components/ProgressBar"; import { TicketList } from "../components/TicketList"; +import ProjectVM from "../viewModels/ProjectVM"; -export const ProjectPage: FC = () => { +interface IProps { + viewModel: ProjectVM; +} +export const ProjectPage: FC = ({ viewModel }) => { + const { + title, + description, + // avatars, + value, + tickets + } = viewModel; return (
-
- { return ( <> -
+
- + {/* // // // diff --git a/client/src/pages/UserPage.tsx b/client/src/pages/UserPage.tsx index da371ac..a2a1ad0 100644 --- a/client/src/pages/UserPage.tsx +++ b/client/src/pages/UserPage.tsx @@ -3,7 +3,7 @@ import { Header } from "../components/Header"; export const UserPage: FC = () => { return ( -
+
// // // diff --git a/client/src/types/Project.ts b/client/src/types/Project.ts index 424e1fb..3fa4d3a 100644 --- a/client/src/types/Project.ts +++ b/client/src/types/Project.ts @@ -1,3 +1,12 @@ +import { Ticket } from "./Ticket"; +import { User } from "./User"; + export interface Project { - Id: number; + id: number; + title: string; + description: string; + progression: number; + tickets: Ticket[]; + + getUsers(): User[]; } diff --git a/client/src/types/User.ts b/client/src/types/User.ts index 9cef2be..5d677e3 100644 --- a/client/src/types/User.ts +++ b/client/src/types/User.ts @@ -1,3 +1,4 @@ export interface User { Id: number; + Picture: string; } diff --git a/client/src/utils/Constants.ts b/client/src/utils/Constants.ts index acb31c2..f889fc4 100644 --- a/client/src/utils/Constants.ts +++ b/client/src/utils/Constants.ts @@ -1,3 +1,3 @@ export class Constants { - static weatherIconUrl?: string; + static getProjectURI: string = "/api/projects"; } diff --git a/client/src/viewModels/ProjectVM.ts b/client/src/viewModels/ProjectVM.ts index 82c8059..dec8981 100644 --- a/client/src/viewModels/ProjectVM.ts +++ b/client/src/viewModels/ProjectVM.ts @@ -1,5 +1,20 @@ -export class ProjectVM { - public Id?: number; +import { Ticket } from "../types/Ticket"; +import { Project } from "../types/Project"; - public constructor() {} +export default class ProjectVM { + public id: number; + public title: string; + public description: string; + // public avatars: string[]; + public value: number; + public tickets: Ticket[]; + + public constructor(project: Project) { + this.id = project.id; + this.title = project.title; + this.description = project.description; + // this.avatars = project.getUsers().map(u => u.Picture); + this.value = project.progression; + this.tickets = project.tickets; + } }