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
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Virtual environments
.venv/
venv/
env/

# VS Code and IDE directories
.vscode/
.idea/

# Test and cache directories
.pytest_cache/
.mypy_cache/

# OS files
.DS_Store
Thumbs.db

# Environment files
.env
.env.*

# Node.js
node_modules/
dist/
build/
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<<<<<<< HEAD
# swtval

Simple FastAPI app.

## Setup

```powershell
python -m venv .venv
# My Sweet Valentine

My Sweet Valentine is an online marketplace designed to provide customers with a wide array of gift options for both men and women, including gender-specific gifts tailored to their preferences.
Expand All @@ -24,6 +33,26 @@ My Sweet Valentine is an online marketplace designed to provide customers with a
- **Version Control**: Git and GitHub for collaborative development
- **Deployment**: Heroku or AWS for hosting the application

## Local API (FastAPI)

This repository also includes a minimal FastAPI app for local API testing.

### Setup

```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
```

### Run

```powershell
python -m uvicorn main:app --reload
```

App will be available at http://127.0.0.1:8000/.

## Project Timeline

- **Week 1-2**: Planning and Research, Define User Stories, UI/UX Design
Expand Down
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const axios = require("axios");

async function callPythonAPI() {
try {
const response = await axios.get("http://127.0.0.1:8000/");
console.log("Python API says:", response.data);

const user = await axios.get("http://127.0.0.1:8000/users/5");
console.log("User:", user.data);
} catch (error) {
console.error("Error calling API:", error.message);
}
}

callPythonAPI();
63 changes: 63 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/users/{user_id}")
def get_user(user_id: int):
return {"user_id": user_id, "name": "Ayodeji"}

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel

app = FastAPI()

# -----------------------------
# Data Model
# -----------------------------
class User(BaseModel):
name: str
email: str

# Fake in-memory database
users = {}

# -----------------------------
# CREATE (POST)
# -----------------------------
@app.post("/users")
def create_user(user: User):
user_id = len(users) + 1
users[user_id] = user
return {"id": user_id, "user": user}

# -----------------------------
# READ (GET)
# -----------------------------
@app.get("/users/{user_id}")
def get_user(user_id: int):
if user_id not in users:
raise HTTPException(status_code=404, detail="User not found")
return {"id": user_id, "user": users[user_id]}

# -----------------------------
# UPDATE (PUT)
# -----------------------------
@app.put("/users/{user_id}")
def update_user(user_id: int, updated_user: User):
if user_id not in users:
raise HTTPException(status_code=404, detail="User not found")
users[user_id] = updated_user
return {"id": user_id, "user": updated_user}

# -----------------------------
# DELETE (DELETE)
# -----------------------------
@app.delete("/users/{user_id}")
def delete_user(user_id: int):
if user_id not in users:
raise HTTPException(status_code=404, detail="User not found")
del users[user_id]
return {"message": "User deleted successfully"}
Loading