项目作者: straw-hat-labs

项目描述 :
Review System
高级语言: Elixir
项目地址: git://github.com/straw-hat-labs/straw_hat_review.git
创建时间: 2018-02-09T00:52:13Z
项目社区:https://github.com/straw-hat-labs/straw_hat_review

开源协议:MIT License

下载


StrawHat.Review

Health Checking
Code Coverage
Docs Health

StrawHat.Review will help you to add reviews to your systems. We took
inspiration from Amazon, Lyf, Google, Uber and Fiverr review systems.

Installation

If available in Hex, the package can be installed
by adding straw_hat_review to your list of dependencies in mix.exs:

  1. def deps do
  2. [
  3. {:straw_hat_review, "~> 0.1"}
  4. ]
  5. end

Usage

We will cover the basic interactions of the systems but please check out
each Interactor module which are the ones that expose the API that developers
should be using.

Aspects

Let’s create some aspects based on Fiverr Reviews.

  1. # id: 1
  2. StrawHat.Review.Aspects.create_review(%{
  3. name: "seller_communication"
  4. })
  5. # id: 2
  6. StrawHat.Review.Aspects.create_review(%{
  7. name: "service_as_described"
  8. })
  9. # id: 3
  10. StrawHat.Review.Aspects.create_review(%{
  11. name: "would_recommend"
  12. })

Reviews

Now let’s give some review to a user.

Normally the reviewee and reviewer are just an string that your systems will
know how to do the aggregation with that data. For example, your system that
uses StrawHat.Review knows that "user:" <> user_id is the way to read back
the user id of the reviewee and reviewer.

  1. # id: 1
  2. StrawHat.Review.Review.create_review(%{
  3. reviewee_id: "user:1",
  4. reviewer_id: "user:2",
  5. comment: "Amazing experience, I really recommended it",
  6. aspects: [
  7. %{
  8. aspect_id: 1, # seller_communication
  9. score: 5
  10. },
  11. %{
  12. aspect_id: 2, # service_as_described
  13. score: 5
  14. },
  15. %{
  16. aspect_id: 3, # would_recommend
  17. score: 5
  18. }
  19. ]
  20. medias: [
  21. %Plug.Upload{
  22. content_type: "image/png",
  23. filename: "some_random_file_name.png",
  24. path: "~tmp/some_random_name.png"
  25. }
  26. ]
  27. })

Comments

Now we could add some comments to the review.

  1. # id: 1
  2. StrawHat.Review.Comments.create_comment(%{
  3. comment: "Really helpful review, thank you very much",
  4. owner_id: "user:3",
  5. review_id: 1
  6. })

Reactions

We could create some reactions for the systems so it could be use later
on reviews and comments.

  1. # id: 1
  2. StrawHat.Review.Reactions.create_reaction(%{
  3. name: "like"
  4. })
  5. # id: 2
  6. StrawHat.Review.Reactions.create_reaction(%{
  7. name: "dislike"
  8. })

Now we could react to the reviews and comments

  1. StrawHat.Review.ReviewReactions.create_review_reaction(%{
  2. review_id: 1,
  3. reaction_id: 1,
  4. user_id: "user:1"
  5. })
  6. StrawHat.Review.CommentReactions.create_comment_reaction(%{
  7. review_id: 1,
  8. reaction_id: 1,
  9. user_id: "user:1"
  10. })

That is a basic usage of the package. Check the interactor modules for more
available APIs.