Skip to content

Commit

Permalink
Merge pull request #6 from GenerateNU/fixing-fe-to-connect
Browse files Browse the repository at this point in the history
Fixing some FE connections to connect the app
  • Loading branch information
leoRysing authored Jan 15, 2024
2 parents b3946ee + 701cada commit 75f2b93
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ backend-format:
cd backend && go fmt

# Build the docker db
.PHONY: backend-docker
.PHONY: db-run
backend-docker:
docker-compose up

Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Algo
Fullstack application for the Algo project

<!-- Github Actions -->
<a href="https://github.com/GenerateNU/Algo/actions/workflows/CI.yml">
<img src="https://github.com/GenerateNU/Algo/actions/workflows/CI.yml/badge.svg"
alt="Workflow Status" />
</a>

## Quick Start

```git clone [email protected]:GenerateNU/Algo.git```
Expand All @@ -9,8 +15,8 @@ Fullstack application for the Algo project
First, understand the tech stack:

- The database is [PostGreSQL](https://www.postgresql.org/) and will be containerized using [Docker](https://www.docker.com/).
- The backend is [Golang](https://go.dev/) with [Echo](https://echo.labstack.com/)
- The frontend is [ReactNative](https://reactnative.dev/) with [TypeScript](https://www.typescriptlang.org/) and uses [Expo](https://expo.dev/) as a build tool and [React Navigation](https://reactnavigation.org/)
- The backend is [Golang](https://go.dev/) with [Gin](https://gin-gonic.com/)
- The frontend is [ReactNative](https://reactnative.dev/) with [TypeScript](https://www.typescriptlang.org/) and uses [Expo](https://expo.dev/) as a build tool, [React Navigation](https://reactnavigation.org/) for navigation, and [NativeWind](https://www.nativewind.dev) + [React Native Paper](https://reactnativepaper.com/) for styling


Before compiling and running our application, we need to install several languages, package managers, and various tools.
Expand All @@ -37,8 +43,10 @@ We will be using some tools to make development a bit easier.

- [Swagger](https://github.com/swaggo/swag) - Will allow us to visualize the API and query requests from the database.
- [Makefile](https://opensource.com/article/18/8/what-how-makefile) - Will allow us to easily run scripts by consolidating them into Makefile commands. Make sure to read up about each command and ask questions. You should know what you are running!
- [xcode](https://docs.expo.dev/workflow/ios-simulator/) - A simulator to view the code on an iphone from a laptop
- [android studio](https://docs.expo.dev/workflow/android-studio-emulator) - An emulator to view the code on an android device from a laptop

If you wish to simulate the app on a phone on your computer, the following will work;
- [Xcode](https://docs.expo.dev/workflow/ios-simulator/) - A simulator to view the code on an iphone from a laptop
- [Android Studio](https://docs.expo.dev/workflow/android-studio-emulator) - An emulator to view the code on an android device from a laptop

### Third party integrations
For this project, we will be using some third-party APIs.
Expand All @@ -53,8 +61,15 @@ We will be containerizing our PostGreSQL database in Docker. Follow the steps be
1. Install [Docker](https://docs.docker.com/get-docker/)
You should be able to run `docker` in your terminal if this was successful.
2. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
3. Run `docker-compose up` from the root directory, this will spin up a postgres image.
3. Run `make db-run` from the root directory, this will spin up a postgres image.

### Backend
1. From root directory, run `make backend-run`
2. Once this has succesfuly spun up, run `make backend-ngrok`. This is necessary for connecting to a the different emulators, or your own phone if you download Expo Go.

### Frontend
1. From the root diectory, as long as you've already run `make frontend-dep` recently, run `make frontend-run`. This will start the expo app.
2. Starting an expo app has choices; it comes prepackeged with a QR code, which you can scan to open the app in Expo Go
3. If you want to run the app on your computer, you will need to make sure you spin up the relevant emulator. This is either an Android Studio emulator if you want to run on Android, or an XCode simulator if you want to run on iOS
4. To run on android, press **a**. To run on iOS, press **i**

104 changes: 104 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/users/": {
"get": {
"description": "Returns all users",
"produces": [
"application/json"
],
"tags": [
"user"
],
"summary": "Gets all users",
"operationId": "get-all-users",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.User"
}
}
},
"404": {
"description": "Failed to fetch users",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
"models.User": {
"type": "object",
"required": [
"email",
"first_name",
"last_name",
"pass_word"
],
"properties": {
"created_at": {
"type": "string",
"example": "2023-09-20T16:34:50Z"
},
"email": {
"type": "string"
},
"first_name": {
"type": "string"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string"
},
"pass_word": {
"type": "string"
},
"updated_at": {
"type": "string",
"example": "2023-09-20T16:34:50Z"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "",
BasePath: "/api",
Schemes: []string{},
Title: "Algo API",
Description: "API for Algo App",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
79 changes: 79 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"swagger": "2.0",
"info": {
"description": "API for Algo App",
"title": "Algo API",
"contact": {},
"version": "1.0"
},
"basePath": "/api",
"paths": {
"/api/users/": {
"get": {
"description": "Returns all users",
"produces": [
"application/json"
],
"tags": [
"user"
],
"summary": "Gets all users",
"operationId": "get-all-users",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.User"
}
}
},
"404": {
"description": "Failed to fetch users",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
"models.User": {
"type": "object",
"required": [
"email",
"first_name",
"last_name",
"pass_word"
],
"properties": {
"created_at": {
"type": "string",
"example": "2023-09-20T16:34:50Z"
},
"email": {
"type": "string"
},
"first_name": {
"type": "string"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string"
},
"pass_word": {
"type": "string"
},
"updated_at": {
"type": "string",
"example": "2023-09-20T16:34:50Z"
}
}
}
}
}
54 changes: 54 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
basePath: /api
definitions:
models.User:
properties:
created_at:
example: "2023-09-20T16:34:50Z"
type: string
email:
type: string
first_name:
type: string
id:
example: 1
type: integer
last_name:
type: string
pass_word:
type: string
updated_at:
example: "2023-09-20T16:34:50Z"
type: string
required:
- email
- first_name
- last_name
- pass_word
type: object
info:
contact: {}
description: API for Algo App
title: Algo API
version: "1.0"
paths:
/api/users/:
get:
description: Returns all users
operationId: get-all-users
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/models.User'
type: array
"404":
description: Failed to fetch users
schema:
type: string
summary: Gets all users
tags:
- user
swagger: "2.0"
1 change: 1 addition & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "backend/docs"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand Down
50 changes: 50 additions & 0 deletions backend/src/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"basePath": "/",
"definitions": {
"types.User": {
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"email": {
"type": "string"
},
"pass_word": {
"type": "string"
}
},
"type": "object"
}
},
"info": {
"contact": {},
"description": "This is an API for the Algo App.",
"title": "Algo API",
"version": "1.0"
},
"paths": {
"/users": {
"get": {
"description": "get all users in the database",
"responses": {
"200": {
"description": "OK",
"schema": {
"items": {
"$ref": "#/definitions/types.User"
},
"type": "array"
}
}
},
"summary": "Get All users",
"tags": ["users"]
}
}
},
"swagger": "2.0"
}

33 changes: 33 additions & 0 deletions backend/src/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
basePath: /
definitions:
types.User:
properties:
first_name:
type: string
last_name:
type: string
email:
type: string
pass_word:
type: string
type: object
info:
contact: {}
description: This is an API for the Algo App.
title: Algo API
version: "1.0"
paths:
/users:
get:
description: get all users in the database
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/types.User'
type: array
summary: Get All users
tags:
- users
swagger: "2.0"
Loading

0 comments on commit 75f2b93

Please sign in to comment.