Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added backend--/__pycache__/main.cpython-313.pyc
Binary file not shown.
Binary file not shown.
45 changes: 45 additions & 0 deletions backend--/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json

class Controllers :
def get_data(self):
with open("../dummyData.json") as File:
data = json.load(File)
return data

def get_all(self, min_total: int):
data = self.get_data()
data_sales = data["salesReps"]

result = []

for sales in data_sales:
# Pastikan 'deals' ada dan bukan kosong
if 'deals' in sales and sales['deals']:
closed_won_values = [deal['value'] for deal in sales['deals'] if deal['status'] == 'Closed Won']
total_closed_won = int(sum(closed_won_values))

if total_closed_won > min_total:
# Tambahkan total_closed_won sebagai string jika perlu
sales['total_closed_won'] = total_closed_won
result.append(sales)

return result

def find_by_id(self,id):
data = self.get_data()
data_sales = data["salesReps"]

result = next((item for item in data_sales if item['id'] == int(id)), None)

return result

def get_clients(self):
data = self.get_data()
data_sales = data["salesReps"]

result = []
for key, value in enumerate(data_sales):
result.append(value['clients'])

return result

67 changes: 67 additions & 0 deletions backend--/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from fastapi import FastAPI, Request, Query
from fastapi.responses import JSONResponse
from controllers.controllers import Controllers
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# List domain yang diizinkan
origins = [
"http://localhost:3000",
"http://webapi.localhost",
"http://127.0.0.1:3000",
"*", # ⚠️ Gunakan ini hanya untuk testing/dev, karena ini mengizinkan semua domain
]

# Tambahkan middleware CORS
app.add_middleware(
CORSMiddleware,
allow_origins=origins, # Bisa juga pakai ["*"]
allow_credentials=True,
allow_methods=["*"], # Mengizinkan semua method (GET, POST, etc.)
allow_headers=["*"], # Mengizinkan semua headers
)

API_TOKEN = "super-secret-token"

@app.middleware("http")
async def check_token(request: Request, call_next):
# Ambil token dari header Authorization
auth_header = request.headers.get("Authorization")

# if auth_header != f"Bearer {API_TOKEN}":
# return JSONResponse(
# status_code=401,
# content={"detail": "Unauthorized. Invalid or missing token."}
# )

# Eksekusi request ke route yang dituju
response = await call_next(request)

return response


@app.get("/")
def read_root():
return {"data": "Hello, FastAPI 🚀"}

@app.get("/api/v1/get-all")
def read_root(deal: int = Query(...)):
controller = Controllers()
data = controller.get_all(deal)

return {"data": data}

@app.get("/api/v1/get-by-id/{id}")
def read_root(id = int):
controller = Controllers()
data = controller.find_by_id(id)

return {"data": data}

@app.get("/api/v1/get-clients")
def read_root(id = int):
controller = Controllers()
data = controller.get_clients()

return {"data": data}
33 changes: 0 additions & 33 deletions backend/main.py

This file was deleted.

2 changes: 0 additions & 2 deletions backend/requirements.txt

This file was deleted.

41 changes: 41 additions & 0 deletions frontend--/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions frontend--/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
16 changes: 16 additions & 0 deletions frontend--/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
7 changes: 7 additions & 0 deletions frontend--/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
Loading