Fireship · @fireship

Star Review System from Scratch with Firestore + Angular

Uploaded October 19, 2017 · Length 10:11

Star Review System from Scratch with Firestore + Angular

Summary

build a five-star review system from scratch using firestore and angular

  • firestore
  • angular
  • five-star review system
  • many-to-many relationships
  • firebase

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    modeling data relationships is one of

  2. 0:02

    the single most important concerns for

  3. 0:03

    an app developer in this episode I'm

  4. 0:05

    going to show you how to build a

  5. 0:06

    five-star review system from scratch

  6. 0:08

    using the new fire stored document

  7. 0:10

    database and angular my goal is to give

  8. 0:13

    you a good foundation for building

  9. 0:14

    many-to-many relationships in a no

  10. 0:16

    sequel back-end environment the reason I

  11. 0:18

    chose a five-star review system for this

  12. 0:20

    episode is because the underlying

  13. 0:22

    concepts can be applied to many

  14. 0:23

    different features such as Facebook

  15. 0:25

    Likes reddit votes Instagram hearts and

  16. 0:27

    many other concepts similar to those one

  17. 0:30

    of the most important best practices

  18. 0:31

    with firestore is to create big

  19. 0:33

    collections and small documents to build

  20. 0:36

    this feature we're going to have three

  21. 0:38

    collections in the root of the database

  22. 0:39

    so this first collection is a user's

  23. 0:42

    collection and the only attribute on the

  24. 0:44

    document itself is the display name I

  25. 0:47

    won't have time to cover user

  26. 0:48

    authentication in this video but if

  27. 0:49

    you're new to my channel make sure to

  28. 0:50

    check out my previous firestore Roth

  29. 0:53

    video to get up to speed on that so back

  30. 0:56

    to the database our primary goal here is

  31. 0:58

    to create a relationship between users

  32. 1:00

    and movies through the Stars collection

  33. 1:02

    so if you look at our movies document it

  34. 1:05

    just has the image title and plot of the

  35. 1:07

    movie if we jump over to the Stars

  36. 1:09

    collection you'll see that's where all

  37. 1:10

    the relational data is cat

  38. 1:12

    each star document will save the movie

  39. 1:14

    ID as well as the user ID and the value

  40. 1:17

    of the rating and then because a user

  41. 1:19

    can only post one review for each movie

  42. 1:21

    I've also created a custom ID here to

  43. 1:23

    ensure that there's no accidental data

  44. 1:25

    duplication so we create the document ID

  45. 1:27

    by concatenating that movie ID to the

  46. 1:30

    user ID separated by an underscore and

  47. 1:32

    you'll see this more once we get into

  48. 1:34

    angular if you come from a sequel

  49. 1:36

    background this is very similar to a

  50. 1:37

    many-to-many through relationship so now

  51. 1:40

    I'm jumping into my angular project I'm

  52. 1:42

    assuming you have angularfire to version

  53. 1:44

    5 installed what I'm going to be doing

  54. 1:47

    today is to creating a very generic

  55. 1:48

    middleman service that can connect

  56. 1:50

    relationships between any two documents

  57. 1:52

    to focus on the relationship aspect of

  58. 1:55

    this feature I'm going to just hard code

  59. 1:56

    a user document and movie document

  60. 1:59

    directly in the app component so I'll