caxco93
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
😉
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
for different fields or w/e
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
small technical debt if you ever end up needing to add a new endpoint
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
yeah if you are certain you will just use it for that page then just go ahead
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
but yeah you always have to question yourself. do you want to ship or do you want to make lots of abstractions that you will only end up using once
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
first of all, if you want good practices then your endpoints should be in plural for each resource.
yeah you have several options here. what you say is indeed a way to go. if you are sure indeed you will only end up using that endpoint there you can leave it like that.
however, in theory, you have 2 other options.
1. add the ability to specify which fields you want for each resource. that way you can do something like
/resources?fields=id,name,code,owner_name
. this is basically one of the things GraphQL aims to solve (not recommending you to use it. i'm just stating it)
2. create 2 different endpoints. 1 for your homepage where you get just a bunch of the fields you need e.g /homepageResources
and then another endpoint that returns all the fields as usual eg /resources
however you can see how the option 1 seems more robust. the solution you propose and the solution 2 I propose are probably only good if you want to ship fast. in theory the option 1 here is the "acceptable" response18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/20/2023 in #questions
REST API Best Practice
hi again
18 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
probably this + the owner_id column is the way to go
108 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
well i guess it is more expressive
108 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
so in theory you could get a USERID1, USERID2 in that column if there were 2 users with role=2
108 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
the problem is it is using string_agg which would in theory join various matches for role=2
108 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
SELECT
c.id,
c.name,
c.code,
COUNT(CASE WHEN e.role = 0 THEN e.user_id END) AS enrolled_count,
COUNT(CASE WHEN e.role = 1 OR e.role= 2 THEN e.user_id END) AS instructor_count,
STRING_AGG(CASE WHEN e.role = 2 THEN e.user_id END,', ') AS creator_id
FROM "Course" c
INNER JOIN "Enrolled" e ON e.course_id = c.id
GROUP BY (c.id)
108 replies
TTCTheo's Typesafe Cult
•Created by Perfect on 4/19/2023 in #questions
Fastest way to get counts (need to redo schema?)
i did finish the query
108 replies