diff --git a/01/01-todolist-doc.md b/01/01-todolist-doc.md index 8f242d3..466fe95 100644 --- a/01/01-todolist-doc.md +++ b/01/01-todolist-doc.md @@ -2,6 +2,42 @@ ## API Docs +**POST** `/tasks' +> to create a new task + +```json + { + "title": "this is something that i need to complete", + "due_date": 20220205 + "completed": false, + } +``` +**POST** `/tasks/{id}' +> to update duedate, description, completed status of any task + +```json + { + "title": "this is something that i need to complete", + "due_date": 20220205 + "completed": true, + } +``` + +**DELETE** '/tasks/{id}' +> deletes the task with the ID provided + + +**POST** `/tasks/{id}/notes' +> to create a new task + +```json + { + "title": "travel", + "body": "Need to leave by 5:00 PM" + } +``` + + **GET** `/tasks` 📄 > get a list of all tasks @@ -54,12 +90,166 @@ examples - {} ] ``` +## Entities + +![image](https://user-images.githubusercontent.com/1327050/180837289-72d49220-f104-45dd-80c6-e30378ab62a6.png) + + +# Blogging App + +## API Docs + +**POST** `/create_user' +> to create a new user + +```json + { + "username": "John", + "email": "john45@gmail.com", + "password": "password" + } +``` + +**POST** `/login' +> login + +```json + { + "username": "John", + "password": "password" + } +``` + +**POST** `/create_article/{id}` +> create an article + +```json + { + "user_id": "12345678", + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags'] + } +``` + + +**GET** `/articles` 📄 +> get a list of all the articles + +```json +[ + { + "user_id": "12345678", + "article_id": 1, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags'] + }, + { + "user_id": "123332378", + "article_id": 2, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags'] + } +] +``` + +**GET** `/{user_id}/{article_id}` +> get all the articles by a user + +```json + [ + { + "article_id": 1, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags'] + }, + { + "article_id": 25, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags'] + } +] +``` + +**GET** `/articles?tags=['sometag']` 📄 +> get a list of all the articles which has the mentioned tag + +```json +[ + { + "user_id": "12345678", + "article_id": 1, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags', 'sometag'] + }, + { + "user_id": "123332378", + "article_id": 2, + "title": "This is my title", + "subtitle": "subtitle" + "body": "contains body of article" + "tags": ['list', 'of', 'tags', 'sometag'] + } +] +``` + +**POST** `/update_article/{id}` +> update an article + +```json + { + "title": "This is the new title", + "subtitle": "new subtitle" + "body": "contains new body of article" + "tags": ['list', 'of', 'tags','adding a new tag'] + } +``` + +**DELETE** `/articles` +> DELETE all the articles by the logged in user + +**DELETE** `/articles/{id}` +> DELETE a specific article identified by the ID + + +**POST** `/article/{id}/like` +> like an article + +```json + { + "user_id": "32324242", + "article_id": "686868" + } +``` + +**POST** `/article/{id}/comment` +> like an article + +```json + { + "user_id": "32324242", + "comment_text": "I have commented on this article" + } +``` + +**DELETE** `/comments/{article_id}` +> DELETE the comments made by the logged in user + + ### References If 📄 is used, it means the endpoint supports `?size=10&page=2` type of pagination properties -## Entities - -![image](https://user-images.githubusercontent.com/1327050/180837289-72d49220-f104-45dd-80c6-e30378ab62a6.png) diff --git a/03/spring/basicapp/src/main/java/com/scaler/basicapp/TaskController.java b/03/spring/basicapp/src/main/java/com/scaler/basicapp/TaskController.java new file mode 100644 index 0000000..5b8919c --- /dev/null +++ b/03/spring/basicapp/src/main/java/com/scaler/basicapp/TaskController.java @@ -0,0 +1,46 @@ +package com.scaler.basicapp; +import com.scaler.basicapp.pojos.Notes; +import com.scaler.basicapp.pojos.Tasks; + +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; + + +@RestController +public class TaskController { + + private ArrayList tasks = new ArrayList<>(); + +// private ArrayList notes = new ArrayList<>(); + + @PostMapping("/tasks") + public Tasks createTask(@RequestBody Tasks task){ + tasks.add(task); + return task; + } + + + @GetMapping("/tasks") + public ArrayList getTasks(){ + System.out.println("The task list is :" +tasks); + return tasks; + } + + @GetMapping("/tasks/{id}") + public Tasks getTask(@PathVariable("id") int id){ + return tasks.get(id); + } + + @PostMapping("/tasks/{id}/notes") + public Tasks createNotes(@PathVariable("id") int id, @RequestBody Notes note){ + tasks.get(id).setNotes(note); + return tasks.get(id); + } + + @GetMapping("/tasks/{id}/notes") + public Notes getNotes(@PathVariable("id") int id){ + return tasks.get(id).getNotes(); + } + +} diff --git a/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Notes.java b/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Notes.java new file mode 100644 index 0000000..85f8446 --- /dev/null +++ b/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Notes.java @@ -0,0 +1,29 @@ +package com.scaler.basicapp.pojos; + +public class Notes { + + private String title; + private String body; + + public Notes(String title, String body){ + this.title = title; + this.body = body; + } + + public void setTitle(String title) { + this.title = title; + } + public String getTitle(){ + return title; + } + + public void setBody(String body){ + + this.body = body; + } + + public String getBody(){ + return body; + + } +} diff --git a/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Tasks.java b/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Tasks.java new file mode 100644 index 0000000..d8a3842 --- /dev/null +++ b/03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/Tasks.java @@ -0,0 +1,50 @@ +package com.scaler.basicapp.pojos; + +import java.util.Date; + +public class Tasks { + + private String title; + private String due_date; + private Boolean completed; + private Notes note; + + + public Tasks(String title, String due_date, Boolean completed){ + this.title = title; + this.due_date = due_date; + this.completed = completed; + this.note = null; + } + + public String getTitle(){ + return title; + } + + public void setTitle(String title){ + this.title = title; + } + + public void setDue_date(String due_date){ + this.due_date = due_date; + } + public String getDue_date(){ + return due_date; + } + + public void setCompleted(Boolean completed){ + this.completed = completed; + } + + public Boolean getCompleted(){ + return completed; + } + + public void setNotes(Notes note){ + this.note = note; + } + public Notes getNotes(){ + return note; + } + +}