Rebuilding Jagr.Co, Post, Collection, & Taxonomy Models

In this stream, we focus on setting up the models and migrations for the Collection and Taxonomy models and tables. We set up their relationships and get the Collection CRUD operations setup

Published
Nov 26, 21
Duration
1h 39m

Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.

Adocasts

Burlington, KY

Transcript

Looking for something specific? Feel free to search the page for keywords to find a specific portion of the live stream that interests you most.

0:22

okay cool came on and the screen was black so i wasn't quite sure if it was working

0:28

um so i think instead of doing like a proper lesson this week um with the holiday over here in the us and

0:33

everything um kind of also had some other stuff that threw me off

0:39

schedule i think i might just go ahead and stream twice this week so we'll do one today and then we'll try to do one tomorrow as well

0:46

we'll be building out more of the jagerko site so not a whole lot code wise has changed at

0:54

least you know back end wise since the last stream i did go through and kind of stub out the home page

1:02

subject to change but this is all just hard-coded stuff so nothing dynamically pulling or anything

1:08

like that it's where's my there it is it's quite literally just like if i go

1:14

into the index page of resources views it's all right here so

1:26

um so like the sidebar latest lessons it's all just hardcoded right here sorry i had to

1:33

bark at my dog there she was growling weren't you yeah um

1:39

we need to do that at some point but today in particular what i want to do is actually get the remainder of the models

1:46

and migrations that we're going to need at least storage wise set up so for a post we're

1:52

going to have uh where did i put it so i'm going to actually change this up so previously i

1:58

had a post model a series model and then topics

2:03

model but i think we're going to change it up because this would allow things to be a little bit more dynamic in naming

2:10

so we're going to do a post model i guess i shouldn't highlight a collection model and then a taxonomy

2:15

model so a collection would be things like the series however that also opens up the possibility for me to allow you

2:21

guys to create your own playlists or whatever since underneath the hood that is all

2:27

considered a collection and then we could have something like a collection type that would say all right this is a

2:33

course it's a series it's a playlist so it just allows things to be a little bit more dynamic as opposed to having a model just called series

2:39

and then we also have a taxonomy which is also more generic than just saying this is specifically a topic right so this

2:46

allows us to have a kind of a tree-based node system for our topics so we could

2:52

do you know a topic like adonisjs then we could do subtopics for each like little adonis js

2:58

sub set package um so one for like edge i need to stop highlighting one for lucid one for the

3:05

validator and so on and then that would also allow for us to do that same thing with other libraries as well like alpine

3:10

and vue um so i think that's the approach at least that i want to try out and see how it

3:16

goes and then we have our intermediary tables with like the post users which is i think we already have that and then the collection posts post taxonomies and

3:23

collection taxonomies as well so collections themselves would be able to have taxonomies assigned to them too

3:30

so we'll see how that goes um and then one last thing that i did is if

3:36

you recall on the last stream um i think it was we were getting like the

3:41

little avatar logo wasn't spinning up and that's because we were actually hitting rate limiting with google so i

3:47

was using this url straight from google um so instead what i did is i added a hook

3:54

to save this into my digitalocean spaces let's see where it was at social service

4:00

so whenever we're doing a find or create user every time that a user logs in just in case their avatar changes or whatever

4:06

we refresh the avatar using that user user data that we're getting from the

4:11

social service and then that was not deprecated or at least that wasn't lined

4:17

up whenever i wrote this okay well i'll need to change that evidently eventually but what it will do is it will fetch the

4:25

social service url then it will turn it into a array buffer and then turn it into a buffer and then i have it saving

4:32

up into well then i get the file name and then i have it checking whether or not exists

4:38

if it does exist then it will destroy it and then it will re-upload the new version

4:43

so that's what i have going on right there um apart from that that's all that's changed so let's go ahead and

4:51

oh shoot i already created topic controllers and all that all right so we'll end up deleting did i do the

4:58

relationship here i did okay well why don't we just leave that in

5:03

there we'll go ahead and make the models and that for the new here let me get this over onto the side so that i can

5:12

cheat and see exactly what all we need here so that i don't have to go back and forth

5:18

okay so we're going to have we already have user we already have post we need one for collection so let's do node ace

5:23

make model collection

5:30

and node ace make model taxonomy now what i did not do is

5:36

pre-think what columns i'm going to need for this so we might need to just kind of play

5:41

that by ear and then we need a migration for the

5:47

intermediary table so that would be node ace make migration um

5:55

nope yeah no collection posts would be the first new one and then

6:01

we have one for collection taxonomies and then we have another one

6:09

that's not collection based at all that is post taxonomies okay

6:17

so there we go that should be all of the models and migrations that we need to generate we will go ahead and get rid of

6:23

the topic here in a little bit uh let's do the migration first let's

6:29

try to think through what all columns we're going to need for this so for the collections first we know we're gonna

6:34

need a um a collection type now we

6:40

could create a collection type table um i think at least starting out that's okay

6:46

to just have it as an enum and then if at any point we determine you know down the road that we need it

6:52

to be a table we can always do that so let's do table dot um

6:57

well i guess first we'll start with well yeah so integer um and then that would be collection

7:04

type id unsigned and that won't that won't reference anything right now and then

7:10

we'll have table string um collection we'll need to have a name

7:17

i want to say let's limit it uh let's do 75 yeah let's do 100 yeah

7:26

um and then let's see

7:33

that might be good enough starting out um well hold on a minute so we would want a couple of

7:39

other things um so like um

7:44

on the current site if we go to the old

7:50

not that one this one so i have it marked as being oops i clicked on it outdated um so we would want something

7:56

like a status indicator to tell whether or not it's in progress outdated

8:02

completed something like that so why don't we also do another integer

8:09

table dot integer um status id that collection status id

8:15

status id what's our current i know i already have a status enum

8:21

it states yeah yeah we could use the states

8:27

because then you know if it's we could add one for in progress that

8:33

wouldn't be too bad but then if it's completed then it would just be yeah i don't know

8:39

that's not one to one what's status oh there we go

8:44

status perfect all right so yeah we'll just do status id um so step status id that will be

8:51

unsigned that won't reference anything because that does not have its own table either

8:58

um [Music] i'm going to note that down on my little note here

9:07

