Skip to content

Commit

Permalink
Merge branch 'main' into comment-out-all-code
Browse files Browse the repository at this point in the history
  • Loading branch information
jhagendoornCP authored Jun 4, 2024
2 parents 9109700 + e92d76f commit ababea6
Show file tree
Hide file tree
Showing 16 changed files with 535 additions and 234 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# Gather
## Gather ( NOT SURE WHICH ONE OF THESE DESCRIPTIONS WE PREFER )

Just a cool little inventory project.
Gather is for individuals who need a way to keep track of items when planning large events like a party or family gathering, moving to a new house, or going on a trip. Gather is a digital inventory management website that helps maintain, share, and organize multiple people’s items. Unlike traditional inventory management sites and check-off list tools that are designed for either an individual or a larger corporation, our product is made for both individuals and small groups of friends and family making it more friendly and easier to collaborate and communicate who has what items through integrated group functionalities.

## Overview
To allow students to keep track of their items after moving to college and organize the purchasing of items with their roommates!

Hi guys fixing my stuff.
## UI Prototype ( MIGHT NOT BE SHARED WITH ZIELKE??? )

### Purpose
https://www.figma.com/design/I5uSIz4KLxSyf4NDAFPLNC/Gather?node-id=40-177&t=qQE31y83u1B30ge8-0

## Dev environment setup
1. Clone the remote repository onto local machine
2. Run npm i or npm install
3. To run workspaces:
a) To run frontend: npm run front
b) To run backend: npm run back
c) To run test suite: npm run cyp

## UML Diagram
Create a wikipage (.md file) on your GitHub repository for the UML Class Diagram you have produced. Include the date the diagrams were last updated. Link to this page from your project README file. Also, push the source files of your diagram to the repo. I suggest you create a docs folder for the sake of organization.

To allow students to keep track of their items after moving to college and organize the purchasing of items with their roommates!

### Team

The Target Share team consists of 5 Cal Poly students. Over the course of about a month, we worked as a team to deploy this web application. The team members are listed below:
The gather team consists of 5 Cal Poly students. Over the course of about a month, we worked as a team to deploy this web application. The team members are listed below:

- [Jason Jelincic](https://www.linkedin.com/in/jasonjelincic/) - Software Developer
- [Zach Mattes](https://www.linkedin.com/in/zachmattes/) - Software Developer / Target guy!
Expand Down
166 changes: 166 additions & 0 deletions frontend/lib/deletes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,172 @@ export const handleDeleteGroupFromUsers = async (
}
};

//single user version of above code so that we can solo delete
export const handleDeleteGroupFromUser = async (
groupId: string,
userId: string,
) => {
try {
const response = await fetch(`${vite_backend_url}/users/${userId}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
});
if (response.ok) {
const user = await response.json();
const userGroups = user.groups;

// Remove the group from the user's groups
const updatedGroups = userGroups.filter((id: string) => id !== groupId);

// Update the user object
user.groups = updatedGroups;

// Send the updated user data back to the server
const updateResponse = await fetch(
`${vite_backend_url}/users/${userId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify({ groups: updatedGroups }),
},
);

if (updateResponse.ok) {
console.log(`Group removed successfully from user ${userId}`);
} else {
console.log(`Failed to update the user ${userId}`);
}
} else {
console.log(`Failed to fetch the user data for user ${userId}`);
}
} catch (error) {
console.log("An error occurred:", error);
}
};

//now this is reverse version deleting user from group's .members
export const handleDeleteUserFromGroup = async (
groupId: string,
userId: string,
) => {
try {
const response = await fetch(`${vite_backend_url}/groups/${groupId}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
});
if (response.ok) {
const group = await response.json();
const groupmembers = group.members;

// Remove the user from the group's members
const updatedusers = groupmembers.filter((id: string) => id !== userId);

// Update the group object
group.members = updatedusers;

// Send the updated group data back to the server
const updateResponse = await fetch(
`${vite_backend_url}/groups/${groupId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify({ members: updatedusers }),
},
);

if (updateResponse.ok) {
console.log(`user removed successfully from group ${groupId}`);
} else {
console.log(`Failed to update the group ${groupId}`);
}
} else {
console.log(`Failed to fetch the group data for group ${groupId}`);
}
} catch (error) {
console.log("An error occurred:", error);
}
};

