Skip to content

Commit

Permalink
testing locally attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssayzhang committed May 6, 2024
1 parent fe429d5 commit d7180f3
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 32 deletions.
81 changes: 81 additions & 0 deletions backend/src/API/coffeeChatImageAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { bucket } from '../firebase';
import { getNetIDFromEmail } from '../utils/memberUtil';
import { NotFoundError } from '../utils/errors';

Check failure on line 3 in backend/src/API/coffeeChatImageAPI.ts

View workflow job for this annotation

GitHub Actions / check

'NotFoundError' is defined but never used

//get all images

Check failure on line 5 in backend/src/API/coffeeChatImageAPI.ts

View workflow job for this annotation

GitHub Actions / check

Expected exception block, space or tab after '//' in comment
export const allCoffeeChatProofImages = async (): Promise<readonly EventProofImage[]> => {
const [files] = await bucket.getFiles({ prefix: 'coffeeChats/' });
const images = await Promise.all(
files.map(async (file) => {
const signedURL = await file.getSignedUrl({
action: 'read',
expires: Date.now() + 15 * 60000 // 15 min
});
const fileName = await file.getMetadata().then((data) => data[1].body.name);
return {
fileName,
url: signedURL[0]
};
})
);
images
.filter((image) => image.fileName.length > 'coffeeChats/'.length)
.map((image) => ({
...image,
fileName: image.fileName.slice(image.fileName.indexOf('/') + 1)
}));

return images;
};

//get images for user

Check failure on line 31 in backend/src/API/coffeeChatImageAPI.ts

View workflow job for this annotation

GitHub Actions / check

Expected exception block, space or tab after '//' in comment
export const allCoffeeChatProofImagesForMember = async (
user: IdolMember
): Promise<readonly EventProofImage[]> => {
const netId: string = getNetIDFromEmail(user.email);
const files = await bucket.getFiles({ prefix: `coffeeChats/${netId}` });
const images = await Promise.all(
files[0].map(async (file) => {
const signedURL = await file.getSignedUrl({
action: 'read',
expires: Date.now() + 15 * 60000 // 15 min
});
const fileName = await file.getMetadata().then((data) => data[1].body.name);
return {
fileName,
url: signedURL[0]
};
})
);

images
.filter((image) => image.fileName.length > 'coffeeChats/'.length)
.map((image) => ({
...image,
fileName: image.fileName.slice(image.fileName.indexOf('/') + 1)
}));

return images;
};

//upload image for user

Check failure on line 61 in backend/src/API/coffeeChatImageAPI.ts

View workflow job for this annotation

GitHub Actions / check

Expected exception block, space or tab after '//' in comment
export const setEventProofImage = async (name: string, user: IdolMember): Promise<string> => {
const file = bucket.file(`${name}.jpg`);
const signedURL = await file.getSignedUrl({
action: 'write',
version: 'v4',
expires: Date.now() + 15 * 60000 // 15 min
});
return signedURL[0];
};

//delete all images for user

Check failure on line 72 in backend/src/API/coffeeChatImageAPI.ts

View workflow job for this annotation

GitHub Actions / check

