Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #46

Merged
merged 35 commits into from
Jan 19, 2024
Merged

Dev #46

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e4c7d72
fix: Github Actions error fixed
Axeloooo Nov 19, 2023
4afa61a
Continuous integration badge added
Axeloooo Nov 19, 2023
0664f6b
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
34bea91
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
5b2b3b0
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
86c1557
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
9c928c7
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
2472e59
fix: Continuous integration improvements
Axeloooo Nov 19, 2023
a523699
Merge pull request #19 from techstartucalgary/fix/github-actions
Axeloooo Nov 19, 2023
c9f0789
feat: Session middleware with redis
Axeloooo Nov 20, 2023
7bdc628
docs: Documentation for installation updated
Axeloooo Nov 24, 2023
95167d9
Merge pull request #23 from techstartucalgary/feature/redis-session-s…
Axeloooo Nov 24, 2023
c0ecdac
feat: Backend cleaned up and connection with database created
Axeloooo Jan 14, 2024
2f1bcce
fix: Continuous integration issue with imports resolved
Axeloooo Jan 14, 2024
f3afbc0
Merge pull request #38 from techstartucalgary/feature/redis-session-s…
Axeloooo Jan 14, 2024
d2e4360
docs: Badges added, typo in tech corrected and instructions updated
Axeloooo Jan 14, 2024
95996a4
Merge pull request #39 from techstartucalgary/docs/general-description
Axeloooo Jan 14, 2024
3a37971
docs: MIT license attached to the repository
Axeloooo Jan 14, 2024
6a96f33
Merge pull request #40 from techstartucalgary/docs/license
Axeloooo Jan 14, 2024
eab7aeb
database setup
aligstanley Jan 14, 2024
423c72d
Merge pull request #41 from techstartucalgary/database_setup-branch
Axeloooo Jan 16, 2024
f93ace6
feat: Prisma user model created
Axeloooo Jan 16, 2024
8c00546
feat: Product and order prisma models updated
Axeloooo Jan 16, 2024
3476048
Merge branch 'dev' into feature/prisma-user-model
Axeloooo Jan 16, 2024
4679891
feat: Database synced with Planetscale
Axeloooo Jan 16, 2024
39c22ba
Merge pull request #42 from techstartucalgary/feature/prisma-user-model
Axeloooo Jan 16, 2024
dc8df7b
docs: PlanetScale badge added to documentation
Axeloooo Jan 16, 2024
352e643
Merge pull request #43 from techstartucalgary/docs/badges-update
Axeloooo Jan 16, 2024
2d9a1ed
Created API
ryanjung1998 Jan 17, 2024
56cf490
Merge pull request #44 from techstartucalgary/api
Axeloooo Jan 18, 2024
dd1ed40
Delete .DS_Store
Axeloooo Jan 18, 2024
af4f80a
fix: .DS_Store file added to .gitignore file
Axeloooo Jan 18, 2024
61a4c6b
feat: Product router, controller, service and repository created
Axeloooo Jan 18, 2024
9ae2c59
Merge pull request #45 from techstartucalgary/feature/products-endpoint
Axeloooo Jan 18, 2024
6b20337
Merge branch 'main' into dev
Axeloooo Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions backend/.github/workflows/ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ on:
branches:
- main
- dev

jobs:

testing:
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install dependencies
run: npm install
run: cd backend && npm install

- name: Test
run: npm run test
- name: Build
run: cd backend && npm run build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
.env
dist
migrations
.vscode
.DS_Store
.vscode
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 techstartucalgary

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 35 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# ♻️ ReThread