export const handleRemoveUserFromEachBasket = async (
groupId: string,
userId: string,
) => {
try {
const response = await fetch(`${vite_backend_url}/groups/${groupId}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
});
if (response.ok) {
const group = await response.json();
const groupBaskets = group.baskets;
for (const basketId of groupBaskets) {
try {
const response = await fetch(
`${vite_backend_url}/baskets/${basketId}`,
{
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
},
);
if (response.ok) {
const basket = await response.json();
const basketmembers = basket.members;
if (basketmembers.includes(userId)) {
const updatedmembers = basketmembers.filter(
(id: string) => id !== userId,
);
// Update the basket object
basket.members = updatedmembers;
if (basketmembers.length === 1) {
await handleDeleteBasketFromGroup(groupId, basketId);
await handleDeleteAllItemsInBasket(basketId);
await handleDeleteBasket(basketId);
} else {
const updateResponse = await fetch(
`${vite_backend_url}/baskets/${basketId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify({ members: updatedmembers }),
},
);
if (updateResponse.ok) {
console.log(
`user removed successfully from basket ${basketId}`,
);
} else {
console.log(`Failed to update the basket ${basketId}`);
}
}
}
} else {
console.log("Failed to fetch the basket data");
}
} catch (error) {
console.log("an error occured", error);
}
}
} else {
console.log("Failed to fetch the group data");
}
} catch (error) {
console.log("an error occured", error);
}
};

// Function to remove a basket from a group
export const handleDeleteBasketFromGroup = async (
groupId: string,
Expand Down
35 changes: 0 additions & 35 deletions frontend/lib/edits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { IItem } from "../../backend/models/itemSchema";
import { IUser } from "../../backend/models/userSchema";
import { IGroup } from "../../backend/models/groupSchema";
import { fetchBasket } from "./fetches";
import { handleDeleteBasket } from "./deletes";

const vite_backend_url = "https://gather-app-307.azurewebsites.net";

Expand Down Expand Up @@ -233,40 +232,6 @@ export const addFriendToUser = async (
});
};

// Remove a user from a group by first removing all of their baskets (that are ONLY associated with them)
export const removeUserFromGroup = async (group: IGroup, user: IUser) => {
fetch(`${vite_backend_url}/groups/removeuser/${group._id}&${user._id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: "",
})
.then((res) => {
if (res.status === 207) {
return res.json();
} else if (res.status === 200) {
console.log("Successfully removed user.");
return;
} else Promise.reject(`Request failed: ${res.status} ${res.statusText}`);
})
.then((json) => {
if (!json) return;
for (let i = 0; i < json.length; i++) {
handleDeleteBasket(json[i]);
removeBasketFromGroup(group, json[i]);
}
// Remove user from group
})
.then(() => {
// Remove group from user
})
.catch((error) => {
console.log("Error deleting user: ", error);
});
};

// Remove a basket from a group
export const removeBasketFromGroup = async (group: IGroup, bid: string) => {
fetch(`${vite_backend_url}/groups/removebasket/${group._id}&${bid}`, {
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"dotenv": "^16.4.5",
"framer-motion": "^11.1.9",
"framer-motion": "^11.2.10",
"mongoose": "^8.4.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
1 change: 0 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function App() {
}
}
};

useEffect(() => {
getUser();
}, [token]);
Expand Down
34 changes: 16 additions & 18 deletions frontend/src/components/Basket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const BasketComp = ({
? "missing"
: basketObj?.description}
</Text>
<Text
<Text
display={multiMemberView ? "auto" : "none"}
marginBottom={multiMemberView ? "10px" : "none"}
>
Expand All @@ -174,28 +174,26 @@ const BasketComp = ({
width="100%"
justifyContent={"space-around"}
padding="5px"
flexDir={
{
xl: "row",
base: "column",
}
}
flexDir={{
xl: "row",
base: "column",
}}
>
{isOwnerOfBasket ? (
<AddFriendToBasket
basketId={basketId.toString()}
groupMembers={groupMembers}
basketMemberIds={basketObj?.members}
currentUserId={LoggedInUser?._id.toString()}
/>
<AddFriendToBasket
basketId={basketId.toString()}
groupMembers={groupMembers}
basketMemberIds={basketObj?.members}
currentUserId={LoggedInUser?._id.toString()}
/>
) : (
<></>
<></>
)}
{isMemberOfBasket ? (
<EditBasket
groupId={groupId}
basketId={basketId.toString()}
/>
<EditBasket
groupId={groupId}
basketId={basketId.toString()}
/>
) : (
<></>
)}
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/BasketItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ const BasketItem = ({ itemId, bid, basketMemberView }: Props) => {
padding={`${basketMemberView ? "0px" : "10px"} 2%`}
borderRadius="20px"
>
<Box
<Box
width={{ base: "40%", md: "25%" }}
margin={{ base: "10px", md: "0px" }}
textAlign={{ base: "center", md: "left" }}
>
{item?.name}
</Box>
<Box
flexGrow="6"
<Box
flexGrow="6"
display={{ base: "none", md: "block" }}
textAlign="center"
>
Expand Down Expand Up @@ -137,7 +137,9 @@ const BasketItem = ({ itemId, bid, basketMemberView }: Props) => {
display={{ base: "none", md: "block" }}
textAlign="center"
>
{item.isPrivate ? "Only viewable by basket members" : "Viewable by all group members"}
{item.isPrivate
? "Only viewable by basket members"
: "Viewable by all group members"}
</Text>
</Flex>
<IconButton
Expand Down
Loading

0 comments on commit ababea6

Please sign in to comment.