just so i don't forget that it's actually there well i don't have anywhere to note it

9:13

okay nevermind um so then that would take care of that why don't

9:18

we do this description oh string um dude description

9:26

that could be 255 table string why don't we do why don't we do a page title and meta description too

9:33

i don't think those are ever going to need to be different

9:38

than the name and description but why not

9:45

okay actually meta descriptions are supposed to be what what what are those supposed to be

9:52

oh i have that as two okay well that works just give it a 255. um

9:58

and then why don't we also do an icon so we'll attach this to the assets as well

10:04

do we want that to be a single or do we want an intermediary table for that though

10:11

why why don't we start out as single so we could do table integer asset

10:16

id unsigned and this one will reference id and table

10:24

assets i had to think for a second what the heck asset ids table was um

10:29

okay that should be a good starting point for the collections i think should get us oh oh um

10:37

collections should be able to nest within one another um

10:42

at least one layer so we're also going to want table dot integer that

10:50

uh parent how do you spell point there we go parent id parent collection id let's

10:56

just do parent id um references id dot in

11:02

table uh table name

11:09

okay so that should be good and then we need to do the taxonomies

11:14

uh taxonomies are going to be the same they're going to be nestable within one another so this will have another integer parent id

11:21

dot unsigned references id and table

11:30

uh this dot table name there we go all right and then table dot

11:37

um let's see this is gonna be pretty similar to the topics table so it's not

11:43

going to take much yeah collections also need a slug good point so um let's also do that before i forget

11:51

on the collection so just after the name we will do slugs since the name is 100

11:56

we'll do this log as 150 to account for the hyphens and all that other stuff that just might need to

12:02

change based off of the title and then this will have the same

12:08

um it's also going to have a name so we'll do name first

12:14

these should be shorter i would say they should not exceed 50. um and then we'll do 100 for the slug on

12:22

that one oh yeah i need to do the null not no differentiation here so name should be

12:28

not null description that's fine um actually you know what i'm going to do

12:34

not nullable and default it yeah there we go

12:42

that way we don't have to do knowledge checks we could just do empty string checks

12:48

okay and then this is nullable i'm going to explicitly

12:54

note that this is not nullable and we will default it

13:01

to um

13:07

state status status right there status dot

13:12

in progress i guess that would be the appropriate one to default to and then collection type id we need to

13:19

create an enum for that actually let's do that real quick so enums

13:25

new file collection type

13:30

oh i didn't capitalize type

13:37

okay there we go enum collection type

13:43

and then this would be let me use my cheat sheet because i already blinking on it

13:49

of course series playlist things like that um so

13:55

why don't we do series as one courses two

14:00

and playlist is three

14:09

all right and we will default that

14:15

to

14:21

course

14:28

okay so that table should be all good and then taxonomies

14:35

so we have the parent we have the name we have the slug why don't we also kind of mimic this a little bit closer to the

14:41

collection so it would have page title it would have description um and it would also have an asset id as

14:48

well because why not so we'll just copy those

14:55

um those status id wouldn't make a whole lot of sense so this should be good um

15:03

for the taxonomy and then we have the what is this collection posts

15:08

so that's pretty similar to the post series table that i had on the um

15:16

old project i'm gonna cheat and see what all i had on there because i i think it i don't remember if i it should have

15:22

sword order um oh nevermind i remember so we have

15:29

table dot first and foremost we need the id integers so this would be post id

15:36

unsigned references the id in the table

15:43

posts and then we have integers almost series

15:49

collection there we go collection id unsigned

15:54

references id in the table collections

16:00

and then we're going to have table dot integer we're going to have

16:06

so because collections we're gonna have the same kind of thing going on with taxonomies to an extent

16:13

um

16:19

no actually no we don't need to worry about that so previously um

16:24

what i had going on on the did i have it open i thought i opened it up on the previous project which

16:30

i did i never liked it the way that i did this um

16:35

if we take a look here where is series oh no post series sorry um i had

16:40

a sort order but then i also had a module sort order for the actual module

16:45

excuse me and then the modules were set up just based off of the actual group uh

16:52

like the same module string so that's kind of a cheap way to do it this way is going

16:58

to be i think a little bit better so instead of doing it to where we just checked to see you know which all

17:05

collection posts records have the same module and group those all together we can just do it based off of the parent

17:11

ids and then sort based off of those so these should just need a single sort order column instead of having one for

17:17

the module one for the actual parent level and this will be non-nullable and we'll

17:22

just default that to zero because it may not be necessary in every

17:28

case okay and i think that's it

17:33

for the collection posts we can always add to it later on and then collection taxonomies

17:39

is i don't even know if we need to worry about that sounded good in my head whenever i was

17:45

thinking through them schema

17:53

but now that i'm here thinking about what would actually go inside of it i don't know

18:05

so why don't we do so first and foremost we'll go ahead and

18:10

get the um ids in place

18:28

references id and table taxonomies

18:36

but apart from that like i think that's mostly just binding you know what what

18:46

we'll leave it like that you never know could come in handy we'll leave it like that and we'll see if we end up using it whenever we actually go to implement

18:52

things and then post taxonomies these will definitely be needed so we'll do integer

19:00

post id references id and table

19:07

posts

19:14

and then we have table dot integer um taxonomy id

19:19

uh text on me id unsigned references

19:26

id in table uh okay i'm pretty sure i spelt that

19:32

wrong according to the highlight i did not but

19:38

i rewrote it anyway um and then these will have a sort order as well i think

19:51

i'm going to go ahead and just go ahead and plop a sword order on this too on the collection taxonomies

19:56

i don't think it's going to need it if we do use it but it'll be there just in case

20:02

okay so let's go ahead and fill out the models with um these so again i'm just going to copy all of

20:08

those and then we need to find them so here's collection

20:15

paste that in there let's line it up

20:23

okay i'll leave those there for a second

20:30

um and then we'll want to do at column public

20:35

drop that in do the type and then

20:41

let's see here what have we got going on they are all not nullable aren't they except for the asset id

20:50

okay good enough so we're going to just get rid of all of those um and then there's

20:55

one more thing i need to do what is it oh

21:03

camel case there we go and then we need to switch these from

21:08

integer to number

21:14

and then i need to do ordinal on the asset id

21:19