[![Continuous Integration](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml/badge.svg)](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml)
![GitHub repo size](https://img.shields.io/github/repo-size/techstartucalgary/rethread?logo=github&color=blue)
![Github tag](https://img.shields.io/github/v/tag/techstartucalgary/rethread?logo=github&color=red)
![GitHub contributors](https://img.shields.io/github/contributors/techstartucalgary/rethread?logo=github&color=yellow)
![Github pull requests](https://img.shields.io/github/issues-pr/techstartucalgary/rethread?logo=github)
![Github license](https://img.shields.io/github/license/techstartucalgary/rethread?logo=github&color=orange)

## 📖 Table of Contents

- [📝 Contributors](#-contributors)
- [👨‍💻 Teck Stack](#-tech-stack)
- [👨‍💻 Tech Stack](#-tech-stack)
- [🚀 Backend Documentation](#-backend-documentation)
- [🏃 Quickstart](#-quickstart)
- [🏃 Quick start](#-quick-start)
- [🛠️ Installation](#️-installation)
- [🧪 Testing](#-testing)
- [🚧 Development Environment](#-development-environment)
Expand Down Expand Up @@ -34,38 +41,27 @@

![Swift](https://img.shields.io/badge/Swift-F05138.svg?style=for-the-badge&logo=Swift&logoColor=white)
![SwiftUI](https://img.shields.io/badge/SwiftUI-2d68f3.svg?style=for-the-badge&logo=Swift&logoColor=black)
![Xcode](https://img.shields.io/badge/Xcode-1575F9.svg?style=for-the-badge&logo=Xcode&logoColor=white)
![Figma](https://img.shields.io/badge/Figma-F24E1E.svg?style=for-the-badge&logo=Figma&logoColor=white)

- Testing

![XCTest](https://img.shields.io/badge/XCTest-6ACD4D.svg?style=for-the-badge&logo=Apple&logoColor=white)
![Xcode](https://img.shields.io/badge/Xcode-1575F9.svg?style=for-the-badge&logo=Xcode&logoColor=white)

- Backend

![Typescript](https://img.shields.io/badge/TypeScript-3178C6.svg?style=for-the-badge&logo=TypeScript&logoColor=white)
![Node.js](https://img.shields.io/badge/Node.js-339933.svg?style=for-the-badge&logo=nodedotjs&logoColor=white)
![Express](https://img.shields.io/badge/Express-000000.svg?style=for-the-badge&logo=Express&logoColor=white)
![OpenAI](https://img.shields.io/badge/OpenAI-412991.svg?style=for-the-badge&logo=OpenAI&logoColor=white)
![Prisma](https://img.shields.io/badge/Prisma-2D3748.svg?style=for-the-badge&logo=Prisma&logoColor=white)
![MySQL](https://img.shields.io/badge/MySQL-4479A1.svg?style=for-the-badge&logo=MySQL&logoColor=white)
![Redis](https://img.shields.io/badge/Redis-DC382D.svg?style=for-the-badge&logo=Redis&logoColor=white)

- Testing

![Mocha](https://img.shields.io/badge/Mocha-8D6748.svg?style=for-the-badge&logo=Mocha&logoColor=white)
![Chai](https://img.shields.io/badge/Chai-A30701.svg?style=for-the-badge&logo=Chai&logoColor=white)
![Node.js](https://img.shields.io/badge/Node.js-339933.svg?style=for-the-badge&logo=nodedotjs&logoColor=white)
![Prisma](https://img.shields.io/badge/Prisma-5a67d8.svg?style=for-the-badge&logo=Prisma&logoColor=white)
![MySQL](https://img.shields.io/badge/MySQL-3e6e93.svg?style=for-the-badge&logo=MySQL&logoColor=white)

- CI/CD
- Cloud

![GitHub Actions](https://img.shields.io/badge/GitHub%20Actions-2088FF.svg?style=for-the-badge&logo=GitHub%20Actions&logoColor=white)
![PlanetScale](https://img.shields.io/badge/PlanetScale-000000.svg?style=for-the-badge&logo=PlanetScale&logoColor=white)


## 🚀 Backend Documentation

All the code is located in the `backend/src` directory. The backend is written using [Node.js](https://nodejs.org/en/) and [Express](https://expressjs.com/).

### 🏃 Quickstart
### 🏃 Quick start

1. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

Expand All @@ -85,18 +81,6 @@ cd fashion
cd backend
```

4. Run `npm install --only=production` to install all the dependencies.

```bash
npm install
```

5. Run `npm run start` to start the server.

```bash
npm run start
```

### 🛠️ Installation

1. Make sure you have `Node.js` and `NPM` installed on your machine. Click [here](https://nodejs.org/en/) to download and install Node.js. Make sure you install the LTS version. NPM is installed automatically when you install Node.js.
Expand All @@ -115,25 +99,17 @@ npm -v

4. If you see the version number of `Node.js` and `npm` then you are good to go. If not, then try to reinstall `Node.js`.

5. Make sure you have `MySQL` installed on your machine. Click [here](https://dev.mysql.com/downloads/mysql/) to download and install MySQL. Make sure you install the latest version.
5. Make sure you have `Docker Desktop` installed on your machine. Click [here](https://www.docker.com/products/docker-desktop) to download and install Docker Desktop. Make sure you install the latest version.

6. Open the terminal and run `mysql --version` to check if `MySQL` is installed.
6. Make sure you have `Git` installed on your machine. Click [here](https://git-scm.com/downloads) to download and install Git. Make sure you install the latest version.

```bash
mysql --version
```

7. If you see the version number of `MySQL` then you are good to go. If not, then try to reinstall `MySQL`.

8. Make sure you have `Redis` installed on your machine. Click [here](https://redis.io/download) to download and install Redis. Make sure you install the latest version.

9. Open the terminal and run `redis-server --version` to check if `Redis` is installed.
7. Open the terminal and run `git -v` to check if `Git` is installed.

```bash
redis-server --version
git -v
```

10. If you see the version number of `Redis` then you are good to go. If not, then try to reinstall `Redis`.
8. If you see the version number of `Git` then you are good to go. If not, then try to reinstall `Git`.

### 🧪 Testing

Expand Down Expand Up @@ -189,16 +165,26 @@ cd backend
npm install
```

5. Run `npm run start` to start the server.
5. Run `npx prisma init` to initialize the database.

```bash
npm run dev
npx prisma init
```

6. Update your `prisma/schema.prisma` file within the `backend` folder to use the `mysql` provider and set the relation mode type to `prisma`.

```prisma
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
```

6. Run `npx prisma studio` to open Prisma Studio and view the database schema (Optional).
7. Once you are ready to push your schema to PlanetScale, run `prisma db push` against your PlanetScale database to update the schema in your database.

```bash
npx prisma studio
npx prisma db push
```


Expand Down
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
9 changes: 3 additions & 6 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
"type": "module",
"scripts": {
"build": "npx tsc",
"prestart": "npx prisma migrate deploy && npx prisma generate",
"start": "NODE_ENV=PROD node dist/src/index.js",
"predev": "npx prisma migrate dev --name init && npx prisma generate",
"dev": "NODE_ENV=DEV nodemon -e ts --exec \"npm run build && node dist/src/index.js\"",
"pretest": "npx prisma migrate deploy && npx prisma generate",
"test": "NODE_ENV=TEST npm run build && mocha \"dist/test/**/*.test.js\""
"start": "node dist/src/index.js",
"dev": "nodemon -e ts --exec \"npm run build && node dist/src/index.js\"",
"test": "npm run build && mocha \"dist/test/**/*.test.js\""
},
"keywords": [],
"author": "",
Expand Down
45 changes: 36 additions & 9 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,43 @@ generator client {
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

model User {
model Product {
id String @id @default(uuid())
title String @unique
size String
color String
description String
gender String
category String
price Float
imageUrl String @map("image_url")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
}

model Order {
id String @id @default(uuid())
email String @unique
password String
firstName String
lastName String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String
productId Int @map("product_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
}

model User {
id String @id @default(uuid())
phoneNumber String @unique @map("phone_number")
email String @unique
password String
firstName String @map("first_name")
lastName String @map("last_name")
gender String
postalCode String @map("postal_code")
dateOfBirth DateTime @map("date_of_birth")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
}
34 changes: 34 additions & 0 deletions backend/src/abstracts/product.abstract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
type PrismaProduct = {
id: string;
title: string;
size: string;
color: string;
description: string;
gender: string;
category: string;
price: number;
imageUrl: string;
createdAt: Date;
updatedAt: Date;
};

type PrismaProducts = PrismaProduct[];

abstract class ProductProvider {
abstract getProducts(): Promise<PrismaProducts | Error>;

abstract getProductById(id: string): Promise<PrismaProduct | Error>;

abstract createProduct(
title: string,
size: string,
color: string,
description: string,
gender: string,
category: string,
price: number,
imageUrl: string
): Promise<PrismaProduct | Error>;

abstract deleteProduct(id: string): Promise<PrismaProduct | Error>;
}
8 changes: 4 additions & 4 deletions backend/src/controllers/algorithm.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response, NextFunction } from "express";
import { BadRequestError } from "../errors/errors.js";
import { HttpBadRequestError } from "../errors/http.error.js";
import { AlgorithmServiceInterface } from "../../types.js";

class AlgorithmController {
Expand All @@ -13,7 +13,7 @@ class AlgorithmController {
try {
const prompt: string = req.body.prompt;
if (!prompt) {
return next(new BadRequestError("No string was provided!"));
return next(new HttpBadRequestError());
}

const isEcoFriendly: boolean =
Expand All @@ -23,8 +23,8 @@ class AlgorithmController {
return res.status(200).json("Clothing is not eco-friendly!");
}
return res.status(200).json("Clothing is eco-friendly!");
} catch (err) {
next(err);
} catch (e) {
next(e);
}
};
}
Expand Down
35 changes: 0 additions & 35 deletions backend/src/controllers/authentication.controller.ts

This file was deleted.

Loading