Giter Site home page Giter Site logo

comments_service's Introduction

Comments service

Based on: https://www.youtube.com/watch?v=CnailTcJV_U

Requirements

Create a comment

POST /api/comments

Need to include:

  • Author
  • Text
  • PostId

Can also include:

  • Reply to id (for nested comments)

After creation, it's also filled with:

  • id
  • createdAt
  • modifiedAt
  • hash
  • published (set to true if there are no bad words, otherwise to false)
  • source:
    • ip
    • user agent

The bad words are checked on some api called "content moderator" https://contentmoderator.cognitive.microsoft.com/

Get comment

Return a comment with all its child comments, available as array under replies.

Change comment text

PATCH /api/comments/:id

Can only change text

Delete a comment

DELETE /api/comments/:id

Returns:

  • Deleted count
  • Whether it was soft delete

If comment has children, the comment is "soft deleted", meaning:

  • author is set to deleted
  • text is set to placeholder

If all comments in a chain are soft deleted, they are then actually deleted.

Thoughts

  • Async/await is still annoying to use with a debugger. Keep with Promises for now.

  • 2 layer architecture (imperative shell, service layer) feels right. 3rd layer could be extracted from private mongo-based methods into some kind of DAL layer. But it feels a lot of these methods would really just be private methods of CommentManager (needlessly) living in a different service, so I didn't go for that. An ORM/OOM on its own could have been the third layer.

  • Using pure classes for services is annoying. Writing this.app.x gets old quick. Closure factory is still a better choice for long lived services.

  • Models with base class still the best choice. No idea how to prevent base class from balooning in complexity.

  • Express with Promise wrapper good.

  • Debug logger better than winston, but I miss the ability to log different events at different levels. Maybe those could too be tags? Had some problems configuring it properly, I wish these libraries didn't insist on screwing with global env-s.

  • Dotenv based config serviceable in a small app, but I'd stil prefer yaml that maps precisely to the settings structure.

  • Extracted all settings into one class, instead of each service declaring its own. Works fine for this small app, might become unwieldy in a real monolith.

  • Does this arch make sense in a microservice? Seems like most code ended up in one file (comment_manager.js). Will it always be that? Should I break it apart? How?

  • Api-tester.http is a JetBrains testing system, replacement for Postman and Insomnia. A bit better once you get used to it, but I found it annoying having to click between my debug and run window. I wish they'd have made results of requests appear in a side-window to the http file editor.

  • Controllers as function work fine. No need for full service class ceremony.

  • Missing features: validation, a bunch of consistency checks.

  • Mongo's ObjectID is the most annoying part of dealing with mongo. I keep having to think which parts of my models need to be casted into and out of ID-s. I wish they could have just used a string (I guess that's why you use ODM?).

  • Mongo is generally annoying.

comments_service's People

Contributors

panta82 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.