since it's nullable okay there we go so collection should be good

21:25

now we need to do taxonomy oh actually

21:31

so we have collection type that is not just a type of number but that is a

21:37

collection type and then the status id is not just a number but it is a

21:44

status there we go now that is good all right so now let's do the taxonomies

21:59

okay

22:05

so at column drop that down public

22:16

cut that out paste it in camel case it

22:24

and then after that we will is any of our um asset ids nullable

22:30

oh i need to go put required um not nullable on the name and on the

22:36

well no parent id is nullable actually i need to go do that on the collection too because paranoid is nullable there too i just didn't

22:42

explicitly just specify that okay and then we'll go to our space change

22:48

these two numbers it's always those little things right

22:54

number number or null on both of those actually

23:01

okay and then we'll do the same thing on collection

23:06

there so parent id should definitely be ordinal okay

23:12

is that yeah that should be good and then we on what was it on the taxonomy table we need to go put

23:19

no that is nullable so i can i can go ahead and explicitly specify that just so i don't confuse myself and then not nullable

23:25

on the name okay that should be good and then we just

23:30

need to define the relationships for these intermediary tables to actually make them workable with lucid so

23:38

let's go do that so collection here

23:43

let's see collection should

23:51

collection has collection to post really shouldn't that also be to the

23:56

user why did i not do that

24:04

hmm oh yeah okay because it's more so to yeah you're not necessarily a user

24:12

but then if you do a playlist then it would be to yeah um

24:18

let's make an explicit user id on that i guess

24:24

at least for right now um

24:29

do owner id how about that

24:40

okay that should be good and then we will define that so that that way if i need to add

24:47

the ability later on for more i don't know why i would but for more people to be on it then we could just

24:53

null out that column or whatever and create a separate table for it um so where was that collection so we'll

25:00

go ahead and do the user first so at that well we need to add that into the

25:06

actual model as well so at column

25:11

public no owner id owner id

25:16

um which is of type number and um yeah

25:22

and then we would do at belongs to

25:29

if i'm remembering my rule right on that uh belongs to

25:35

user public owner id

25:42

belongs to type of oops user okay something didn't import there was

25:48

it belongs to it was it user

25:53

or i got something wrong am i misremembering something here i

26:00

must be let me go cheat and look at one of the others it's been a it's been a minute

26:07

ah it looks pretty right let me try rewriting it maybe i fledge something up

26:14

belongs to user all right what are you actually

26:19

complaining about let's read it argument of type collection is not assignable to a parameter of type owner id belongs to

26:36

that um okay

26:45

oh well okay at least there that needs to yeah yeah something as simple as tacking an

26:51

id on the end of it all right there we go and then this also needs

26:57

uh a mini to many with post so many too many

27:04

with uh post i'm going to explicitly specify the pivot table

27:12

as what is it collection posts

27:17

and then we have the pivot columns of what did we put on it collection

27:25

posts just sword order okay

27:32

there we go public posts

27:37

many too many type of post

27:43

and then collection taxonomies which is the one that we weren't quite i wasn't quite sure whether or not i'd actually

27:48

need whoa no we're not tax enemies

27:57

there we go taxonomy scroll up a little bit

28:02

this one has pivot sure column of i believe i just put sword order on that

28:08

and then a pivot table

28:14

of collection taxonomies public taxonomies

28:21

many to many type of taxonomy there we go okay so that should

28:28

be for the collection and then we just need to go do the taxonomy and the user um

28:37

taxonomy is very much so will be specific to just jaeger so there won't necessarily need to be a user uh per se

28:43

on that um so we'll do at

28:50

nope see oh we need to go do the asset as well so there's asset id on there

28:57

so we'll do that so that would be what that that would be another belongs to so let me put that up with the other belongs to

29:09

asset public asset um

29:14

belongs to type of asset

29:20

okay now that should be good if i go take a look at everything else parent we need

29:26

to do the parent too oh boy there's always one more thing in there all right so at

29:31

belongs to itself so collection

29:38

public just name this parent belongs to type of

29:48

collection all right now that should be it now let's go do the taxonomy okay so we

29:54

have parent so i'm gonna and and we have asset

30:00

so i'm gonna go ahead and just copy and we'll we're gonna have posts

30:05

so why don't we just copy all three of those and we'll just need to import stuff

30:10

so belongs to asset

30:19

belongs to collect nope not collection type sorry

30:26

collection and

30:31

many to many post

30:37

and many to many okay and then the name of this pivot table then goes to

30:43

what what am i on taxonomy and this is for post so that would be post taxonomies

30:50

and that also has a sort order um

31:01

isn't there one more oh yeah the inverse of the taxonomy um

31:08

so here i can actually copy and paste this and we'll just inverse it

31:14

okay so instead of taxonomy here which is the model that we're currently within this would be

31:20

collection and then instead of collection no yes no that would still be collection

31:26

taxonomies and instead of taxonomies that would be collections

31:32

and then instead of type of taxonomy that would be type of collection there we go now we

31:37

got the information that and then we can we need to go tech on collections onto the user so

31:44

that's going it's going to be a has many so we'll put that with asmini's

31:53

and uh collection is the model for that

32:07

yeah flip that up there we go and i said i was putting

32:13

this with the has minis but i put it right underneath it has one so let's put that with the has many

32:18

okay and then we're gonna be getting rid of topics so i'm gonna go ahead and do that within here

32:24

so there goes topic bye bye um i'm going to get rid of the model if

32:29

i can find it there it is so delete

32:34

and then we will go ahead and because i don't believe we've done anything yeah now the controller's

32:41

completely empty so it should be a-okay to just get rid of

32:46

it okay that looks good

32:52

and then we didn't do series yet so that's weird that i did already had topic in there but not serious

33:02

but that works um okay so let's go ahead and

33:07

roll back and try running the migrations let's see if we run into any issues and then

33:13

before we rerun the migration we'll go ahead and get rid of the topics migrations so be topic post topics

33:21

and i think that's it so node ace migration

33:27

roll back hyphen hyphen back batch zero so say goodbye to everything

33:34

and then node ace migration run oh no

33:40

get rid of you and you

33:45

all right and i don't know why they just scrolled me up so all right looks good

33:55

let's go ahead and hit run and everything ran okay let's go ahead

