Skip to content

Commit

Permalink
Merge pull request #18 from denssle/friends
Browse files Browse the repository at this point in the history
Add Friends Function
  • Loading branch information
Dominik Hellweg authored May 1, 2024
2 parents 211133c + 5197e46 commit 626a76d
Show file tree
Hide file tree
Showing 94 changed files with 2,874 additions and 1,024 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## Installation

- add `.env` File for Connection to redis DB. Should look like this:
- add `.env` File for Connection to a Maria DB. Should look like this:
- database name same as user name
- the db should run on `localhost:3306`

```
REDIS_TOKEN="rediss://*****"
UPSTASH_REDIS_REST_URL="https://*****"
UPSTASH_REDIS_REST_TOKEN="*****="
MARIA_DB_USER="***"
MARIA_DB_PASSWORD="***"
```

- run `npm install`
Expand Down
1,743 changes: 1,370 additions & 373 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "festival",
"version": "0.2.1",
"version": "0.3.0",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down Expand Up @@ -48,6 +48,9 @@
"type": "module",
"dependencies": {
"bcrypt-ts": "^4.0.0",
"ioredis": "^5.3.2"
"ioredis": "^5.3.2",
"mariadb": "^2.5.6",
"sequelize": "^6.37.1",
"sequelize-cli": "^6.6.2"
}
}
2 changes: 1 addition & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
import type { CurrentUser } from '$lib/models/CurrentUser';
import type { CurrentUser } from '$lib/models/user/CurrentUser';

