Skip to content

Commit

Permalink
DynamoDB CRUD and AWS Lambda integration
Browse files Browse the repository at this point in the history
  • Loading branch information
zvoverman committed May 19, 2024
1 parent 7f13cc4 commit 0b2fc88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import ToggleButtonGroup from 'react-bootstrap/ToggleButtonGroup';

const queryClient = new QueryClient();

interface CharacterData {
id: string;
name: string;
height: string;
mass: string;
eye_color: string;
hair_color: string;
skin_color: string;
}

function App() {
return (
<QueryClientProvider client={queryClient}>
Expand Down Expand Up @@ -35,11 +45,11 @@ function GetPeople() {

useEffect(() => {
if (data) {
//setFavoriteCards(data.map(person => person.id));
setFavoriteCards(data.map(person => parseInt(person.id)));
}
}, [data]);

console.log(data);
console.log(favoriteCards);

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = parseInt(event.target.value);
Expand Down
5 changes: 3 additions & 2 deletions src/components/PersonCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CharacterData {
}

const addPerson = async (id: number, data: CharacterData): Promise<CharacterData> => {
data.id = id.toString();
const response = await fetch(`https://w5c9dy2dg4.execute-api.us-east-2.amazonaws.com/people`, {
method: 'PUT',
headers: {
Expand Down Expand Up @@ -58,13 +59,13 @@ function PersonCard({ index, isFavorite, onFavoriteToggle }: PersonCardProps): J
)
);

const addMutation = useMutation((newData: CharacterData) => addPerson(person, newData), {
const addMutation = useMutation((newData: CharacterData) => addPerson(index, newData), {
onSuccess: () => {
queryClient.invalidateQueries('getPerson_' + person);
},
});

const deleteMutation = useMutation(() => deletePerson(person), {
const deleteMutation = useMutation(() => deletePerson(index), {
onSuccess: () => {
queryClient.invalidateQueries('getPerson_' + person);
},
Expand Down

0 comments on commit 0b2fc88

Please sign in to comment.