34:00

and let's log out

34:07

and then oh

34:13

all right let's see what we've got going on here so can i find module topic where

34:18

model post so all right i took it out of the user but i forgot to take it out of the post as well so let's do that so we're going to want

34:24

to get rid did i i might not have gotten rid of the import in the user either i think i just deleted out the um

34:30

relationship so there we go now it's out of the post

34:36

uh let's go take care of the import on the user okay so now that we have that oops did not

34:42

mean to open safari my bad all right

34:47

cool so now we're signed out um let's go ahead and sign up

34:53

and all right my fix is in place but i fixed the scroll so as you can see here on the

34:58

login the scroll is fixed but my fix is still in place here so we'll need to fix that at some point but

35:04

all right did i break this

35:11

i might have broken this i was working on this earlier today and i could not remember what i was working on

35:18

but i had to abruptly leave so it could be that i broke something and never finished it my

35:24

bad if that is indeed the case no value in column email of relation

35:30

users violates non-null constraint insert into users avatar url created at

35:37

google access to a control id values returning id

35:44

so it looks like it wasn't setting an email but doesn't google come with the email

35:52

like you need a email to have a google account i'm pretty sure

35:58

all right well if i didn't change so much view-wise i would go look and see what

36:04

the git history was but if i had to guess it's something with the off social changes that i did with the

36:10

steve did i change anything in particular two emails here

36:19

you're gonna have to assume it's trying to insert it into the user right insert it to users yes

36:27

so it would probably be this right here oh i didn't provide the email

36:36

really i didn't provide the email

36:43

yeah no no emails lit up what are you lit up about string or null oh okay yeah well both

36:51

github and google the two social services that i require uh

36:56

come with an email so it should be good to just state that that is actually there

37:02

so let's back out try that again see if that was indeed the issue uh no not quite role id what what is it now

37:08

returning inserter update on user table violates foreign cake straight user role id foreign

37:14

so i'm providing a role id is oh i didn't

37:19

seed nothing

37:25

there we go now we should be good cedars are so easy to forget about

37:33

especially since it's been you know whenever it's been a little bit so there we go all right we were able to

37:38

log in i need to make myself an administrator again um

37:43

let's jump in here and do that okay

37:49

what was that roll two i think

37:56

and voila there's all that stuff okay

38:01

so now just the the fun portion where and how do we want to bind

38:09

collection and taxonomy creation management

38:15

so first the verbage here on the pages should probably be updated

38:22

from post to series topics to post collections and taxonomies um

38:29

so why don't we go ahead and do that if i can remember where that is i think

38:35

oh yeah no i also kind of restructured the components and all that too um

38:41

so that's another thing that i did off screen so like if we come in here instead of referencing components um and then

38:47

components and then the actual path uh just using the shorthand of you know

38:52

form input alt to read from components form input

38:59

um so cut back on a little bit of the syntax there

39:05

uh so that's another thing that happened but what was i gonna go do the header for the studio

39:11

so this changes to collections and this changes to taxonomies

39:18

and then we'll need and we i need to update the permission check on

39:23

that as well but we'll circle around and do that later um

39:29

and then the drop down for the actual header needs that as well so uh post

39:36

uh collections and

39:42

taxonomies okay so now that should be updated here as well and it is

39:48

okay so now we need to create the we'll start with collections so we'll create the collections page

39:57

um i think uh

40:02

yeah we'll go ahead and create so let's do node ace make

40:08

controller studio

40:16

collection it should work oh i forgot to make it as a resource

40:21

let's see if we can override it maybe

40:26

skip okay well let me delete it and we'll recreate it

40:35

there we go okay so we'll need an index page this for

40:41

right now we will just return back the view so we'll extract view return views dot

40:47

render studio uh

40:55

collections index and that should just be view

41:01

we'll go ahead and create that page so we'll go down to studio

41:08

collapse some of this up here and cut back on the noise all right so studio new file

41:15

collections index.edge i'm just going to copy and paste the post index uh it's definitely

41:21

going to be different but for the most part it's probably still going to be a table at the end of the day um so it'd just be a matter of changing

41:28

table columns and all that stuff so create new collection and then we're gonna get

41:34

an error here but we'll go ahead and type in what the so this would be

41:39

collection with an s

41:47

and that would be collections and then

41:52

trying to think of whether or not this is going to throw an error probably i'm just going to provide an empty array for right now and then we'll

41:58

need to go through and update all the columns and all that stuff okay so

42:05

we need to go create the create page as well so that that does not throw an error so

42:11

let's see right here

42:16

so this will be view return view dot render

42:23

studio collections are we going to need a separate create

42:29

an update page i want to say no we can always split it

42:34

apart if we end up needing that so let's do create or edit for this as well

42:44

yeah we need to go create that

42:49

so down here do a new file create or edit

42:57

and i don't think it would hurt to just copy

43:05

and paste it from the posts i mean it's going to need a decent amount of changes

43:10

but it should be okay right so let's see if we have a collection id

43:17

then this would be update collection otherwise it's create new collection

43:24

um um i think these actually i think this

43:29

also needs a state doesn't it because then you should be able to put a collection as public private or um

43:36

yeah yeah so it needs a state as well so let's go back into migrations

43:42

collections and where is status let's do state as well

43:49

so table integer state id unsigned

43:55

not nullable and default it to

44:02

public ship that's private public should be good okay there we go

44:07

and then let's go add it into the model and then rerun our migration and then we should be good to proceed

44:15

so there's status we'll do it right underneath there column public

44:20

state id state cool cool

44:27

all right so what was i doing down here yeah so

44:33

for the most part we should be okay to keep some of that right here um

44:39

the draft doesn't make sense but save as unlisted save as private

44:47

and then just i don't know save i'll workshop that

44:53

later on um let's see and then i'm going to just

44:59

comment this double okay we'll just do everything here one one go so let's do

45:05

collections collections

45:14

hey mike thanks for stopping by

45:20

collections there oh thank you for the complaint i appreciate that

45:26

um and then let's see so

45:32

we will stick with the state id but we will get rid of defaulting to draft

45:37

instead we'll default to public and then instead of post that needs to be collection

45:44

and instead of post form this will be collection form um

45:50

