WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9d0432d

Browse files
committed
2 parents ece179c + 360f68e commit 9d0432d

File tree

10 files changed

+581
-132
lines changed

10 files changed

+581
-132
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/[email protected]
16+
with:
17+
show-progress: false
18+
19+
- name: Install uv
20+
uses: astral-sh/[email protected]
21+
22+
- name: Run linter
23+
run: uvx ruff check

.github/workflows/pylint.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/pytest.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/[email protected]
19+
with:
20+
show-progress: false
21+
22+
- name: Install uv
23+
uses: astral-sh/[email protected]
24+
25+
- name: Run test(s)
26+
run: uv run pytest

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ Refer to the Fellowship LMS for information!
44

55
## Setup
66

7-
```
8-
python3 -m venv .venv
9-
source .venv/bin/activate
10-
pip install -r requirements.txt
7+
```bash
8+
uv venv
119
```
1210

1311
## Run
14-
```
12+
13+
```bash
1514
flask run
1615
```
1716

1817
### Run tests
19-
```
18+
19+
```bash
2020
pytest test_pytest.py
2121
```
2222

2323
### Run Linter
24-
```
25-
pylint *.py
24+
25+
```bash
26+
ruff check .
2627
```

app.py

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,98 @@ def update_experience(item_id):
144144

145145
return jsonify({"error": "Experience not found"}), 404
146146

147+
@app.route("/resume/experience/<int:item_id>", methods=["DELETE"])
148+
def delete_experience(item_id):
149+
"""
150+
Delete an experience by index.
151+
152+
Parameters
153+
----------
154+
item_id : int
155+
The index of the experience to delete.
156+
157+
Returns
158+
-------
159+
Response
160+
JSON message indicating success or error.
161+
Returns 404 if experience not found.
162+
Returns 400 if request is invalid.
163+
"""
164+
if item_id < 0 or item_id >= len(data["experience"]):
165+
return jsonify({"error": "Invalid request"}), 400
166+
data["experience"].pop(item_id)
167+
return jsonify({"message": "Experience has been deleted"}), 200
168+
169+
@app.route("/resume/experience/<int:item_id>", methods=["DELETE"])
170+
def delete_experience(item_id):
171+
"""
172+
Delete an experience by index.
173+
174+
Parameters
175+
----------
176+
item_id : int
177+
The index of the experience to delete.
178+
179+
Returns
180+
-------
181+
Response
182+
JSON message indicating success or error.
183+
Returns 404 if experience not found.
184+
Returns 400 if request is invalid.
185+
"""
186+
if item_id < 0 or item_id >= len(data["experience"]):
187+
return jsonify({"error": "Invalid request"}), 400
188+
data["experience"].pop(item_id)
189+
return jsonify({"message": "Experience has been deleted"}), 200
190+
147191

148192
@app.route("/resume/education", methods=["GET", "POST"])
149193
def education():
150194
"""
151-
Handles education requests
195+
Handles GET and POST requests for education entries.
196+
197+
GET: Returns all stored education entries.
198+
POST: Adds a new education entry to the system after validating required fields.
199+
200+
Returns
201+
-------
202+
Response
203+
JSON response containing:
204+
- All education entries with status 200 (on GET).
205+
- The index of the newly added entry with status 201 (on valid POST).
206+
- An error message with status 400 if POST data is missing or invalid.
207+
- An error message with status 405 if the HTTP method is not allowed.
152208
"""
209+
if request.method == 'POST':
210+
content = request.json
211+
212+
# Check if the content is empty:
213+
if not content:
214+
return jsonify({"error": "Bad request"}), 400
215+
216+
# Check if all required fields are present:
217+
required_fields = [
218+
'course', 'school', 'start_date', 'end_date', 'grade', 'logo'
219+
]
220+
if not all( key in content for key in required_fields):
221+
return jsonify({"error": "Missing required fields"}), 400
222+
223+
# Create a new Education object, add it to the data, and return the index:
224+
new_education = Education(
225+
content['course'],
226+
content['school'],
227+
content['start_date'],
228+
content['end_date'],
229+
content['grade'],
230+
content['logo']
231+
)
232+
data['education'].append(new_education)
233+
return jsonify({"id": len(data['education']) - 1}), 201
234+
153235
if request.method == "GET":
154236
return jsonify(data["education"]), 200
155237

156-
if request.method == "POST":
157-
try:
158-
education_data = request.get_json()
159-
is_valid, error_message = validate_data("education", education_data)
160-
if not is_valid:
161-
return jsonify({"error": error_message}), 400
162-
# pylint: disable=fixme
163-
# TODO: Create new Education object with education_data
164-
# TODO: Append new education to data['education']
165-
# TODO: Return jsonify({"id": len(data['education']) - 1}), 201
166-
return jsonify({}), 201
167-
except (TypeError, ValueError, KeyError):
168-
return jsonify({"error": "Invalid data format"}), 400
169-
170-
return jsonify({})
238+
return jsonify({"error": "Method not allowed"}), 405
171239

172240

173241
@app.route("/resume/education/<int:index>", methods=["GET", "DELETE"])
@@ -323,6 +391,27 @@ def profile():
323391
return jsonify({"error": f"Invalid data format: {str(e)}"}), 400
324392

325393
return jsonify({"error": "Method not allowed"}), 405
394+
@app.route("/resume/skill/<int:index>", methods=["GET"])
395+
def get_skill_by_index(index):
396+
"""
397+
Get a specific skill by index
398+
"""
399+
try:
400+
skill_index = data["skill"][index]
401+
return jsonify(skill_index), 200
402+
except IndexError:
403+
return jsonify({"error": "Skill not found"}), 404
404+
405+
406+
@app.route("/resume/skill/<int:index>", methods=["DELETE"])
407+
def delete_skill(index):
408+
"""
409+
Delete specific skill by index
410+
"""
411+
if 0 <= index < len(data["skill"]):
412+
data["skill"].pop(index)
413+
return jsonify({"message": "Successfully deleted skill"}), 200
414+
return jsonify({"error": "Skill not found"}), 404
326415

327416

328417
if __name__ == "__main__":

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "orientation-project"
3+
version = "0.1.0"
4+
description = ""
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = ["flask>=3.1.1"]
8+
9+
[dependency-groups]
10+
dev = ["pytest>=8.3.5", "ruff>=0.11.12"]

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)