Expected exception block, space or tab after '//' in comment
export const deleteCoffeeChatProofImagesForMember = async (user: IdolMember): Promise<void> => {
const netId: string = getNetIDFromEmail(user.email);
const files = await bucket.getFiles({ prefix: `coffeeChats/${netId}` });
Promise.all(
files[0].map(async (file) => {
file.delete();
})
);
};
6 changes: 5 additions & 1 deletion backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
hideShoutout,
deleteShoutout
} from './API/shoutoutAPI';
import { createCoffeeChat, getAllCoffeeChats } from './API/coffeeChatAPI';
import {
allSignInForms,
createSignInForm,
Expand Down Expand Up @@ -81,7 +82,6 @@ import {
regradeSubmissions,
updateSubmissions
} from './API/devPortfolioAPI';
import { getAllCoffeeChats } from './API/coffeeChatAPI';
import DPSubmissionRequestLogDao from './dao/DPSubmissionRequestLogDao';
import AdminsDao from './dao/AdminsDao';
import { sendMail } from './API/mailAPI';
Expand Down Expand Up @@ -275,6 +275,10 @@ loginCheckedDelete('/shoutout/:uuid', async (req, user) => {
return {};
});

loginCheckedPost('/coffee-chat', async (req, _) => ({
coffeeChats: await createCoffeeChat(req.body)
}));

// Pull from IDOL
loginCheckedPost('/pullIDOLChanges', (_, user) => requestIDOLPullDispatch(user));
loginCheckedGet('/getIDOLChangesPR', (_, user) => getIDOLChangesPR(user));
Expand Down
2 changes: 1 addition & 1 deletion backend/src/dao/CoffeeChatDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class CoffeeChatDao extends BaseDao<CoffeeChat, DBCoffeeChat> {
* Deletes a coffee chat
* @param uuid - DB uuid of CoffeeChat
*/
async deleteCoffeeChat(uuisd: string): Promise<void> {
async deleteCoffeeChat(uuid: string): Promise<void> {
await this.getDocuments();
}

Expand Down
21 changes: 21 additions & 0 deletions frontend/src/API/ShoutoutsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ export default class ShoutoutsAPI {
});
}

public static createCoffeeChat(coffeeChat: CoffeeChat): Promise<CoffeeChat> {
return APIWrapper.post(`http://localhost:3000/coffee-chat`, coffeeChat).then((res) => res.data);
}

public static getAllCoffeeChats(): Promise<CoffeeChat[]> {
const coffeeChatProm = APIWrapper.get(`http://localhost:3000/coffee-chat`).then(
(res) => res.data
);
return coffeeChatProm.then((val) => {
if (val.error) {
Emitters.generalError.emit({
headerMsg: "Couldn't get all coffee chats",
contentMsg: `Error was: ${val.err}`
});
return [];
}
const coffeeChats = val.coffeeChats as CoffeeChat[];
return coffeeChats;
});
}

public static getShoutouts(email: string, type: 'given' | 'received'): Promise<Shoutout[]> {
const responseProm = APIWrapper.get(`${backendURL}/shoutout/${email}?type=${type}`).then(
(res) => res.data
Expand Down
123 changes: 93 additions & 30 deletions frontend/src/components/Forms/ShoutoutsPage/ShoutoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,102 @@ const ShoutoutForm: React.FC<ShoutoutFormProps> = ({ getGivenShoutouts }) => {
}
};

const createCoffee = () => {
const mem1: IdolMember = {
netid: 'abc',
email: 'abc@gmail.com',
firstName: 'a',
lastName: 'b',
pronouns: 'she/her',
graduation: '2024',
major: 'cs',
hometown: 'az',
about: 'hello',
subteams: ['Idol'],
role: 'designer',
roleDescription: 'Designer'
};

const mem2: IdolMember = {
netid: 'xyz',
email: 'xyz@gmail.com',
firstName: 'x',
lastName: 'z',
pronouns: 'she/her',
graduation: '2026',
major: 'cs',
hometown: 'az',
about: 'hello',
subteams: ['CU reviews'],
role: 'designer',
roleDescription: 'Designer'
};

const coffeeChat: CoffeeChat = {
uuid: '',
members: [mem1, mem2],
image: 'hallooo',
category: 'cool',
description: 'hehe',
status: 'pending',
date: Date.now()
};
ShoutoutsAPI.createCoffeeChat(coffeeChat).then((val) => {
Emitters.generalSuccess.emit({
headerMsg: 'Shoutout submitted!',
contentMsg: `Thank you for recognizing ${receiver}'s awesomeness! 🙏`
});
});
};

const getCoffee = () => {

Check failure on line 108 in frontend/src/components/Forms/ShoutoutsPage/ShoutoutForm.tsx

View workflow job for this annotation

GitHub Actions / check

'getCoffee' is assigned a value but never used
ShoutoutsAPI.getAllCoffeeChats().then((val) => {
Emitters.generalSuccess.emit({
headerMsg: 'Shoutout submitted!',
contentMsg: `Thank you for recognizing ${receiver}'s awesomeness! 🙏`
});
console.log('hello');

Check warning on line 114 in frontend/src/components/Forms/ShoutoutsPage/ShoutoutForm.tsx

View workflow job for this annotation

GitHub Actions / check

Unexpected console statement
});
};

return (
<Form className={styles.shoutoutForm}>
<h2 className={styles.formTitle}>Give someone a shoutout! 📣</h2>
<div className={styles.formContainer}>
<Form.Input
label="Who is awesome?"
value={receiver}
onChange={(event) => setReceiver(event.target.value)}
required
/>
<Checkbox
label={{ children: 'Anonymous?' }}
className={styles.isAnonCheckbox}
checked={isAnon}
onChange={() => setIsAnon(!isAnon)}
/>
</div>
<div>
<Form className={styles.shoutoutForm}>
<Form.Button floated="right" onClick={createCoffee}>
'testing'
</Form.Button>
<h2 className={styles.formTitle}>Give someone a shoutout! 📣</h2>
<div className={styles.formContainer}>
<Form.Input
label="Who is awesome?"
value={receiver}
onChange={(event) => setReceiver(event.target.value)}
required
/>
<Checkbox
label={{ children: 'Anonymous?' }}
className={styles.isAnonCheckbox}
checked={isAnon}
onChange={() => setIsAnon(!isAnon)}
/>
</div>

<div className={styles.reasonContainer}>
<Form.Input
label="Why are they awesome?"
name="message"
value={message}
control={TextArea}
onChange={(event) => setMessage(event.target.value)}
required
/>
</div>
<div className={styles.reasonContainer}>
<Form.Input
label="Why are they awesome?"
name="message"
value={message}
control={TextArea}
onChange={(event) => setMessage(event.target.value)}
required
/>
</div>

<Form.Button floated="right" onClick={giveShoutout} disabled={isSubmitting}>
{isSubmitting ? <Loader active inline size="small" /> : 'Send'}
</Form.Button>
</Form>
<Form.Button floated="right" onClick={giveShoutout} disabled={isSubmitting}>
{isSubmitting ? <Loader active inline size="small" /> : 'Send'}
</Form.Button>
</Form>
</div>
);
};

Expand Down

0 comments on commit d7180f3

Please sign in to comment.