this does not need time zone and then we'll need to alter a lot of

45:57

these fields form fields um the

46:02

the uh see we don't need publish at at all so we get rid of that

46:08

we have slug we have description uh instead of nate at title its name

46:15

of title would make more sense but we'll change this to name

46:26

um and then this also needs um go ahead and just do a quick find and replace on this so post

46:34

changes to collection there there there there

46:39

there there oh skip over that one actually we can get rid of canonical

46:45

altogether won't need that okay

46:51

let's replace that one won't need this at all either

46:58

actually this whole right side we're good to get rid of but we want to maintain it because at a

47:03

later point in time we'll add in like the post and the taxonomy management over there

47:12

so we'll leave that there uh we don't need the editor

47:17

so that doesn't need to be there and that leaves us with what is this oh description yeah i

47:26

think i think that's all the right fields okay um and then we can get rid of this

47:31

script i think uh i miss name so i named this studio

47:37

post editor but it does a little bit more than just the editor

47:44

but i i need to split this up so i was going to do it as this just the

47:49

editor and then import it in to another file specifically for the editor page

47:56

but no this does not have anything in it that the collection page would need so we're good

48:02

to get rid of that and then i don't know why that console log was there

48:08

i think this is it so i think that's pretty pretty spot on what we'll need

48:13

um and that just takes us back to defining the routes

48:21

so there's our posts so the route that group

48:27

wow

48:32

all right there we go we got our spelt right this time route.get

48:39

um um shoot collections yes

48:49

and i believe i said this last time but i'll say it again so you can definitely use a resource here um i have this thing

48:55

where i just really like having all of my routes manually labeled out it's i don't know how to describe it it's just

49:02

personal preference but definitely if it's your cup of tea use a

49:07

resource instead of doing what i'm doing and manually defining everything

49:29

i'm going to say hey just copy and paste the posts i think that's what i usually do anyways just copy and paste from one another

49:36

whenever i have a new resourceful style rail

49:42

and then just change all of these from posts to

49:48

collections all right and then on here we'll prefix it

49:55

with collections

50:01

as collections and this will require the middleware role with a role of admin

50:09

and then that leaves us with the finishing up this controller for the

50:15

most part but before we do that

50:20

no i didn't actually add in the url to go to the page let's do that i guess first

50:26

so down to our header and studio header did i close it i did

50:32

oh it's partials so header studio

50:37

wanna do route studio collections index and i will copy this

50:46

and then in the main header we will paste that in

50:54

okay so we should be good to go to collections

51:00

and this button is updated yeah it's updated but it

51:06

cannot read so we need to provide that data the same way that we are to um the

51:12

posts so if we go into the post controller here and we go into

51:18

the create page we have these states so we also need to provide that the same

51:23

way with our collections controller so for the show create sorry

51:30

do state and states

51:37

okay so now if we try it there it is so we have name slug description

51:46

and the seo stuff

51:51

okay so then let's

52:01

[Music] go ahead and

52:08

get that store written then so we'll want

52:15

the request and response for that no yeah yeah yeah response

52:22

um and we'll want to validate it and i think i'm going to use

52:29

a separate validator so we'll do node ace make validator

52:37

collection i don't remember yeah just collection validator

52:45

yeah that works all right um so name which is the schema dot string

52:52

um trim it to true

52:58

rules dot oh i need to import rules oop

53:03

there we go rules dot

53:09

um max length of i believe i set it to 100 you can always double check that

53:16

sl uh well what did i do for the post does that need a slug i think slug.optional

53:22

right

53:29

yeah that should be good okay

53:37

and then we need to copy over that slug unique constraint as well

53:45

i'm doing get rid of that massive comment okay here we go

53:52

um uh what else do you have

53:58

i'll copy that over onto the side so i can actually see it uh owner will get off of the

54:03

authenticated user uh whenever it's created um parents would be another one that we need so

54:09

uh would that be yes that would

54:14

would it be yeah i guess

54:20

we'll bypass that for right now we can always add it in later on so we'll just do a single layer first and then we'll come back and add on that

54:26

second layer with the parent id on it uh collection [Music]

54:35

type id which is a schema and

54:42

job enum

54:48

what is it object.values collection type

54:54

am i remembering that right all right it reads quickly so i guess

55:00

all right and then we have status id

55:06

would be very similar so oh

55:11

wait what options allow oh yeah okay

55:17

so that would be object values and that would be status

55:26

and then you have asset id schema.number and then that we need to

55:32

do rules.exists table

55:39

assets column id

55:44

and then we already have the name in the slug

55:50

description schema.string

55:55

uh we'll go ahead and say sure trim that as why do i keep trying to type trim prime

56:02

so we'll do trim there too and then we'll have meta description

56:11

and then we'll tack on the max lengths to those i believe both are 255.

56:26

okay and a page title skipped every page title so we'll put that above

56:33

the descriptions

56:45

i don't remember what i said as a max length for that max length for that sorry i can't speak

56:51

um

56:58

okay

57:04

cool

57:10

slug is 150 here so instead of 255 we'll do 150 there we go all right so that should be it i think

57:18

for the collection

57:25

so then we'll head back into the collections controller and we'll do const data equals

57:34

await request.validate

57:39

collection validator

57:45

await collection dot create

57:52

data return response dot

57:57

redirect dot to

58:02

route studio

58:07

collections index

58:12

we haven't set anything up with the session um alerts yet but we'll do session.flash

58:20

success your collection

58:28

has been created

58:33

and we have a red squiggly on our data what is it

58:44

oh yeah i do need to provide some more stuff into there don't i

58:49

let's see so what are we missing here we're missing the owner id so we need off

59:00

okay what else are we missing

59:05

um

59:13

paranoid is nullable so that's not going to be needed

59:19

status id should be in data i think right

59:26

um we need to do the slug but that would be we'd do the same thing there as we're

59:32

doing for the post so we need to add that onto the model actually

59:47

collection type id no i'm pretty sure that's in the data

59:53

yep it's in both

1:00:00

oh types of prop oh right right right right

1:00:07

so let's change these back to number

1:00:14

that should fix that right because what what does this say the collection type id

1:00:21

type is for the validator straight all right string um

1:00:27

ran into that with the post as well didn't we that's why we didn't end up using the enum type because we needed numbers

