Skip to content

Commit 9c31de7

Browse files
committed
fixing commit bugs
1 parent abc96b6 commit 9c31de7

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

frontend/src/data/response.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
export interface MainCommandResponse {
23
id: number;
34
name: string
@@ -23,3 +24,30 @@ export interface CommandResponse {
2324
export interface CommandListResponse {
2425
data: CommandResponse[]
2526
}
27+
=======
28+
export interface MainCommandResponse {
29+
id: number;
30+
name: string
31+
params: string | null;
32+
format: string | null;
33+
data_size: number;
34+
total_size: number;
35+
}
36+
37+
export interface MainCommandListResponse {
38+
data: MainCommandResponse[]
39+
}
40+
41+
export interface CommandResponse {
42+
id: number
43+
name: string
44+
params: string | null
45+
format: string | null
46+
created_on: string
47+
updated_on: string
48+
}
49+
50+
export interface CommandListReponse {
51+
data: CommandResponse[]
52+
}
53+
>>>>>>> parent of bcd74d4 (Made changes to frontend based on Kashif's feedback (#3))

frontend/src/display/command_api.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
import axios from "axios";
23
import { CommandListResponse } from "../data/response";
34
import { API_URL } from "../environment";
@@ -20,3 +21,18 @@ export const getCommands = async (): Promise<CommandListResponse> => {
2021
* @param id: command to delete
2122
* @returns Promise<CommandListResponse>: list of commands after the command with the given id was deleted
2223
*/
24+
=======
25+
import axios from "axios";
26+
import { CommandListReponse } from "../data/response";
27+
import { API_URL } from "../environment";
28+
29+
export const getCommands = async (): Promise<CommandListReponse> => {
30+
try {
31+
const { data } = await axios.get<CommandListReponse>(`${API_URL}/commands/`)
32+
return data;
33+
} catch (error) {
34+
console.error(error)
35+
throw error
36+
}
37+
}
38+
>>>>>>> parent of bcd74d4 (Made changes to frontend based on Kashif's feedback (#3))

frontend/src/display/row.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
import { CommandStatusMapping } from "../data/other";
23
import { CommandResponse } from "../data/response";
34

@@ -20,3 +21,26 @@ const CommandRow = ({ id, command_type, params, status, created_on, updated_on,
2021
}
2122

2223
export default CommandRow;
24+
=======
25+
import { CommandResponse } from "../data/response";
26+
27+
interface CommandRowProp extends CommandResponse {
28+
handleDelete: () => void;
29+
}
30+
31+
const CommandRow = ({ id, name, params, format, created_on, updated_on, handleDelete }: CommandRowProp) => {
32+
return (
33+
<tr>
34+
<th>{id}</th>
35+
<th>{name}</th>
36+
<th>{params}</th>
37+
<th>{format}</th>
38+
<th>{created_on}</th>
39+
<th>{updated_on}</th>
40+
<th><button onClick={handleDelete}>Delete {id}</button></th>
41+
</tr>
42+
)
43+
}
44+
45+
export default CommandRow;
46+
>>>>>>> parent of bcd74d4 (Made changes to frontend based on Kashif's feedback (#3))

frontend/src/display/table.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
import { useEffect, useState } from "react"
23
import { CommandResponse } from "../data/response"
34
import { getCommands } from "./command_api"
@@ -44,3 +45,50 @@ const CommandTable = () => {
4445
}
4546

4647
export default CommandTable;
48+
=======
49+
import { useEffect, useState } from "react"
50+
import { CommandResponse } from "../data/response"
51+
import { getCommands } from "./command_api"
52+
import CommandRow from "./row"
53+
54+
const CommandTable = () => {
55+
const [commands, setCommands] = useState<CommandResponse[]>([])
56+
57+
const getCommandsFn = async () => {
58+
const data = await getCommands();
59+
setCommands(data.data)
60+
}
61+
62+
useEffect(() => {
63+
getCommandsFn();
64+
}, [])
65+
66+
const handleDelete = (id: number) => {
67+
return () => {
68+
// TODO: (Member) Handle delete logic here
69+
70+
}
71+
}
72+
73+
return (
74+
<table>
75+
<thead>
76+
<tr>
77+
<th>ID: </th>
78+
<th>Name: </th>
79+
<th>Params: </th>
80+
<th>Format: </th>
81+
<th>Created On: </th>
82+
<th>Updated On: </th>
83+
<th>Delete</th>
84+
</tr>
85+
</thead>
86+
<thead>
87+
{commands.map(value => (<CommandRow {...value} handleDelete={handleDelete(value.id)} />))}
88+
</thead>
89+
</table>
90+
)
91+
}
92+
93+
export default CommandTable;
94+
>>>>>>> parent of bcd74d4 (Made changes to frontend based on Kashif's feedback (#3))

frontend/src/input/input_api.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
import { API_URL } from "../environment";
23
import { CommandRequest } from "../data/request";
34
import axios from "axios";
@@ -23,3 +24,30 @@ export const getMainCommands = async (): Promise<MainCommandListResponse> => {
2324
throw error;
2425
}
2526
}
27+
=======
28+
import { API_URL } from "../environment";
29+
import { CommandRequest } from "../data/request";
30+
import axios from "axios";
31+
import { CommandResponse, MainCommandListResponse } from "../data/response";
32+
33+
export const createCommand = async (requestData: CommandRequest): Promise<CommandResponse | undefined> => {
34+
try {
35+
const { data } = await axios.post<CommandResponse>(`${API_URL}/commands`, requestData);
36+
return data
37+
} catch (error) {
38+
console.error(error);
39+
throw error;
40+
}
41+
}
42+
43+
export const getMainCommands = async (): Promise<MainCommandListResponse> => {
44+
try {
45+
const { data } = await axios.get<MainCommandListResponse>(`${API_URL}/main-commands/`);
46+
console.log(data)
47+
return data;
48+
} catch (error) {
49+
console.error(error)
50+
throw error;
51+
}
52+
}
53+
>>>>>>> parent of bcd74d4 (Made changes to frontend based on Kashif's feedback (#3))

0 commit comments

Comments
 (0)