Skip to content

Commit

Permalink
Merge pull request #46 from techstartucalgary/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Axeloooo authored Jan 19, 2024
2 parents 5d59ca4 + 6b20337 commit 6d43499
Show file tree
Hide file tree
Showing 29 changed files with 506 additions and 353 deletions.
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

0 comments on commit 6d43499

Please sign in to comment.