ngankhanh98 / coursebox-angular

Coursebox webapp using angular
https://ngankhanh98.github.io/coursebox-angular/
MIT License
0 stars 2 forks source link

Get my-courses suggestions?? #3

Closed ngankhanh98 closed 3 years ago

ngankhanh98 commented 3 years ago

Issue type

I'm submitting a ... (check one with "x")

Issue description

Current situation: Currently, we have 2 big modules: pages and auth, each has their own Akita's state:

// auth.ts (state for AuthModule)
export interface Auth {
  username: string;
  fullname: string;
  userId: string;

  token: string;
}

// course.ts (state for PagesModule)
import { Auth } from 'app/auth/state/auth';

export interface Course {
  courseId: string;
  title: string;
  teacher: Auth;
}

Expected behavior: In route: /attend/my-courses, I expect to see courses created by me. To doing so, auth.userId or auth.username should be retrieve; and course should returns to all course, then querying them both

Solution suggests:

  1. Rewrite an api (GET - /course/{userId}), and maybe install another store state
  2. Find the way to query the expected result from 2 store state using Akita query. In doing this, I found myself being confused about: where to install code properly, in my-courses.component.ts or in state/course.service.ts 2.1. And do I have the kind of query allowing to use filter based on 2 Observerable (one with auth state, and the other with course state)?

__ Currently, I'm doging my 2nd approach. The above drawbacks are what I faced or am facing with. Besides, I would like to know if these 2 solutions are anti-pattern (because I have no idea). @dohoangdinhtien

dohoangdinhtien commented 3 years ago

Hi Khánh,

  1. Nestjs side, you need to make new API to get my course (based on JWT token, we can get userId. Then we will make filter the course with it).
  2. Angular side, add new myCourse interface extend from Course interface.
ngankhanh98 commented 3 years ago

Yes, and with the first solution, I believe I need to install a new state or else, modify course state to store my-course from called API. Then, when I create my course, 2 sources of state need to be updated: all-course and my-course. Part of me thinks this way is antithesis to Single source of truth priciple.

I think I will follow your 2nd direction, to efficiently use the power of Akita query. Thank you sir!!!