|
1 | 1 | # MS-Forum |
2 | | -Micro Service of Forum for networking section |
| 2 | +This backend API is used as an interface for Forum interaction with backend. |
| 3 | + |
| 4 | +## Steps to run & deploy |
| 5 | +### Load and Connect Database |
| 6 | + |
| 7 | +### Running in dev |
| 8 | +For running your server in dev environment please use the following command: |
| 9 | + |
| 10 | + npm run dev |
| 11 | + If everything is correct you will receive following message in console: |
| 12 | + |
| 13 | + |
| 14 | + Server listening on port 3000 |
| 15 | +port 3000 is the default port and it is not yet configurable. |
| 16 | + |
| 17 | +### Running in Production |
| 18 | +For running your server in dev environment please use the following command: |
| 19 | + |
| 20 | + npm run start |
| 21 | + If everything is correct you will receive following message in console: |
| 22 | + |
| 23 | + |
| 24 | + Server listening on port 3000 |
| 25 | +port 3000 is the default port and it is not yet configurable. |
| 26 | + |
| 27 | +## Business Logic |
| 28 | + |
| 29 | + |
| 30 | +## Endpoints |
| 31 | +### Get Discussions |
| 32 | +You can get a list of all products using endpoint `/api/discussions`by a GET HTTP Request, this list is used typically by the FrontEnd for picking values. |
| 33 | + |
| 34 | +### Get Discussion by Id |
| 35 | +You can get a list of all invoices using endpoint `/api/discussions/{id}` by a GET HTTP Request, this list can be used to access to a particular discussion id, it will always retrieve last version created in database. Below is a JSON example of this request answer: |
| 36 | + |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "id": 1, |
| 41 | + "title": "Example Title", |
| 42 | + "content": "Example Content", |
| 43 | + "category": 1, |
| 44 | + "created_at": "2012-04-23T18:25:43.511Z", |
| 45 | + "created_by": 1, |
| 46 | + "modified_at": null, |
| 47 | + "modified_by": null, |
| 48 | + "status": 1, |
| 49 | + "discussion_version_no": 1 |
| 50 | +} |
| 51 | +``` |
| 52 | +### Create a new discussion |
| 53 | +You can create a new discussion using endpoint `/api/discussions/create` by a POST HTTP request with following body: |
| 54 | +```json |
| 55 | +{ |
| 56 | + "title": "Example Title", |
| 57 | + "content": "Example Content", |
| 58 | + "category": 1, |
| 59 | +} |
| 60 | +``` |
| 61 | +This will return the created discussion with void comments as: |
| 62 | +```json |
| 63 | +{ |
| 64 | + "id": 1, |
| 65 | + "title": "Example Title", |
| 66 | + "content": "Example Content", |
| 67 | + "category": 1, |
| 68 | + "created_at": "2012-04-23T18:25:43.511Z", |
| 69 | + "created_by": 1, |
| 70 | + "modified_at": null, |
| 71 | + "modified_by": null, |
| 72 | + "status": 1, |
| 73 | + "discussion_version_no": 1 |
| 74 | +} |
| 75 | +``` |
| 76 | +### Get all discussion likes |
| 77 | +You can get a list of all products using endpoint `/api/likes/discussions` by a GET HTTP Request, this list is used typically by the FrontEnd for picking values. It retrieves a list of JSON objects with likes details: |
| 78 | + |
| 79 | +```json |
| 80 | +[{ |
| 81 | + "id": 1, |
| 82 | + "discussionId": 1, |
| 83 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 84 | + "userId": 1, |
| 85 | + "isActive": true |
| 86 | +} |
| 87 | +, |
| 88 | +{ |
| 89 | + "id": 2, |
| 90 | + "discussionId": 1, |
| 91 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 92 | + "userId": 2, |
| 93 | + "isActive": true |
| 94 | +} |
| 95 | +, |
| 96 | +{ |
| 97 | + "id": 3, |
| 98 | + "discussionId": 1, |
| 99 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 100 | + "userID": 3, |
| 101 | + "isActive": true |
| 102 | +}, |
| 103 | +{ |
| 104 | + "id": 4, |
| 105 | + "discussionId": 2, |
| 106 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 107 | + "userId": 2, |
| 108 | + "isActive": true |
| 109 | +}] |
| 110 | +``` |
| 111 | + |
| 112 | +### Give like/unlike to a discussion |
| 113 | +You can give like to an existing discussion using endpoint `/api/likes/discussions` by a POST HTTP request with following body: |
| 114 | +```json |
| 115 | +{ |
| 116 | + "discussionId": 1, |
| 117 | + "user_id": 2 |
| 118 | +} |
| 119 | +``` |
| 120 | +This will return the created like as: |
| 121 | +```json |
| 122 | +{ |
| 123 | + "id": 1, |
| 124 | + "discussionId": 1, |
| 125 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 126 | + "userId": 2, |
| 127 | + "isActive": true, |
| 128 | + "currentdiscussionLikes": 2 |
| 129 | +} |
| 130 | +``` |
| 131 | +if the like is already created, isActive will be false. |
| 132 | + |
| 133 | +### Get likes for a discussion and user |
| 134 | +You can give like to an existing discussion using endpoint `/api/likes/discussions` by a GET HTTP request. This can be filtered using params : |
| 135 | +`discussionId` -> optional param |
| 136 | +`userId` -> optional param |
| 137 | +`groupBy` -> optional param |
| 138 | + |
| 139 | +if `userId` is present (`/api/likes/discussions?userId=2`) then this will return the like as: |
| 140 | + |
| 141 | +```json |
| 142 | +[{ |
| 143 | + "id": 1, |
| 144 | + "discussionId": 1, |
| 145 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 146 | + "userId": 2, |
| 147 | + "isActive": true, |
| 148 | + "currentdiscussionLikes": 3 |
| 149 | +}, |
| 150 | +{ |
| 151 | + "id": 4, |
| 152 | + "discussionId": 2, |
| 153 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 154 | + "userId": 2, |
| 155 | + "isActive": true, |
| 156 | + "currentdiscussionLikes": 1 |
| 157 | +}] |
| 158 | +``` |
| 159 | + |
| 160 | +if `groupBy` is present and it corresponds to a JSON object property (`/api/likes/discussions?userId=2&groupBy='discussionId'`) then endpoint will return the like as: |
| 161 | + |
| 162 | +```json |
| 163 | +[{ |
| 164 | + |
| 165 | + "discussionId": 2, |
| 166 | + "count": 1 |
| 167 | +}, |
| 168 | +{ |
| 169 | + |
| 170 | + |
| 171 | + "discussionId": 1, |
| 172 | + "count": 3 |
| 173 | + |
| 174 | +} |
| 175 | + |
| 176 | + |
| 177 | +``` |
| 178 | +if `discussionId` is present and it corresponds to a JSON object property (`/api/likes/discussions?discussionId=1`) then endpoint will return the like as: |
| 179 | + |
| 180 | +```json |
| 181 | +[{ |
| 182 | + "id": 1, |
| 183 | + "discussionId": 1, |
| 184 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 185 | + "userId": 1, |
| 186 | + "isActive": true, |
| 187 | + "currentdiscussionLikes": 3 |
| 188 | +} |
| 189 | +, |
| 190 | +{ |
| 191 | + "id": 2, |
| 192 | + "discussionId": 1, |
| 193 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 194 | + "userId": 2, |
| 195 | + "isActive": true, |
| 196 | + "currentdiscussionLikes": 3 |
| 197 | +} |
| 198 | +, |
| 199 | +{ |
| 200 | + "id": 3, |
| 201 | + "discussionId": 1, |
| 202 | + "likedAt": "2012-04-23T18:25:43.511Z", |
| 203 | + "userID": 3, |
| 204 | + "isActive": true, |
| 205 | + "currentdiscussionLikes": 3 |
| 206 | +}] |
| 207 | + |
| 208 | +``` |
| 209 | + |
| 210 | +Also you can use `groupBy` to obtain the count of every discussion (`/api/likes/discussions?groupBy=discussionId`) the endpoint will return: |
| 211 | + |
| 212 | +```json |
| 213 | +[{ |
| 214 | + |
| 215 | + "discussionId": "1", |
| 216 | + "count": 3 |
| 217 | +} |
| 218 | +, |
| 219 | +{ |
| 220 | + |
| 221 | + "discussionId": "2", |
| 222 | + "count":1 |
| 223 | +} |
| 224 | +] |
| 225 | + |
| 226 | +``` |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | +if nothing is found, then you will receive a 404 HTTP status. |
| 232 | +## To Do |
| 233 | + |
| 234 | + |
| 235 | + |
0 commit comments