Skip to content

Commit 7afc977

Browse files
authored
Add files via upload
1 parent 7ff5ad1 commit 7afc977

File tree

11 files changed

+288
-0
lines changed

11 files changed

+288
-0
lines changed

api-docker-file.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.9
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt requirements.txt
6+
RUN pip install -r requirements.txt
7+
8+
COPY . .
9+
10+
CMD ["python", "app.py"]

app-py.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from flask import Flask, request, jsonify
2+
from flask_sqlalchemy import SQLAlchemy
3+
4+
app = Flask(__name__)
5+
app.config['SQLALCHEMY_DATABASE_URI'] = 'mssql+pyodbc://username:password@localhost/RecipesDB?driver=ODBC+Driver+17+for+SQL+Server'
6+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
7+
db = SQLAlchemy(app)
8+
9+
class Recipe(db.Model):
10+
id = db.Column(db.Integer, primary_key=True)
11+
name = db.Column(db.String(100), nullable=False)
12+
ingredients = db.Column(db.Text, nullable=False)
13+
steps = db.Column(db.Text, nullable=False)
14+
preparation_time = db.Column(db.Integer, nullable=False)
15+
ratings = db.relationship('Rating', backref='recipe', lazy=True)
16+
comments = db.relationship('Comment', backref='recipe', lazy=True)
17+
18+
class Rating(db.Model):
19+
id = db.Column(db.Integer, primary_key=True)
20+
rating = db.Column(db.Integer, nullable=False)
21+
recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id'), nullable=False)
22+
23+
class Comment(db.Model):
24+
id = db.Column(db.Integer, primary_key=True)
25+
text = db.Column(db.Text, nullable=False)
26+
recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id'), nullable=False)
27+
28+
# API Endpoints
29+
@app.route('/recipes', methods=['POST'])
30+
def add_recipe():
31+
# Implementation for adding a recipe
32+
pass
33+
34+
@app.route('/recipes', methods=['GET'])
35+
def get_recipes():
36+
# Implementation for getting all recipes
37+
pass
38+
39+
@app.route('/recipes/<int:recipe_id>', methods=['GET'])
40+
def get_recipe(recipe_id):
41+
# Implementation for getting a specific recipe
42+
pass
43+
44+
@app.route('/recipes/<int:recipe_id>', methods=['PUT'])
45+
def update_recipe(recipe_id):
46+
# Implementation for updating a specific recipe
47+
pass
48+
49+
@app.route('/recipes/<int:recipe_id>', methods=['DELETE'])
50+
def delete_recipe(recipe_id):
51+
# Implementation for deleting a specific recipe
52+
pass
53+
54+
@app.route('/recipes/<int:recipe_id>/ratings', methods=['POST'])
55+
def rate_recipe(recipe_id):
56+
# Implementation for rating a recipe
57+
pass
58+
59+
@app.route('/recipes/<int:recipe_id>/comments', methods=['POST'])
60+
def add_comment(recipe_id):
61+
# Implementation for adding a comment to a recipe
62+
pass
63+
64+
@app.route('/recipes/<int:recipe_id>/comments', methods=['GET'])
65+
def get_comments(recipe_id):
66+
# Implementation for getting comments of a recipe
67+
pass
68+
69+
if __name__ == '__main__':
70+
app.run(debug=True, host='0.0.0.0')

csharp.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project/
2+
3+
api/
4+
app.py
5+
Dockerfile
6+
7+
db/
8+
init.sql
9+
Dockerfile
10+
11+
docker-compose.yml

db-docker-file.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mcr.microsoft.com/mssql/server:2019-latest
2+
3+
ENV ACCEPT_EULA=Y
4+
ENV SA_PASSWORD=YourStrong@Passw0rd
5+
6+
COPY init.sql /docker-entrypoint-initdb.d/

docker-file.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# api/Dockerfile
2+
3+
# Dockerfile for Flask API
4+
FROM python:3.9
5+
6+
WORKDIR /app
7+
8+
COPY requirements.txt requirements.txt
9+
RUN pip install -r requirements.txt
10+
11+
COPY . .
12+
13+
CMD ["python", "app.py"]

docker-yml.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
3+
services:
4+
api:
5+
build: ./api
6+
ports:
7+
- "5000:5000"
8+
depends_on:
9+
- db
10+
environment:
11+
- SQLALCHEMY_DATABASE_URI=mssql+pyodbc://sa:YourStrong@Passw0rd@db/RecipesDB?driver=ODBC+Driver+17+for+SQL+Server
12+
13+
db:
14+
build: ./db
15+
ports:
16+
- "1433:1433"

dockerfile.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# db/Dockerfile
2+
3+
# Dockerfile for MSSQL Database
4+
FROM mcr.microsoft.com/mssql/server:2019-latest
5+
6+
ENV ACCEPT_EULA=Y
7+
ENV SA_PASSWORD=YourStrong@Passw0rd
8+
9+
COPY init.sql /docker-entrypoint-initdb.d/

