Skip to content

Commit 04c6e7e

Browse files
Adding: README file
1 parent 48f8961 commit 04c6e7e

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Spring REST API Documentation - Topics and Courses
2+
3+
This API provides functionalities for managing topics and their associated courses.
4+
5+
**Communication:**
6+
7+
- **Content-Type:** Application/JSON is used for both request and response bodies.
8+
- **Spring Annotations:** The API leverages Spring annotations for controller definitions and dependency injection.
9+
- **Error Responses:** Responses include an error message and status code in case of exceptions.
10+
11+
**1. Topics API**
12+
13+
**Endpoints:**
14+
15+
* **GET /get/topics**
16+
* Description: Retrieves a list of all topics.
17+
* Response: JSON array of `Topic` objects.
18+
* **GET /get/topic/{id}**
19+
* Description: Gets a specific topic by its ID.
20+
* Path Parameter: `{id}` - The numeric ID of the topic to retrieve.
21+
* Response: JSON object representing the `Topic` or a Not Found status code if not found.
22+
* **POST /post/topic**
23+
* Description: Creates a new topic.
24+
* Request Body: JSON object representing the new `Topic`.
25+
* Response: JSON array containing the list of topics after creation (including the newly created one).
26+
* **PUT /update/topic/{id}**
27+
* Description: Updates an existing topic.
28+
* Path Parameter: `{id}` - The numeric ID of the topic to update.
29+
* Request Body: JSON object representing the updated `Topic`.
30+
* Response: JSON object representing the updated `Topic` or a Not Found status code if not found.
31+
* **DELETE /delete/topic/{id}**
32+
* Description: Deletes a topic by its ID.
33+
* Path Parameter: `{id}` - The numeric ID of the topic to delete.
34+
* Response: No response body, but deletes the specified topic (returns void).
35+
36+
**2. Courses API**
37+
38+
**Endpoints (all require a topic ID in the path):**
39+
40+
* **GET /get/topics/{id}/courses**
41+
* Description: Retrieves all courses associated with a specific topic.
42+
* Path Parameter: `{id}` - The numeric ID of the topic to get courses for.
43+
* Response: JSON array of `Course` objects.
44+
* **GET /get/topic/{topicId}/courses/{id}**
45+
* Description: Gets a specific course by its ID within a topic.
46+
* Path Parameters:
47+
* `{topicId}` - The numeric ID of the topic containing the course.
48+
* `{id}` - The numeric ID of the course to retrieve.
49+
* Response: JSON object representing the `Course` or a Not Found status code if not found.
50+
* **POST /post/topic/{topicId}/courses**
51+
* Description: Creates a new course associated with a specific topic.
52+
* Path Parameter: `{topicId}` - The numeric ID of the topic for the new course.
53+
* Request Body: JSON object representing the new `Course`. The course object should include the topic ID in its request body.
54+
* Response: No response body, but creates the new course associated with the specified topic.
55+
* **PUT /update/topic/{topicId}/courses/{id}**
56+
* Description: Updates an existing course within a topic.
57+
* Path Parameters:
58+
* `{topicId}` - The numeric ID of the topic containing the course.
59+
* `{id}` - The numeric ID of the course to update.
60+
* Request Body: JSON object representing the updated `Course`. The course object should include the topic ID in its request body.
61+
* Response: JSON object representing the updated `Course`.
62+
* **DELETE /delete/topic/{topicId}/courses/{id}**
63+
* Description: Deletes a course by its ID within a topic.
64+
* Path Parameters:
65+
* `{topicId}` - The numeric ID of the topic containing the course.
66+
* `{id}` - The numeric ID of the course to delete.
67+
* Response: No response body, but deletes the specified course (returns void).
68+
69+
**Note:**
70+
71+
- The `Course` API endpoints require the corresponding topic to exist before creating or updating courses.
72+
- Error responses might include details about exceptions encountered during processing.
73+

src/main/java/learnAPI/restAPI/RestApiJpaApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public static void main(String[] args) {
1010
SpringApplication.run(RestApiJpaApplication.class, args);
1111
}
1212

13-
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// BadRequestException.java
2+
package learnAPI.restAPI.exceptions;
3+
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.web.bind.annotation.ResponseStatus;
6+
7+
@ResponseStatus(HttpStatus.BAD_REQUEST)
8+
public class BadRequestException extends RuntimeException {
9+
public BadRequestException(String message) {
10+
super(message);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package learnAPI.restAPI.exceptions;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(HttpStatus.NOT_FOUND)
7+
public class NotFoundException extends RuntimeException {
8+
public NotFoundException(String message) {
9+
super(message);
10+
}
11+
}

src/main/java/learnAPI/restAPI/topic/Topic.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ public String getDescription() {
3737
public void setDescription(String description) {
3838
this.description = description;
3939
}
40-
}
40+
}

src/main/java/learnAPI/restAPI/topic/TopicController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public void del(@PathVariable Integer id) {
5353
topicService.deleteTopic(id);
5454
}
5555

56-
}
56+
}

0 commit comments

Comments
 (0)