1:00:37

so what did we do for the post i think we just changed it to numbers

1:00:46

yeah so number.optional okay i'm sure you do some type of

1:00:52

check on that as well but uh all right so

1:00:59

well those these ones are required well no we do have the database well yeah we'll leave them as required that would

1:01:04

make more sense okay

1:01:10

so did that get rid of this quickly it did okay so give that a save

1:01:18

and we'll go ahead and try this out let's see if it works so we'll do

1:01:24

uh test collection believe that oh that reminds me slug so we need to go do

1:01:31

what we did on the post for the collection and then while we're

1:01:37

while we have this copy and pasted um we'll do the same thing for the taxonomy because we'll have the exact

1:01:43

same thing so there's slug all the way down there

1:01:48

now we need to import sluggify this one

1:01:54

all right and then instead of title that reads off of name okay and

1:02:01

the same thing there for taxonomy so where is slug on this one

1:02:11

there we go okay now we should be good test so we'll leave the slug empty

1:02:20

this is the description is it save

1:02:27

nothing all right so it didn't even seem like it refreshed

1:02:33

at all so i'm guessing it didn't fire out at all which means we probably have something going wrong here so

1:02:41

yeah can't access priority state id document forms post form oh okay

1:02:46

so on the uh creator update page for the collections all the way down here if we scroll all the way down

1:02:53

to the bottom change this to collection form

1:03:02

okay let's try this again

1:03:07

empty that and scale it down all right so

1:03:12

test collection this is a test

1:03:18

save all right that time it refreshed it brought us back to here i have to assume that we got some sort

1:03:24

of validation error um

1:03:31

so let's dig into what that might be

1:03:42

so i will do a pre-tag well let's actually just do

1:03:49

inspect um

1:03:55

let's just inspect all the flash messages and we'll tr yeah refreshed all right so

1:04:03

test collection this is test

1:04:08

send it off so

1:04:13

collection type id status id asset id

1:04:19

page title i really messed up on the validation evidently

1:04:25

so let's go take a look at that so yeah well these are sending up to my all

1:04:31

right so my thinking was these were sending up empty strings but obviously that's not happening the save is empty strings

1:04:37

if they're not provided so we need to definitely provide optional here

1:04:43

as for the asset id that should be optional and status id should not be

1:04:52

so i'm not i said i said he should be sitting up with him so i'm digging why that's not

1:05:00

and then the collection type id we'll need to add a selector for

1:05:06

but why would these status um status id not be simple

1:05:14

well no so this is state not status so you do need a state a status id selector

1:05:20

as well so okay

1:05:27

underneath here let's do um what do i have going on for this look

1:05:32

but i believe that's in the normal input component yeah

1:05:40

yeah select right there okay so copy

1:05:45

copy this

1:05:52

okay type is select

1:06:01

oops

1:06:08

and then we'll want to do the options here so we'll do at well we do optional manually to find

1:06:15

them that's fine value equals

1:06:21

and then we need to provide these into the page so let's do const statuses

1:06:31

status there we go and what was the other one um uh collection type so const

1:06:37

collection types equals collection type

1:06:51

okay so then this would be

1:07:04

this would be first status

1:07:16

status id it will have a default selection so we

1:07:23

don't need to worry about that collection dot status id otherwise flash message

1:07:31

for the status id otherwise it should be

1:07:37

statuses dot what is in my statuses

1:07:47

[Music] in progress if you're just creating it

1:07:54

in progress all right now that does not need rows at

1:08:01

all so statuses dot

1:08:06

in progress

1:08:18

and then we'll have another one

1:08:25

for completed and another one for archived

1:08:33

and another one for outdated actually so yeah

1:08:43

so completed archived

1:08:50

outdated oh i never put the ending

1:08:56

there we go okay so that should be good for that one and then we need one more for the

1:09:01

collection type which should probably not be the last field in the form but we'll put it here for right now

1:09:08

so this will be type

1:09:13

collection type id

1:09:20

collection type id and then this would be collection types dot

1:09:28

sirius i think is the default that i put on the database so we'll default it here as well and then collection type

1:09:37

and then i think this just has three and the first one

1:09:43

is series course

1:09:49

playlist

1:10:05

all right

1:10:10

so the select style could use some work that's not the best but we'll fix that up later on um let's go ahead and do our

1:10:17

test collection here this is test

1:10:22

then we have our default of in progress and series save

1:10:28

okay cool we went back to the home page so all should be good there it should have created we can verify that with the

1:10:33

database to refresh and go to collections

1:10:39

and there it is so then we'll go ahead and get that querying down

1:10:47

probably do the same thing as we're doing here um

1:10:54

yeah copy most of what we're doing for the posts

1:11:01

directly into the series and just import our stuff so state descriptions

1:11:08

uh we already got states we need to import the route module and it doesn't want to it's too many

1:11:14

competing stuff so we'll import route from at ifc

1:11:20

adonis core route and then we need our off and request so

1:11:27

request auth and that should now do it and then instead of the base url blank

1:11:34

studio post that should be studio collections and we need to return back

1:11:40

states let's uh shoot

1:11:46

state descriptions and instead of querying the related

1:11:52

posts this should now instead be collections

1:11:58

which does not have authors but i'll comment that out for right now

1:12:04

good enough all right so let's see if we can get that at least plopping the name out in the table

1:12:11

so we'll come in here name

1:12:18

name will not have an author column

1:12:23

it will have a status that will have a type it will eventually probably have a view account

1:12:28

won't have publish app and it will have actions and we'll publish that at all so we get rid of that um

1:12:34

and then we need to provide did i change the name of that or am i still writing i just post yeah

1:12:40

collections uh

1:12:46

collections and collections

1:12:54

so provide that into the table as collections uh we can get rid of

1:13:04

that bit right there change this one to name

1:13:09

and instead of doing

1:13:16

say name there everything else should be okay we're gonna need to update the routing though so instead of that it

1:13:21

should be collections uh

1:13:28

yeah and then i have this one hardcoded because it doesn't exist yet but it definitely won't be collections but we'll

1:13:34

hold it there for right now um okay i think that's it so we can go

1:13:39

ahead save oh this needs to change the collections as well edit and destroy

1:13:50

okay now we should be okay to refresh or at