declare global {
namespace App {
Expand Down
10 changes: 5 additions & 5 deletions src/app.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<link rel="icon" type="image/png" href="%sveltekit.assets%/favicon.png" />
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css" />
<link href="%sveltekit.assets%/favicon.png" rel="icon" type="image/png" />
<link href="https://cdn.simplecss.org/simple.min.css" rel="stylesheet" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett" />
<meta name="description" content="Svelte demo app" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
<meta content="GNU Terry Pratchett" http-equiv="X-Clacks-Overhead" />
<meta content="Svelte demo app" name="description" />
<title>Festival</title>
%sveltekit.head%
</head>
Expand Down
7 changes: 5 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Handle } from '@sveltejs/kit';
import * as userController from '$lib/services/user-service';
import type { BackendUser } from '$lib/models/BackendUser';
import { startDB } from '$lib/db/db';
import { SessionTokenUser } from '$lib/models/user/SessionTokenUser';

startDB();

// https://kit.svelte.dev/docs/hooks
const noAuthURLs: string[] = ['/login', '/registration', '/about', '/impressum'];
Expand All @@ -9,7 +12,7 @@ export const handle: Handle = async ({ event, resolve }): Promise<Response> => {
const pathname: string = event.url.pathname;
const sessionCookie: string | undefined = event.cookies.get('session');
const valid: boolean = await userController.validateSessionToken(sessionCookie);
const currentUser: BackendUser | null = userController.extractUser(sessionCookie);
const currentUser: SessionTokenUser | null = userController.extractUser(sessionCookie);
if (currentUser) {
event.locals.currentUser = {
isAuthenticated: valid,
Expand Down
63 changes: 63 additions & 0 deletions src/lib/db/attributes/FestivalEventAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { FrontendFestivalEvent } from '$lib/models/festivalEvent/FrontendFestivalEvent';
import { loadFrontEndUserById } from '$lib/services/user-service';
import { BackendFestivalEvent } from '$lib/models/festivalEvent/BackendFestivalEvent';
import { Model } from 'sequelize';
import {
GuestInformationAttributes,
mapToBackendGuestInformation,
mapToFrontendGuestInformation
} from '$lib/db/attributes/GuestInformationAttributes';

export type FestivalEventAttributes = {
id: string;
name: string;
description: string;
bringYourOwnBottle: boolean;
bringYourOwnFood: boolean;
location: string;
createdAt: Date;
updatedAt: Date;
startDate: Date;
UserId: string;
GuestInformations: Model<GuestInformationAttributes, any>[];
};

export async function mapToFrontendFestivalEvent(event: FestivalEventAttributes): Promise<FrontendFestivalEvent> {
return {
id: event.id,
name: event.name,
bringYourOwnBottle: event.bringYourOwnBottle,
bringYourOwnFood: event.bringYourOwnFood,
createdAt: event.createdAt,
createdBy: (await loadFrontEndUserById(event.UserId)) ?? null,
description: event.description,
startDate: event.startDate,
location: event.location,
updatedAt: event.updatedAt,
frontendGuestInformation: event.GuestInformations
? await Promise.all(
event.GuestInformations.map((value) => {
return mapToFrontendGuestInformation(value.dataValues);
})
)
: []
};
}

export async function mapToBackendFestivalEvent(event: FestivalEventAttributes): Promise<BackendFestivalEvent> {
return {
id: event.id,
name: event.name,
bringYourOwnBottle: event.bringYourOwnBottle,
bringYourOwnFood: event.bringYourOwnFood,
createdAt: event.createdAt,
location: event.location,
description: event.description,
startDate: event.startDate,
UserId: event.UserId,
updatedAt: event.updatedAt,
guestInformation: event.GuestInformations.map((value) => {
return mapToBackendGuestInformation(value.dataValues);
})
};
}
7 changes: 7 additions & 0 deletions src/lib/db/attributes/FriendAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type FriendAttributes = {
id: string;
friend1Id: string;
friend2Id: string;
createdAt: Date;
updatedAt: Date;
};
18 changes: 18 additions & 0 deletions src/lib/db/attributes/FriendRequestAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { loadFrontEndUserById } from '$lib/services/user-service';
import { FriendRequestData } from '$lib/models/updates/FriendRequestData';

export type FriendRequestAttributes = {
id: string;
senderId: string;
receiverId: string;
createdAt: Date;
updatedAt: Date;
};

export async function convertToFriendRequest(attribute: FriendRequestAttributes): Promise<FriendRequestData> {
return {
id: attribute.id,
receivedFrom: await loadFrontEndUserById(attribute.receiverId),
sendTo: await loadFrontEndUserById(attribute.senderId)
};
}
42 changes: 42 additions & 0 deletions src/lib/db/attributes/GuestInformationAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BackendGuestInformation } from '$lib/models/guestInformation/BackendGuestInformation';
import { FrontendGuestInformation } from '$lib/models/guestInformation/FrontendGuestInformation';
import { loadFrontEndUserById } from '$lib/services/user-service';

export type GuestInformationAttributes = {
id: string;
festivalEventId: string;
food: string;
drink: string;
numberOfOtherGuests: number;
coming: boolean;
comment: string;
createdAt: Date;
updatedAt: Date;
FestivalEventId: string;
UserId: string;
};

export async function mapToFrontendGuestInformation(
dataValues: GuestInformationAttributes
): Promise<FrontendGuestInformation> {
return {
coming: dataValues.coming,
numberOfOtherGuests: dataValues.numberOfOtherGuests,
drink: dataValues.drink,
comment: dataValues.comment,
food: dataValues.food,
user: await loadFrontEndUserById(dataValues.UserId)
};
}

export function mapToBackendGuestInformation(dataValues: GuestInformationAttributes): BackendGuestInformation {
return {
UserId: dataValues.UserId,
FestivalEventId: dataValues.festivalEventId,
food: dataValues.food,
comment: dataValues.comment,
drink: dataValues.drink,
numberOfOtherGuests: dataValues.numberOfOtherGuests,
coming: dataValues.coming
};
}
6 changes: 6 additions & 0 deletions src/lib/db/attributes/SessionTokenAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface SessionTokenAttributes {
token: string;
UserId: string;
createdAt: Date;
updatedAt: Date;
}
25 changes: 25 additions & 0 deletions src/lib/db/attributes/UserAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { BackendUser } from '$lib/models/user/BackendUser';

export type UserAttributes = {
id: string;
password: string;
nickname: string;
forename: string;
lastname: string;
email: string;
createdAt: Date;
updatedAt: Date;
};

export function convertToBackendUser(dataValues: UserAttributes): BackendUser {
return {
id: dataValues.id,
email: dataValues.email,
nickname: dataValues.nickname,
forename: dataValues.forename,
lastname: dataValues.lastname,
updatedAt: dataValues.updatedAt,
createdAt: dataValues.createdAt,
password: dataValues.password
};
}
7 changes: 7 additions & 0 deletions src/lib/db/attributes/UserImageAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type UserImageAttributes = {
id: string;
UserId: string;
image: Buffer;
createdAt: Date;
updatedAt: Date;
};
Loading

0 comments on commit 626a76d

Please sign in to comment.