first commit
This commit is contained in:
7
backend/Dockerfile
Normal file
7
backend/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY . .
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "6000"]
|
||||
|
33
backend/main.py
Normal file
33
backend/main.py
Normal file
@ -0,0 +1,33 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from redis import Redis
|
||||
from datetime import datetime
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
redis_client = Redis(host="redis", port=6379, decode_responses=True)
|
||||
mongo_client = MongoClient("mongodb://mongo:27017")
|
||||
mongo_db = mongo_client["logs"]
|
||||
mongo_col = mongo_db["actions"]
|
||||
|
||||
class Action(BaseModel):
|
||||
user: str
|
||||
type: str
|
||||
|
||||
@app.post("/action")
|
||||
async def log_action(action: Action):
|
||||
entry = {
|
||||
"user": action.user,
|
||||
"type": action.type,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
}
|
||||
redis_client.rpush("user_actions", json.dumps(entry))
|
||||
return {"status": "saved to redis"}
|
||||
|
||||
@app.get("/actions")
|
||||
async def get_actions():
|
||||
actions = list(mongo_col.find({}, {"_id": 0}))
|
||||
return actions
|
||||
|
6
backend/requirements.txt
Normal file
6
backend/requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
redis
|
||||
pydantic
|
||||
pymongo
|
||||
|
Reference in New Issue
Block a user