@@ -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" ])
149193def 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
328417if __name__ == "__main__" :
0 commit comments