intl-sql.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- db/init.sql
2+
3+
-- SQL script to initialize MSSQL database
4+
CREATE DATABASE RecipesDB;
5+
6+
USE RecipesDB;
7+
8+
CREATE TABLE Recipe (
9+
id INT PRIMARY KEY IDENTITY(1,1),
10+
name NVARCHAR(100) NOT NULL,
11+
ingredients TEXT NOT NULL,
12+
steps TEXT NOT NULL,
13+
preparation_time INT NOT NULL
14+
);
15+
16+
CREATE TABLE Rating (
17+
id INT PRIMARY KEY IDENTITY(1,1),
18+
rating INT NOT NULL,
19+
recipe_id INT NOT NULL,
20+
FOREIGN KEY (recipe_id) REFERENCES Recipe(id)
21+
);
22+
23+
CREATE TABLE Comment (
24+
id INT PRIMARY KEY IDENTITY(1,1),
25+
text TEXT NOT NULL,
26+
recipe_id INT NOT NULL,
27+
FOREIGN KEY (recipe_id) REFERENCES Recipe(id)
28+
);

python.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# api/app.py
2+
3+
from flask import Flask, request, jsonify
4+
from flask_sqlalchemy import SQLAlchemy
5+
6+
app = Flask(__name__)
7+
app.config['SQLALCHEMY_DATABASE_URI'] = 'mssql+pyodbc://username:password@localhost/RecipesDB?driver=ODBC+Driver+17+for+SQL+Server'
8+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
9+
db = SQLAlchemy(app)
10+
11+
# Define database models
12+
class Recipe(db.Model):
13+
id = db.Column(db.Integer, primary_key=True)
14+
name = db.Column(db.String(100), nullable=False)
15+
ingredients = db.Column(db.Text, nullable=False)
16+
steps = db.Column(db.Text, nullable=False)
17+
preparation_time = db.Column(db.Integer, nullable=False)
18+
ratings = db.relationship('Rating', backref='recipe', lazy=True)
19+
comments = db.relationship('Comment', backref='recipe', lazy=True)
20+
21+
class Rating(db.Model):
22+
id = db.Column(db.Integer, primary_key=True)
23+
rating = db.Column(db.Integer, nullable=False)
24+
recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id'), nullable=False)
25+
26+
class Comment(db.Model):
27+
id = db.Column(db.Integer, primary_key=True)
28+
text = db.Column(db.Text, nullable=False)
29+
recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id'), nullable=False)
30+
31+
# API Endpoints
32+
33+
@app.route('/recipes', methods=['POST'])
34+
def add_recipe():
35+
"""Add a new recipe."""
36+
# Implementation for adding a recipe
37+
pass
38+
39+
@app.route('/recipes', methods=['GET'])
40+
def get_recipes():
41+
"""Retrieve a list of all recipes, sorted by most recent."""
42+
# Implementation for getting all recipes
43+
pass
44+
45+
@app.route('/recipes/<int:recipe_id>', methods=['GET'])
46+
def get_recipe(recipe_id):
47+
"""Retrieve details of a specific recipe by its ID."""
48+
# Implementation for getting a specific recipe
49+
pass
50+
51+
@app.route('/recipes/<int:recipe_id>', methods=['PUT'])
52+
def update_recipe(recipe_id):
53+
"""Update a specific recipe by its ID."""
54+
# Implementation for updating a specific recipe
55+
pass
56+
57+
@app.route('/recipes/<int:recipe_id>', methods=['DELETE'])
58+
def delete_recipe(recipe_id):
59+
"""Delete a specific recipe by its ID."""
60+
# Implementation for deleting a specific recipe
61+
pass
62+
63+
@app.route('/recipes/<int:recipe_id>/ratings', methods=['POST'])
64+
def rate_recipe(recipe_id):
65+
"""Rate a specific recipe."""
66+
# Implementation for rating a recipe
67+
pass
68+
69+
@app.route('/recipes/<int:recipe_id>/comments', methods=['POST'])
70+
def add_comment(recipe_id):
71+
"""Comment on a specific recipe."""
72+
# Implementation for adding a comment to a recipe
73+
pass
74+
75+
@app.route('/recipes/<int:recipe_id>/comments', methods=['GET'])
76+
def get_comments(recipe_id):
77+
"""Retrieve all comments for a specific recipe."""
78+
# Implementation for getting comments of a recipe
79+
pass
80+
81+
if __name__ == '__main__':
82+
app.run(debug=True, host='0.0.0.0')

sql.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE DATABASE RecipesDB;
2+
3+
USE RecipesDB;
4+
5+
CREATE TABLE Recipe (
6+
id INT PRIMARY KEY IDENTITY(1,1),
7+
name NVARCHAR(100) NOT NULL,
8+
ingredients TEXT NOT NULL,
9+
steps TEXT NOT NULL,
10+
preparation_time INT NOT NULL
11+
);
12+
13+
CREATE TABLE Rating (
14+
id INT PRIMARY KEY IDENTITY(1,1),
15+
rating INT NOT NULL,
16+
recipe_id INT NOT NULL,
17+
FOREIGN KEY (recipe_id) REFERENCES Recipe(id)
18+
);
19+
20+
CREATE TABLE Comment (
21+
id INT PRIMARY KEY IDENTITY(1,1),
22+
text TEXT NOT NULL,
23+
recipe_id INT NOT NULL,
24+
FOREIGN KEY (recipe_id) REFERENCES Recipe(id)
25+
);

yaml.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# docker-compose.yml
2+
3+
version: '3'
4+
5+
services:
6+
api:
7+
build: ./api
8+
ports:
9+
- "5000:5000"
10+
depends_on:
11+
- db
12+
environment:
13+
- SQLALCHEMY_DATABASE_URI=mssql+pyodbc://sa:YourStrong@Passw0rd@db/RecipesDB?driver=ODBC+Driver+17+for+SQL+Server
14+
15+
db:
16+
build: ./db
17+
ports:
18+
- "1433:1433"

0 commit comments

Comments
 (0)