1:13:55

least try nope missing model attribute user dot

1:14:00

collections expects user id to exist on collection model but it is missing so

1:14:05

that is a model based issue with how we are defining the user is and

1:14:11

collections so we are querying from the user

1:14:19

did i never i might have never defined the inverse so i know that we put the user on the

1:14:25

collection as owner

1:14:30

did we not put collections on the user nope it's right here

1:14:39

all right i must have something inversed here let's see

1:14:48

oh it's okay yeah so what what what is that form

1:14:54

foreign key i think that's what they use for that and then that needs to be owner id since this doesn't know what the heck

1:15:00

i'm referencing it as on the collection table i need to tell hey check out the owner id for what collection this user

1:15:07

belongs to so that should nope

1:15:14

okay now user.collections expects owner id to exist on collection model

1:15:24

there we go unexpected okay yeah now it's the commented out issue so we got past that

1:15:33

and it does not like this style of comment well we can get rid of that this definitely doesn't have

1:15:38

authors in it all right another error oh yeah there is no post type

1:15:44

description but this does have a type

1:15:50

so let's just replace this for right now with scope row

1:15:57

type id is it type id it's collection type id isn't it

1:16:05

okay there we go so we get we at least have the name down

1:16:11

so that's a start uh the status is undefined i'm not entirely sure why

1:16:19

and then our uh type is one so our post type there's collection type is one

1:16:26

um so let's see why why why why is the status undefined here so we have state descriptions which i

1:16:32

believe i'm sending down with it and then we have the state id

1:16:38

is that all saving is that let's see where state id

1:16:43

oh there's no state id oh i never refreshed the migration now did i i added it i'm pretty sure i added it i

1:16:49

added it right

1:16:55

yep and double check i wasn't just messing up my eyes here

1:17:02

no there is no state okay so we need to note ace migrate

1:17:10

roll back everything should already be on badge zero so let me just do that and then

1:17:16

notice migration run

1:17:25

let's go log out let's go sign up

1:17:31

and

1:17:37

another issue with this i just fixed it insert into users avatar url created at

1:17:44

email yada yada

1:17:49

user's role id form is that the same issue i ran into last time that i had just fixed

1:17:55

or did i not fix it evidently i didn't what was the issue

1:18:02

oh i didn't see

1:18:10

i need to i need to group those um freaking commands into just a node ace

1:18:16

um migration reset or something like that so that automatically tries to run the seeds for

1:18:22

me and then now somehow we got to the page login

1:18:29

so i'm not i don't know how we got to there

1:18:35

prop oh prob probably the middleware i haven't updated that quite yet

1:18:42

all right let's make ourselves an admin

1:18:48

really okay there we go

1:18:54

definitely logged in should have a user okay

1:19:01

verify that that worked there we go all right so if we go into collections

1:19:07

and we create a new one we should be good to get rid of that now um that little inspect

1:19:15

so if we go down to collections creator edit it's up here at the top right here

1:19:23

all right

1:19:30

this is a test we have these types there go ahead and save

1:19:37

all right now it's coming through as public there we go

1:19:42

test private collection

1:19:49

sure that's fine though um save us private ooh

1:19:55

that didn't work

1:20:01

so what's going on there um click save as private

1:20:08

that worked for the post if i had to guess well no i wouldn't

1:20:16

need it for the validator wouldn't it

1:20:26

and those buttons don't submit the form

1:20:37

hmm

1:20:46

so it would have had to have sent up with something is it still is it looking for state id or did it

1:20:52

change that state all right is it collection form

1:20:58

it is collection form

1:21:05

all right let's try to oh i didn't make the edit page yet so we can't edit it all right

1:21:11

and i don't have delete yet either

1:21:24

so let's see if unlisted might work

1:21:35

nope all right what did i do to you

1:21:47

so let's put actually let's pass in

1:21:54

man i can no longer type i'm sorry event

1:22:01

event and event there we go

1:22:06

let's pass in the event let's prevent default and verify that it's actually sending up

1:22:12

altering then sending up

1:22:20

okay well what am i doing let's get rid of the submit it is just in that click

1:22:32

all right there we go let me get rid of the event there we go okey dokey

1:22:38

so really i shouldn't need to test or type anything but we will go ahead and affirm

1:22:44

document collection form dot what was it state id status id get those

1:22:51

two confused too much state id dot value

1:22:58

actually is it looking for state id or

1:23:03

did i do state id or do it did i just do state

1:23:12

well okay there's a part of the issue there is no state okay

1:23:17

state id schema.number

1:23:22

so there's half of the battle

1:23:28

i wasn't passing it up into the data

1:23:33

so let's see if that was the whole issue testing

1:23:39

unlisted two yep sure enough

1:23:46

well that i mean it would be hard to save it as a specific state if you're not actually saying that it should be a

1:23:51

specific state not wouldn't it there we go all right

1:23:58

there should be different colors but that's a whole different issue hey roman um let's see he said you

1:24:04

should create a mf s that migrates back

1:24:09

runs and seeds alias mfs star yeah

1:24:17

i i don't know why i have such a hard time remembering to run seeds

1:24:23

um but it is an ever long issue for me all right um

1:24:31

let's see let me go ahead rig up the edit page and the delete because this should already

1:24:37

exist since we just need to query it provide the same stuff that we have here in the store and then delete would just

1:24:45

be deleting it and then we'll need to slowly add in the ability to manage the posts

1:24:51

and then we'll see whether or not we want to do taxonomy so i'm still undecided about that

1:24:57

um so we would want view we

1:25:02

did params and [Music]

1:25:10

that probably probably it um so we'll want to do const

1:25:15

collection equals await collection dot find

1:25:22

or fail programs dot id

1:25:28

shouldn't need to preload anything at this point in time um

1:25:34

yeah so and then we will do return

1:25:40

view dot render studio

1:25:46

collections create or edit and pass it in

1:25:52

the collection and we're also going to need to pass it the same stuff that we're passing to the create so states

1:25:59

statuses and collection types so we'll go up to here and just copy

1:26:05

these okay here oh

1:26:10

that's supposed to be statuses there we go

1:26:16

so that might actually just be it for edit and then we would need to go through and do update so we'll see if we can yep

1:26:25

