Skip to content

Commit

Permalink
Merge pull request #42 from GTBitsOfGood/samrat/integration
Browse files Browse the repository at this point in the history
Samrat/integration
  • Loading branch information
SamratSahoo authored Mar 5, 2024
2 parents 0380e07 + 9a388cd commit 23ba1cb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/src/actions/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ export const getProjectByServerKey = async (serverApiKey: string): Promise<Proje
export const deleteProjectById = async (projectId: string) => {
await dbConnect();
return await ProjectModel.findOneAndDelete({ _id: projectId });
}

export const getAllProjects = async () => {
await dbConnect();
return await ProjectModel.find({}).select("projectName _id");

}
14 changes: 13 additions & 1 deletion api/src/controllers/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProject } from "@/src/actions/project";
import { createProject, getAllProjects, getProjectIDByName } from "@/src/actions/project";
import { relogRequestHandler } from "@/src/middleware/request-middleware";
import APIWrapper from "@/src/utils/api-wrapper";
import { Project } from "@/src/utils/types";
Expand All @@ -24,10 +24,22 @@ const projectRoute = APIWrapper({
projectName, clientApiKey, serverApiKey
}

const preexistingProject = await getProjectIDByName(projectName);
if (preexistingProject) {
throw new Error("A project with this name already exists")
}

const createdProject = await createProject(project);
return createdProject
},
},
GET: {
config: {},
handler: async (req: Request) => {
return getAllProjects();
}
}

});

export const project = relogRequestHandler(projectRoute);
3 changes: 2 additions & 1 deletion api/src/models/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose from "mongoose";
import mongoose, { trusted } from "mongoose";
import { Project } from "@/src/utils/types";

export const ProjectSchema = new mongoose.Schema<Project>({
Expand All @@ -13,6 +13,7 @@ export const ProjectSchema = new mongoose.Schema<Project>({
projectName: {
type: String,
required: true,
unique: true
},
},
{
Expand Down
11 changes: 9 additions & 2 deletions dashboard/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests
from utils import EventTypes

base_url = "https://analytics.bitsofgood.org"
base_url = "http://api:3001"


def get_default_after_time():
Expand Down Expand Up @@ -119,4 +119,11 @@ def get_event_types(project_name):

def get_projects():
# When we have the project api setup, we will want to retrieve real projects
return [f"project_{i}" for i in range(0, 3)]
return ["project_1", "project_2", "project_3"]

project_url = base_url + "/api/project"

response = requests.get(project_url)
response.raise_for_status() # error
response = response.json()
return [project["projectName"] for project in response["payload"]]
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:
volumes:
- ./dashboard:/app
- ./dashboard/venv:/app/venv
networks:
- bog-analytics-net

example-app:
build:
Expand Down

0 comments on commit 23ba1cb

Please sign in to comment.