Skip to content

Commit 9d739a1

Browse files
committed
Initial commit
0 parents  commit 9d739a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6080
-0
lines changed

REACME.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# プロジェクトのセットアップ
2+
3+
## 前提条件
4+
このプロジェクトを開始する前に、以下のソフトウェアがインストールされている必要があります:
5+
6+
- **MongoDB**
7+
- **Node.js****npm**
8+
- **Python**
9+
10+
## セットアップ手順
11+
12+
### フロントエンドのセットアップ
13+
1. ターミナルでプロジェクトのフロントエンドディレクトリに移動します。
14+
```sh
15+
cd frontend
16+
```
17+
18+
2. `yarn install`コマンドを実行して依存関係をインストールします。
19+
```sh
20+
yarn install
21+
```
22+
23+
### バックエンドのセットアップ
24+
1. ターミナルでプロジェクトのバックエンドディレクトリに移動します。
25+
```sh
26+
cd backend
27+
```
28+
29+
2. 仮想環境を作成します。
30+
```sh
31+
python3 -m venv venv
32+
```
33+
34+
3. 仮想環境を有効化します。
35+
- **macOS/Linux**:
36+
```sh
37+
source venv/bin/activate
38+
```
39+
- **Windows**:
40+
```sh
41+
venv\Scripts\activate
42+
```
43+
44+
4. `requirements.txt`から依存関係をインストールします。
45+
```sh
46+
pip install -r requirements.txt
47+
```
48+
49+
### サービスの開始
50+
1. ターミナルでMongoDBを開始します。
51+
```sh
52+
sudo systemctl start mongod
53+
```
54+
55+
2. フロントエンド開発サーバーを起動します。
56+
```sh
57+
cd frontend
58+
yarn dev
59+
```
60+
61+
3. バックエンド開発サーバーを起動します。
62+
```sh
63+
cd backend
64+
uvicorn app.main:app --reload
65+
```
66+
67+
## アクセス
68+
- フロントエンドは [http://localhost:5173](http://localhost:5173) で利用可能です。
69+
- バックエンドは [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) で利用可能です。
70+
- データベースは [mongodb://localhost:27017](mongodb://localhost:27017) で利用可能です。
71+
72+

backend/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Python virtual environment
2+
.venv/
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
pip-wheel-metadata/
27+
share/python-wheels/
28+
29+
# Installer logs
30+
pip-log.txt
31+
pip-delete-this-directory.txt
32+
33+
# Unit test / coverage reports
34+
htmlcov

backend/app/__init__.py

Whitespace-only changes.

backend/app/cruds/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from pymongo import MongoClient
2+
from datetime import datetime, timezone, timedelta
3+
from bson import ObjectId
4+
5+
client = MongoClient('mongodb://localhost:27017/')
6+
7+
db = client['fastapi_react_database']
8+
9+
collection = db['notifications']
10+
11+
12+
def notification_post(id,message):
13+
utc_now = datetime.now(timezone.utc)
14+
jst = timezone(timedelta(hours=9))
15+
jst_now = utc_now.astimezone(jst)
16+
doc = {
17+
"id":id,
18+
"message": message,
19+
"time": jst_now.strftime('%Y/%m/%d %H:%M:%S')
20+
}
21+
collection.insert_one(doc)
22+
23+
def notification_delete(id):
24+
collection.delete_one({"id": id})
25+
26+
def notifications_get():
27+
notifications = list(collection.find())
28+
for notification in notifications:
29+
notification["_id"] = str(notification["_id"])
30+
return notifications
31+
32+
def notification_get(id):
33+
notification = collection.find_one({"id":id})
34+
notification["_id"] = str(notification["_id"])
35+
return notification

backend/app/cruds/todo_cruds.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from pymongo import MongoClient
2+
from datetime import datetime
3+
from bson import ObjectId
4+
5+
client = MongoClient('mongodb://localhost:27017/')
6+
7+
db = client['fastapi_react_database']
8+
9+
collection = db['todos']
10+
11+
12+
def todo_post(id,todo,priority,date:datetime,detail):
13+
doc = {
14+
"id":id,
15+
"todo":todo,
16+
"priority":priority,
17+
"date":date,
18+
"detail":detail
19+
}
20+
collection.insert_one(doc)
21+
22+
def todo_delete(id):
23+
collection.delete_one({"id": id})
24+
25+
def todos_get():
26+
todos = list(collection.find())
27+
for todo in todos:
28+
todo["_id"] = str(todo["_id"])
29+
return todos
30+
31+
def todo_get(id):
32+
todo = collection.find_one({"id":id})
33+
todo["_id"] = str(todo["_id"])
34+
return todo
35+
36+
def todo_put(id,todo,priority,date:datetime,detail):
37+
new = {
38+
"todo":todo,
39+
"priority":priority,
40+
"date":date,
41+
"detail":detail
42+
}
43+
collection.update_one({"id":id}, {"$set":new})

backend/app/cruds/user_cruds.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from pymongo import MongoClient
2+
3+
client = MongoClient('mongodb://localhost:27017/')
4+
5+
db = client['fastapi_react_database']
6+
7+
collection = db['users']
8+
9+
10+
def user_post(id,name,username,email,phone):
11+
doc = {
12+
"id":id,
13+
"name":name,
14+
"username":username,
15+
"email":email,
16+
"phone":phone
17+
}
18+
collection.insert_one(doc)
19+
20+
def user_delete(id):
21+
collection.delete_one({"id": id})
22+
23+
def users_get():
24+
users = list(collection.find())
25+
for user in users:
26+
user["_id"] = str(user["_id"])
27+
return users
28+
29+
def user_get(id):
30+
user = collection.find_one({"id":id})
31+
user["_id"] = str(user["_id"])
32+
return user
33+
34+
def user_put(id, name,username,email,phone):
35+
new = {
36+
"name":name,
37+
"username":username,
38+
"email":email,
39+
"phone":phone
40+
}
41+
collection.update_one({"id":id}, {"$set":new})

backend/app/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
4+
from app.routers import notifications, todos, users
5+
6+
app = FastAPI()
7+
8+
# CORS設定
9+
origins = [
10+
"http://localhost:5173",
11+
]
12+
13+
app.add_middleware(
14+
CORSMiddleware,
15+
allow_origins=origins,
16+
allow_credentials=True,
17+
allow_methods=["*"],
18+
allow_headers=["*"],
19+
)
20+
21+
app.include_router(notifications.router)
22+
app.include_router(todos.router)
23+
app.include_router(users.router)
24+

backend/app/routers/__init__.py

Whitespace-only changes.

backend/app/routers/notifications.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from fastapi import APIRouter, HTTPException
2+
from app.cruds.notification_cruds import notifications_get, notification_get, notification_delete, notification_post
3+
from pydantic import BaseModel
4+
5+
router = APIRouter()
6+
7+
class Notification(BaseModel):
8+
id: str
9+
message: str
10+
11+
@router.get("/notifications")
12+
async def get_notifications():
13+
notifications = notifications_get()
14+
return notifications
15+
16+
@router.get("/notifications/{notification_id}", response_model=Notification)
17+
async def get_notification(notification_id):
18+
notification = notification_get(notification_id)
19+
if notification:
20+
return notification
21+
raise HTTPException(status_code=404, detail="Notification not found")
22+
23+
@router.post("/notifications")
24+
async def post_notifications(notification:Notification):
25+
notification_post(notification.id, notification.message)
26+
return {"message":"Notification created successfully"}
27+
28+
@router.delete("/notifications/{notification_id}")
29+
async def delete_notifications(notification_id):
30+
try:
31+
notification_delete(notification_id)
32+
return {"message": "Notification deleted successfully"}
33+
except Exception as e:
34+
raise HTTPException(status_code=404, detail=f"Notification not found: {e}")

0 commit comments

Comments
 (0)