um the slug auto populated nothing else did did i have maybe i i knew i put a

1:26:32

description on this one yeah so this is probably still just referencing title probably forgot to update that

1:26:39

let's go see sure enough there it is

1:26:46

okay there we go and then while we're here let's go ahead and do the update as well

1:26:52

so this one will take request response params

1:26:59

session and i don't think we'll need off because the owner's

1:27:04

already set so use the same validator as the create so

1:27:11

wait request dot validate collection valid theater

1:27:19

um scroll to the top on accent

1:27:25

all right and then let's actually do well yeah validate the data before you actually

1:27:30

query and then we'll do collection equals awaits

1:27:38

collection finder fail params.id

1:27:45

and then collection dot merge

1:27:53

data dot save wait

1:27:59

return view oh i grabbed a response i want view

1:28:05

there we go dot render studio

1:28:14

i had such a hard time remembering collections collections index

1:28:21

no create no uh sorry no what am i doing here you do you're not

1:28:26

referencing the edit this is update so you do want response

1:28:32

and you want to redirect to that route

1:28:42

okay and then we can go ahead and while we're here let's do destroy

1:28:49

no we won't need requests at all we just need response and params

1:28:54

so const collection equals weight

1:29:00

collection.find or fail params.id

1:29:06

and then we will do awaits collection dot delete

1:29:13

return response dot redirect to route

1:29:20

studio collections oop doing dots

1:29:26

collections index there we go okie doke

1:29:33

so i think everything on the front end should already be set up to accommodate

1:29:39

for that so we have the name in here we have the

1:29:44

slug description and the statuses so let's change this to a course type

1:29:50

let's change the description to have edit on it let's change the title or the name

1:29:55

to have edit on it as well and this one was public so let's try to

1:30:02

change it to unlisted did i have two of these

1:30:08

i must have so this changed to unless it created

1:30:17

it might have created let's try that again

1:30:23

edit two sure enough yeah that created because

1:30:28

now we have seven we had six so

1:30:34

i bet you that still checking if post which would definitely be

1:30:40

false yep right there so if post so if

1:30:46

collection all right there we go

1:30:52

well that gives us the uh plenty of records to test start to lead out with anyway so we'll delete

1:30:59

can i find route studio collections index oh collection needs ass

1:31:09

well why am i hard coding that to route studio dot

1:31:15

collections dot index there you go see so i was right with dots i was just second guessing myself

1:31:21

because that's a redirect not a not a render path okay

1:31:28

man i need to go to bed it's only going on six but i am

1:31:36

evidently really ready for bed all right so let's try delete row not found

1:31:42

we're not found studio collection seven

1:31:53

taxonomy tech nope collections so we only have six

1:32:00

and it looks like this one may have already deleted so yeah okay that makes sense then

1:32:07

all right and then we'll try it again this one make sure it goes okay yeah all right there we go

1:32:12

all right so now let's try this again let's see if so let's do edit three we haven't named anything three yet

1:32:19

give that a save okay still with this can i find route studio

1:32:27

collections index on the redirect

1:32:32

to the route oh i fixed that on the delete but not

1:32:39

the yeah right here

1:32:45

all right there we go i thought i looked at them

1:32:50

all but evidently not all right so let's try you again so let's let's go back into collections

1:32:57

and we have this three now so let's try four

1:33:04

and we no longer have a three but we do have a four so that seems to be working let's try changing it from public to private

1:33:11

that's working private to unlisted that's working

1:33:17

in progress to archived and from series to course

1:33:26

oh i don't have the in progress state on here but the series the course did work

1:33:33

and then we can try course to playlist which should be three now and there we go okay so that's working

1:33:41

and then

1:33:51

we're going to do

1:34:01

add the status onto there go ahead and do that real quick

1:34:11

so no that is status archived

1:34:17

in progress complete archived outdated but no so i have that mislabeled that's not

1:34:23

status it's state yeah

1:34:28

yeah got that mislead so state

1:34:34

state id uh really that

1:34:40

could probably just put that on the same line

1:34:47

that way it's not taking up a whole other column

1:34:54

so we have state descriptions do we have a status description

1:35:01

state status we do status description so we will go to

1:35:08

here and on the index page in addition to states and state descriptions we'll do const

1:35:16

i don't know if i need status provide it and see

1:35:28

okay

1:35:40

and then we'll just need to do the same thing here so status descriptions

1:35:45

scope row status id

1:35:51

we'll see how that looks it might not look what that why did it what did i do

1:36:00

why did that just turn into a number

1:36:09

oh yeah i need to update this as well

1:36:29

there we go all right sitting here going what did i do wrong

1:36:35

all right let's try this now status descriptions scope row

1:36:44

status id and it's not the best

1:36:49

i'll leave it as is though it wouldn't be too bad to do like a little slash have this be darker and bolded and that

1:36:56

light and not folded

1:37:01

um yeah i don't really know how i like in the previous project i didn't use them a

1:37:06

whole lot it was mostly just on this page and then on the create network page [Music]

1:37:12

but i'll play that by ear i definitely could make those globals

1:37:20

um

1:37:28

well i can see

1:37:37

yeah that's a be on the post page series page

1:37:44

comments page so it's mostly all on the back end side but

1:37:49

i'll play that by ear

1:37:57

okay

1:38:03

let's see um

1:38:08

so we need to bind our posts to our well we

1:38:14

don't have any post anymore but we need to bind our posts to our controllers as well our

1:38:20

collections as well i might save that for tomorrow um

1:38:26

kind of out of it tonight but we did manage to get our collection

1:38:32

set up we managed to get our migration set up for the future and

1:38:41

some other stuff i can't quite remember but yeah um so

1:38:46

cool good times ahead we'll hopefully be getting this homepage rigged up to live

1:38:52

data here soonish once we get the posts and the collections set up which should

1:38:58

be good taxonomies can come in later um but yeah so thanks everybody for

1:39:05

stopping by i'm gonna go take a nap or something but i appreciate you guys appreciate you

1:39:11

guys stopping by and i will see you guys tomorrow i'm not quite sure what time but

1:39:16

um probably morning or afternoonish

Join The Discussion! (0 Comments)

Please sign in or sign up for free to join in on the dicussion.

robot comment bubble

Be the first to Comment!