Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. # Blog Socket
  2.  
  3. ## Intro
  4.  
  5. This is a try to define a Blog Socket in Syncano. Such socket gives a base functionalities that allows to
  6. host and manage a blog in Syncano Platform. I've decided to make some simplifications - only two user roles:
  7. `user` and `admin`; In popular blogging platforms there are more roles usually (editor, author, contributor).
  8.  
  9. ## User stories
  10.  
  11. * As an user I want to read blog post.
  12. * As an user I want to see main page with post wall.
  13. * As an user I want to make a comment under the post.
  14. * As an user I want to see comments list under the post made by other users.
  15. * As an user I want to login/register to write a comment.
  16. * As an user I want to give a like for post.
  17. * As an admin I want to be able to add blog post.
  18. * As an admin I want to be able to publish post (set status to publish).
  19. * As an admin I want to be able to schedule blog post (set as publish in a given time).
  20. * As an admin I want to be able to edit blog post.
  21. * As an admin I want to be able to remove blog post.
  22. * As an admin I want to be able to unpublish blog post.
  23. * As an admin I want to be able to manage my media library: add/edit/remove.
  24. * As a developer I want to have possibility to edit blog template.
  25.  
  26. ## Classes
  27.  
  28. class post
  29. id an ID of the post (not editable)
  30. created_at the creation date (not editable)
  31. updated_at the last update date (not editable)
  32. created_by by who this post was created (multiple admins) (not editable)
  33. updated_by by who this post was updated (multiple admins) (not editable)
  34. title the title of the post
  35. text the body of the post
  36. image the main image of the post (relation to `media` class)
  37. status the main image of the post (relation to `media` class)
  38.  
  39. class media
  40. id the ID of the image (not editable)
  41. title The media title
  42. media the image URL
  43. size image size (eg.: filtering by size when frontend expect a thumbnail)
  44. type one of the: image|video|audio
  45.  
  46. class comment
  47. id the ID of the comment (not editable)
  48. user_id the user ID which made a comment
  49. title the comment title
  50. text the comment body
  51. parent_id <optional> a reference to the `comment` class - tells if comment is a response to another one;
  52.  
  53. class like
  54. id the ID of the like (not editable)
  55. user_id user ID which makes the like
  56. post_id the ID of the liked post
  57.  
  58. class user_profile (extension)
  59. avatar the avatar of the user
  60.  
  61. ## Groups
  62.  
  63. ### Admin
  64.  
  65. This is a blog owner. He creates the content and manage it.
  66.  
  67. ### User
  68.  
  69. This is a blog consumer. He reads the content provided by Admin.
  70.  
  71. ## Endpoints
  72.  
  73. The request/response example in the yml definition.
  74.  
  75. * GET /blog/posts/ - list post
  76. * GET /blog/posts/<id>/ - single post
  77. * POST /blog/posts/ - add post
  78. * PUT/PATCH /blog/post/ - edit post
  79. * DELETE /blog/posts/<id>/ - remove post
  80. * POST /blog/posts/<id>/publish/ - publish post
  81. * POST /blog/posts/<id>/schedule/ - schedule post
  82. * POST /blog/posts/<id>/unpublish/ - unpublish post
  83. * POST /blog/posts/<id>/like/ - add like to post
  84. * GET /blog/posts/<id>/like/ - get post likes
  85. * POST /blog/posts/<id>/comments/ - add a comment
  86. * GET /blog/posts/<id>/comments/ - list comments
  87. * POST /blog/login/ - login user/admin
  88. * POST /blog/register/ - register user
  89. * POST /blog/media/ - add media
  90. * PUT/PATCH /blog/media/<id>/ - update media
  91. * DELETE /blog/media/<id>/ - removes media
  92.  
  93. ## Hosting Socket
  94.  
  95. In this Socket the very desired functionality is to define the Hosting Socket as a dependency to the original Socket.
  96. This will allow to easily modify the hosted files and also gives Syncano user a whole `product` - not only the API.
  97.  
  98. The Hosting Socket in yml can look like this:
  99.  
  100. hosting: sites
  101.  
  102. Which means that the Socket installation process will also automatically move all the files from sites to the Hosting Socket
  103. (publish the page under the `sites` directory).
  104.  
  105. ## YML definition
  106.  
  107. name: blog
  108. description: Blog application
  109.  
  110. endpoints:
  111. posts:
  112. object: post
  113. parameters:
  114. title: string
  115. text: text
  116. image: integer
  117.  
  118. acl:
  119. groups:
  120. _admin: *
  121. _user:
  122. - GET
  123. media:
  124. object: media
  125. parameters:
  126. title: string
  127. media: file
  128. size: string
  129. type: integer
  130.  
  131. acl:
  132. groups:
  133. _admin: *
  134. _user:
  135. - GET
  136.  
  137. comments:
  138. object: comment
  139. parent: post
  140. parameters:
  141. title: string
  142. media: file
  143. size: string
  144. type: integer
  145.  
  146. acl:
  147. groups:
  148. _admin: *
  149. _user: *
  150.  
  151. like:
  152. object: like
  153. parent: post
  154. parameters:
  155. user_id: integer
  156. post_id: integer
  157.  
  158. acl:
  159. groups:
  160. _admin: *
  161. _user: *
  162.  
  163. login:
  164. POST:
  165. script: login
  166. parameters:
  167. username: string
  168. password: string
  169. avatar: file <optional>
  170.  
  171. register:
  172. POST:
  173. script: register
  174. parameters:
  175. username: string
  176. password: string
  177.  
  178. schedule:
  179. action: true
  180. parent: post
  181. script: schedule
  182.  
  183. publish:
  184. action: true
  185. parent: post
  186. script: publish
  187.  
  188. unpublish:
  189. action: true
  190. parent: post
  191. script: unpublish
  192.  
  193. dependencies:
  194. objects:
  195. post:
  196. description: Post object;
  197. media:
  198. description: Image object;
  199. comment:
  200. description: Comment object;
  201. like:
  202. description: Like object;
  203.  
  204. hostings:
  205. hosting: site
  206. description: a Hosting files for blog platform
  207.  
  208. scripts:
  209. login:
  210. description: Exchange user/password for token;
  211. register:
  212. description: Register new user;
  213. publish:
  214. description: Publish post;
  215. unpublish:
  216. description: Unpublish the post;
  217. schedule:
  218. description: Schedule the post;
  219.  
  220. classes:
  221. post:
  222. schema:
  223. - name: id
  224. type: integer
  225. - name: created_at
  226. type: datetime
  227. - name: updated_at
  228. type: datetime
  229. - name: created_by
  230. type: integer
  231. - name: updated_by
  232. type: integer
  233. - name: title
  234. type: string
  235. - name: text
  236. type: text
  237. - name: image
  238. type: integer
  239. - name: status
  240. type: integer
  241.  
  242. media:
  243. schema:
  244. - name: id
  245. type: integer
  246. - name: title
  247. type: string
  248. - name: media
  249. type: file
  250. - name: size
  251. type: string
  252. - name: type
  253. type: integer
  254.  
  255. comment:
  256. schema:
  257. - name: id
  258. type: integer
  259. - name: user_id
  260. type: integer
  261. - name: title
  262. type: string
  263. - name: text
  264. type: string
  265. - name: parent_id
  266. type: string
  267.  
  268. like:
  269. schema:
  270. - name: user_id
  271. type: integer
  272. - name: post_id
  273. type: integer
  274.  
  275. user_profile:
  276. schema:
  277. - name: avatar
  278. type: file
  279.  
  280. groups:
  281. - name: admin
  282. - name: user
  283.  
  284.  
  285. ## Summary and comments
  286.  
  287. Basically I've drove off a little :)
  288.  
  289. I know that this socket can be done in current way of how Syncano Custom Sockets works. But writing a scripts for simple CRUD
  290. operations seems like a misunderstanding. Also - the usa of the `administrator` API for that - is not so nice to the end user.
  291. So I've came up with an idea of new dependecy: objects, which maybe sometime will be existing :) This dependecy provides a simple
  292. CRUD API for given object, for example:
  293.  
  294. class Message
  295. id: integer
  296. body: text
  297. send_date: datetime
  298.  
  299. and dependency:
  300.  
  301. dependecies:
  302. objects:
  303. message:
  304. description: Message CRUD
  305.  
  306. Will give to the user following endpoints:
  307.  
  308. * GET /messages/
  309. * POST /messages/
  310. * GET /messages/<id>/
  311. * PUT /messages/<id>/
  312. * PATCH /messages/<id>/
  313. * DELETE /messages/<id>/
  314.  
  315. Which is basically a CRUD operations for model Message;
  316.  
  317. Additionally I came up with an idea of some `action` script for CRUD operations. In the above example such action is publish:
  318.  
  319. * /blog/posts/<id>/publish/
  320.  
  321. Which simply - change the status of the blog post. Such actions is similar to the drf decorator: @detail_route
  322. And the logic can be processed in custom script;
  323.  
  324. What more?
  325. Well - for such Sockets it would be nice to have Hosting Socket dependency.
  326. The Socket installation process should also publish hosting files.
  327. Additionally it can ask for such things as custom domain and so on.
  328.  
  329. This example is only the tip of the iceberg - I've intentionally omitted such subjects as: statistics and user analytics.
  330. But both of them are very desirable in blog.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement