Thứ Hai, 2 tháng 10, 2017

Waching daily Oct 2 2017

♪♪

>> WE'VE ALL HEARD THE WISE

ADVICE "DON'T BELIEVE EVERYTHING

YOU HEAR."

BUT THERE'S ALSO WISDOM IN A

SIMILAR IDEA: "DON'T BELIEVE

EVERYTHING YOU THINK," BECAUSE

SOME FALSE INFORMATION MAY COME

FROM OUR OWN THOUGHTS.

WE MAY THINK THINGS ABOUT

OURSELVES AND OTHERS THAT SIMPLY

ARE NOT TRUE--THOUGHTS LIKE "I

CAN NEVER CHANGE" OR "I CAN'T

FORGIVE THIS PERSON" OR "I'M

NOT GOOD ENOUGH" OR "SHE DOESN'T

LIKE ME."

THE DANGER OF SUCH THOUGHTS IS

THAT THEY DON'T STAY THOUGHTS

FOR LONG.

THEY CAN QUICKLY HARDEN INTO

BELIEFS THAT AFFECT THE WAY

WE SEE THE WORLD. SOON THOSE

BELIEFS BECOME ACTIONS THAT

CAN LIMIT OUR PROGRESS, DAMAGE

OUR RELATIONSHIPS, AND HINDER

OUR HAPPINESS.

SO HOW DO WE PREVENT THIS? ONE

APPROACH IS TO TREAT OUR

THOUGHTS THE WAY WE WOULD TREAT

OTHER INFORMATION WE MIGHT

ENCOUNTER.

WE CAN ASK OURSELVES, "IS IT

TRUE?

WHAT EVIDENCE DO I HAVE? DOES IT

SQUARE WITH OTHER THINGS I

ALREADY KNOW? IS THERE ANOTHER

EXPLANATION?"

WE CAN LISTEN TO OUR CONSCIENCE

AND TO TRUSTED LOVED ONES.

IT TAKES COURAGE AND HUMILITY

TO EVALUATE OUR THOUGHTS IN THIS

WAY, BECAUSE IT MIGHT MEAN

ADMITTING THAT WE WERE WRONG!

NOT LONG AGO, SOME TEENAGERS

DECIDED THAT A BEAUTIFUL YOUNG

WOMAN AT THEIR SCHOOL DIDN'T

LIKE THEM.

SHE HARDLY EVER LOOKED AT THEM,

AND WHENEVER SHE DID, SHE

SQUINTED AT THEM.

THEY CONCLUDED THAT SHE WAS

VAIN AND CONCEITED.

WHAT THEY DIDN'T KNOW WAS THAT

SHE HAD POOR VISION.

EVEN WITH CONTACTS, SHE HAD TO

SQUINT TO SEE PEOPLE.

ONCE PEOPLE ACTUALLY GOT TO

KNOW HER, THEY REALIZED THAT

SHE WAS VERY KIND AND WONDERFUL.

BUT FOR TOO LONG, PEOPLE WHO

COULD HAVE BEEN HER FRIENDS

AVOIDED HER BECAUSE THEY

BELIEVED THEIR INCORRECT

THOUGHTS.

IS IT TIME TO DEBUNK SOME MYTHS

IN YOUR OWN MIND? A GOOD PLACE

TO START MIGHT BE THOSE NEGATIVE

OR DEGRADING THOUGHTS--ABOUT

YOURSELF AND ABOUT OTHERS.

YOU CAN CHANGE, AND SO CAN

OTHERS.

YOU CAN FORGIVE, AND SO CAN

OTHERS.

PEOPLE MIGHT LIKE YOU MORE THAN

YOU THINK.

AND YOU MIGHT LIKE THEM MORE

THAN YOU THINK.

GIVE YOUR BELIEFS AND ACTIONS

THE FIRM FOUNDATION OF TRUE,

UPLIFTING, CHARITABLE THOUGHTS,

AND REMEMBER, DON'T BELIEVE

EVERYTHING YOU THINK.

For more infomation >> Don't Believe Everything You Think - The Spoken Word - Duration: 3:00.

-------------------------------------------

50 Most Awkward Christmas Family Photos Ever - Duration: 5:33.

Most Awkward Christmas Family Photos Ever Most Awkward Christmas Family Photos

Ever

Most Awkward Christmas Family Photos Ever Most Awkward Christmas Family Photos Ever

Most Awkward Christmas Family Photos Ever

For more infomation >> 50 Most Awkward Christmas Family Photos Ever - Duration: 5:33.

-------------------------------------------

React & Azure Cosmos DB Part 3 - Creating The UI - Duration: 8:06.

all right now it's time to build the front-end portion of our application so

let's get right to it let's start here in our source folder which is where our

front end is and we'll just start with App.js is let's start with some cleanup we

don't need this constructor and we actually don't need this method here

either they come by default with the boilerplate project we don't need those

we're not going to be making Ajax call here this is a pretty dumb component and

then let's replace the default markup that we have with some new markup so

we'll have an h1 which will be our basically our title says heroes and then

below that let's create something called a header bar which is just an empty div

with a nice blue bar and then below that this is where all of our hero's go

pretty much the application is gonna go here and I'm calling it heroes for now

because that's gonna be the main wrapping component I'm gonna have some

CSS and I'm just copying and pasting this in and get this from the github project

home let's collapse our bar and then let's check and see what this looks like

so far in the browser okay starting to look pretty good we got a title we got a

bar ready to build out our list of heroes over here on the side so let's do

that I'm gonna come over and I'm going to

create a components folder where we're gonna put all of our components and

inside of that create a new component and call it heroes now inside the heroes

component we're going to need to import React and component alright so let's

start with a component class and abrir just gonna call it heroes and then we're

gonna go ahead and set the initial state of heroes to be an empty array this is

we're gonna stuff the returned from our Ajax call to display on the page here

and then down here let's start writing our JSX so we'll have an empty div and

inside of that a an unordered list of heroes where we're gonna list out all of

the heroes those will go here and then below that let's have an edit area area

perfect and then our edit form goes here too so we'll just put some comments

there now let's go ahead and actually get the heroes so that we can see them

listed out here so to do that and actually before we can do that we need

to actually have some data so let's jump over to our index file up here let's

modify this route just a little bit so let's call this heroes and instead of

welcome to Express let's just say const heroes and that's

going to be arrey and then let's return one so an

hero has an ID a name so I'm gonna use the tick because that's my favorite and

saying what's the tick saying spoon have no idea why but that's what it is

if you've ever seen the tick before that makes sense to you if not that's

complete nonsense so we'll send back our heroes sorry and we want to do res.json

because we want to send back some JSON cool let's restart the server and then

let's test this out make sure this works so we'll jump over to the browser

remember Express is running on port 3001 so we can say api/heroes and we should

get back yep we do there's our JSON so we're ready to consume this and display

it over here so let's do that we can hop over to our hero's file and we can just

sort of list out our hero's here so what we could do is say this don't state dot

hero's and map and map will loop over our hero's object and we can work with

each individual hero in that collection and then we could have we could have

just a list item that has the hero name let's just do this for simplicity at the

moment and we'll start to build this out more and then up here we need to

actually make our Ajax call so let's do that I'm gonna use a component did mount

method so our components mounted it's ready to go and we use the fetch API to

call /api/heroes which returns a promise we get a result we'll

take that result turn it into JSON which is a built-in method on fetch and that

because is yet another promise which has our actual JSON in it and then in there

we can say this.setState and then heroes is equal to our JSON okay so

we're making the API call we're turning the result into JSON and they were

taking the JSON which is the array and we're putting it into the state and then

we're looping over the state and listening out the heroes let's go ahead

and add this component to our App.js file since we're done here and let's go

ahead and put it in so we'll just say we can say heroes and it'll automatically

get pulled in and imported up here at the top cool alright now let's go back

and check out our app tation and we're pulling in our items so

if we added another item it would show down below this just go ahead and

continue to build this out and again we don't want to put all of this here let's

actually make this into its own component so we'll pull this out and I'm

gonna do a new file here and let's go ahead and save it I'm just gonna call it

hero.js and we'll put it inside of these source components here we'll just

save it right there then we need to pull and react and we actually don't need

component we just need to React and this is gonna be a stateless component and

we're gonna call it hero and we'll build out the innards of this thing and we'll

have a list item and that list item will contain a delete button so we can delete

the hero and it will contain an element which has all the hero of properties on

it so we'll call that hero element and inside of that we're gonna have a badge

which will display the ID and then we can just copy option shift copy these

three rows down we can change this to a name and we can change this to sink okay

and then up here we're gonna look at props hero which we haven't created yet

the ID and then let's copy this in as well and actually I should have done

that and then copy the line down would have been a little bit faster here and

then we'll update the name and we'll update the saying okay we're pretty much

ready to go here other than the fact that we need to add in properties so

let's add in props up here otherwise we won't be able to read them and we're

ready to use this component in our hero's component let's let's go back and

we can just do return and we can say hero we'll just let it pull in our hero

component automatically if you remember it does that up at the top and then we

need to pass in that prop that hero's props.hero right there and then

we'll just say it's equal to hero okay if we do this and nothing else this

should work just fine so if we go back over to our application and oops made a

little bit of a typo there so let's go ahead and fix that so it's not props.hero

it's not props.name its props.hero.name and props.hero.saying

and now we're looking a whole lot better cool alright so the

next thing we need to do is add in the ability to edit this item so that's what

we'll be doing next now what we want to happen is when we click this item

when an edit form to show up and we want this to be highlighted in the edit form

to contain the data from this item so the first thing you need to do is

actually handle the select from this item here so let's jump back over here

and I'm gonna go back to the heroes component and in fact I'm gonna go let

me move this to the side and let's close everything but this stay focused here

and what we need to do is we need to pass in a basically a click event

handler for this hero so we click on a hero we can handle the event so first

let's just add that event here and we'll call it a handle select and then that's

going to receive a hero so when we click on this hero element any hero element it

will handle the select and pass that hero in to the select event and we also

need to go ahead and start with a constructor here because we're gonna be

using events so we're gonna need to bind the context of those events so bear with

me here let's carry it create a constructor and then inside of that

we'll call super and then we'll just add our state back on and then the next

thing we want to do is we want to bind so we'll say this.handleSelect

equals this.handleSelect that bind this and the reason why we do that is so

that inside of our function here this has an actual value if we don't do the

bind up here then this will be unknown and that is not a limitation of React

with a limitation of es6 classes just the way it is so now when we handle this

the select what we want to do is we want to go ahead and set a selected hero so

we're gonna do this.setState and we're gonna do a selected hero and set

that to hero right here now once we've set the selected hero we need to show

this edit area form which we haven't created yet so let's do that now I'm

gonna open up a new file we'll save it and we'll call it EditHero and we'll

put it in the source and the components and let's give it the right file

extension there we go and then let's import React and again this is going to

be a stateless component and it's gonna be called EditHero ok and we're gonna

put our edit form here now actually gonna copy this in because it's a little

bit lengthy ok so let's look at this markup because there seems to be a lot

of it it's not that bad but let's go through it we're gonna look at the

selected and if there is a selected hero then

we're gonna return the enough markup to create the Edit form if we scroll down

the else condition is to return an empty div so we're gonna only gonna show the

Edit form when there is a hero selected that's all that's doing and then we're

gonna loop to the Edit fields and on the ID portion we're gonna look at the props

and say are we adding a hero this is a boolean value that we have it created

yet if so then allow the user to change the

ID if not then the ID will just be a label and then as we move down the form

we're gonna have two more inputs one for name and one for saying and the value

will be the selected hero name and saying so we're bound to the selected

hero so when we change the selected hero in this form the selected hero objects

going to change and that's what we're gonna eventually pass back to the

database and then we're handling the on change of inputs because this is how

forms work in React and these are controlled inputs so we're actually

gonna have to handle the change of these inputs so that we can make sure that our

selected hero changes along with those inputs when they change so let's go

ahead and build this out in our heroes file where we're actually going to

consume this edit hero component so let's go back here and we'll add an edit

hero as we've done before many times and then we need several different things

here the first thing we need here is adding here adding here is a boolean

that tells us whether or not we're adding a hero or editing a hero we're

gonna set that equal to this.state.addingHero and that doesn't exist

so let's go ahead and add that to our initial state up here so we'll say

hero's and adding hero by default will be false okay now the next thing that we

need to do is we need to pass in the selected hero so we'll say selected hero

and that's going to be equal to this.state.selectedHero and if you

remember on our select event up here we're actually setting that selected

hero to the hero when a hero is selected now the next thing we need to do is we

need to handle the on change event of those inputs so we're going to go ahead

and do on change and we're gonna have an event called this.handleChange

doesn't exist yet we'll create that in a moment

we've also got an on save event in form so we'll visit this.handleSave

and we've got a cancel event so on cancel it equals this.handleCancel

okay let's go ahead and add these events in up here and I'm just gonna go ahead

and so you don't have to watch me type all this I'm just gonna go ahead and put

them in and I'll be right back with you alright I've added those in here's all

the events and I just stubbed him out I haven't coded anything so you didn't

miss anything and then of course they've been added in down here so let's go

ahead and take a look at the application still nothing is happening here and

that's because we're not handling the click we haven't wired this up and we

need to do that in this hero component so what we need to do is is pass in an

event here so we're gonna pass in the let's see handle select is what we

called its arena say on select equals handles select and now that we're

passing an onSelect prop we need to do something with that prop so let's

go over to our heroes file our hero file excuse me and let's go ahead and handle

that so in the list item each time we have a click an on click in the list

item here we need to handle that and I'm going to copy this in alright so on

click we're going to call the on select from our props and we're gonna pass in

the currently selected hero and then the other thing we that we need to do is we

need to set a class name so that we know that this item when it's selected stays

highlighted so we'll do that and I'll copy that in alright here we go on this

line we've got the class name and the class looks at the hero and compares

that to the selected hero and if those two things are the same then it applies

a selected class if they're not then there is no class so one last thing over

on heroes we need to actually pass in our selected hero because we're not

doing that yet so let's do selected hero equals this.state.selectedHero

ok perfect save that I'll get some formatting we're

looking good alright let's jump over to our application and have a look oh and

we've got a silly area here this needs to be this.handleSelect all right

and now if we click on one of these we see the Edit form and the item stays

highlighted so the next thing we need to do is wire up the cancel button because

that doesn't currently do anything so let's go back and do that in this method

have to do is say this.setState and we're gonna say the selected hero and

we're just gonna set it to null because there's no longer a selected hero and

what that will do is reset the form so if we click this now we say cancel and

we go back right this is no longer highlighted and the form goes away

perfect now notice in our edit form we can't actually edit this form so I can

type all day but these inputs are not accepting that and that's because these

are controlled inputs so we need to handle the change and we've already

specified that here on the on change we've already got a method waiting to be

implemented here so let's do that in the handleChange what we want to do is

first we want to get a reference to the currently selected hero so we're going

to say let's selected hero equal this.state.selectedHero because the

things in the state are immutable means you can't change them so in order to

change it we have to make a copy change the copy and then put it back this is

generally considered a good thing because it makes it so that you can't

change the state really without very explicitly doing so and now we want to

change you that the name or the saying of the selected hero based on which

input change but how do we know which input change they're all calling this

same event well we're gonna pass in an event object and that's already me and

passed in and then what we'll do is we'll use array notation on the selected

hero so we look at the event target name so if we come back over and look at our

event targets you can see that we have our event target name is set to name and

name is set to saying here so when this happens this will be selected hero dot

either saying or name depending on which event got passed in and then we'll set

it to the value of the input so that's how we can use one event to handle

multiple inputs and then the last thing we want to do is just update the state

so this.state and selected hero equals selected hero

okay now that we've done that let's go back over to our application click on

one and now we can edit these fields right and you can see that as I make

these changes it makes the change over here on this

side as well all right so we're good let's go ahead and implement the ability

to add a new item to do that we're gonna need a button so let's add one in I've

got one ready to go and we need a handle enable ad mode so I'm gonna add that in

okay so I've added that in both up top here I've bound it and down below here's

the method and what we want to do is we want to set the state here and we're

gonna set two things we're gonna set adding Hiro because that's not true and

we're going to set the selected hero to a default value so we're gonna give

it all empty strings all the way across the board and the reason why we're doing

that is we're looking at this both of these properties really so selected hero

if we go back over to the form see if we all pass the selected hero we don't see

this form at all so we need to pass in a selected hero otherwise we see nothing

because this is how we're controlling the visibility of the form and that the

boolean just tells us we're in an edit mode versus add mode so now we click on

the button we get the form here now it's important to note that now that we've

set the adding hero state here to true whenever we cancel out we need to make

sure that we put that state back so we need to say adding hero here is false

now once we've done that we come back over if we click we do not get to edit

the ID if we add a new hero we can edit the ID which is exactly what we want so

handling all the different states them you might have here okay now the last

thing we need to do is just implement this delete and this save but really we

need to wire those up to the database in order to do that so we're on to Cosmos

DB we're ready to rock and roll so let's go ahead and do that

For more infomation >> React & Azure Cosmos DB Part 3 - Creating The UI - Duration: 8:06.

-------------------------------------------

Yummy Nummies! - Duration: 3:23.

Hey guys what's up welcome back to my youtube channel my name is Jacob and if

you're new here please make sure you hit that subscribe button I post new videos

every Mondays and Thursdays and without further ado let's get into the video

today I have a yummy nummies kit for us to do I've never actually done one of

these before but I thought it was kind of cool because you just mix powder and

water and it makes food so we're going to be making some donuts and let's get

started and see how it turns out inside we have this tray along with all of

these different packets of powder I think that we mix to make donuts so

first we have to cut this tray and now in this little section right here we

have to mix 12 packets of the vanilla batter and 5 scoops of water so this is

what we have so far I've never really made donuts before but I don't think

this is what the batter usually looks like so hopefully I'm doing it well

right now the directions say we have to fill this tray with the donut mix and

then we put it in the microwave for 15 to 20 seconds so let's go do that

so now that our doughnuts are out of the microwave they look pretty good they

actually smell really good I'm kind of surprised so now we have to make the

icing and how we do that is we have to mix two big scoops of frosting powder

with two small scoops of water whoa it's turning blue so now that we have our

frosting we've to frost our doughnuts it came with these little bags but I don't

really have the time to do that so we're just gonna throw the frosting on

now that our doughnuts are all frosted we're gonna add some sprinkles and voila

now we have some wonderful doughnuts wow are these Dunkin Donuts or did I just

make these I can't tell but first you have to do a little taste test hmm well

I'm just surprised you get really good thank you guys so much for watching I

hope you liked it they actually came out way better than I thought they would so

that's kind of a surprise but make sure you comment down below if you've ever

done one of these yummy nummies before and let me know what video you think I

should do next time make sure you subscribe because I post new videos

every Mondays and Thursdays and we'll see you next time bye

For more infomation >> Yummy Nummies! - Duration: 3:23.

-------------------------------------------

Letters a & o and Handwriting Analysis Graphology - Duration: 9:57.

The letters "a"& "o" and your handwriting.

I'm Fiona MacKay Young and in this video we're going to look at the lower case letters "a" and "o"

and how they show in handwriting, and what they mean:

how the different strokes and ways of writing them, the different meanings that gives.

We'll also take a look at the capital letters.

So, if you've ever wondered what you "a" and "o" mean, or you'd like to change and get something new,

this is the video for you. So "a" and "o" in handwriting. Coming right up.

For more infomation >> Letters a & o and Handwriting Analysis Graphology - Duration: 9:57.

-------------------------------------------

Publisher of Thinkrutptor Magazine - Excuses are holding you back!! - Duration: 7:15.

Want to know more? Subscribe for your free magazine copy at Thinkruptor.com!

Want to know more? Subscribe for your free magazine copy at Thinkruptor.com!

Want to know more? Subscribe for your free magazine copy at Thinkruptor.com!

For more infomation >> Publisher of Thinkrutptor Magazine - Excuses are holding you back!! - Duration: 7:15.

-------------------------------------------

14 Days, Yes! Only 14! 14 Day Challenge To Lose Up To 9 Kilos! - Duration: 3:03.

subscribe our channel for more !

14 Days, Yes! Only 14! 14 Day Challenge To Lose Up To 9 Kilos!

Losing weight is one of the things that everyone looks for with much interest. We want to see

ourselves well, to be within the standards of beauty and it is considered that the human

being is always looking to lose weight.

But, not always, it is so easy to achieve and if we want to do it takes a lot of effort

and dedication.

Usually people are looking for several types of methods to lose weight: diuretics, laxatives,

pills and extreme diaries or exercise routines that damage and deplete our body, many of

these people resort to some surgery as a last resort to get the body they want to have , Without

realizing that there are methods that allow you to achieve the goals you want without

side effects.

Today we will tell you about this natural remedy that will cause you to lose up to 9

kilos in 14 days. The best thing about this remedy is that it is very easy to prepare

and completely natural, it has no side effects, on the contrary it will provide nutrients

that your body needs. We recommend you try it and take note.

In addition to losing weight, this method will detoxify your entire body. This will

allow the substances you no longer need in your body to expel them naturally.

YOU WILL DRINK THIS DRINK EVERY DAY FOR AT LEAST 45 MINUTES BEFORE BREAKFAST:

Day1: Dissolve the Juice of 1 lemon in 1 cup of fresh water

Day 2: Dissolve the juice of 2 lemons in 2 cups of water with ¼ teaspoon of honey.

Day 3: Dissolve the juice of 3 lemons in 3 cups of water with ¼ teaspoon of honey.

Day 4: Dissolve the juice of 4 lemons in 4 cups of water with ¼ teaspoon of honey.

Day 5: Dissolve the juice of 5 lemons in 5 cups of water with ¼ teaspoon of honey.

Day6: Dissolve the juice of 6 lemons in 6 cups of water with ¼ teaspoon of honey.

Day7: Dissolve the juice of 3 lemons in 10 cups of fresh water with 1 tablespoon of honey

(you must drink throughout the day).

Day 8: Dissolve the juice of 6 lemons in 6 cups of water with ½ teaspoon of honey.

Day 9: Dissolve the Juice of 5 lemons in 5 cups of water with ½ teaspoon of honey.

Day 10: Dissolve the juice of 4 lemons in 4 cups of water with ½ teaspoon of honey.

Day 11: Dissolve the juice of 3 lemons in 3 cups of water with ½ teaspoon of honey.

Day 12: Dissolve the juice of 2 lemons in 2 cups of water with ½ teaspoon of honey.

Day 13: Dissolve the Juice of 1 lemon in 1 cup of fresh water without honey.

Day14: Dissolve the Juice of 3 lemons diluted in 10 cups of water with 1 tablespoon of honey

(you must drink throughout the day).

The days where it is not indicated to drink the drink throughout the day, it is because

the lemon juice should be taken in one go.

If you like our video then do subscribe to our channel.

Please leave us a comment and give a thumbs up.

It means a lot. Thank You :)

For more infomation >> 14 Days, Yes! Only 14! 14 Day Challenge To Lose Up To 9 Kilos! - Duration: 3:03.

-------------------------------------------

Shorewood IL Sewer Repairs 815-630-1024 Shorewood IL Sewer Repair - Duration: 1:09.

Shorewood IL Sewer Repairs. Are you sick of having your drains or sewer line rodded and paying someone to come out

every 6 months?

Tritan Plumbing has a long lasting solution to the problem of drain obstructions and tree

roots intruding into sewer lines.

We have a state of the art high pressure water jetter that cleans out grease, sludge, tree

roots or any other blockages in your pipes.

While rodding only pokes a hole in the clog, water jetting cleans out the entire surface

of the pipe.

We are trained experts in sewers, drains, and septic systems.

We'll stop your problem at it's source and keep your home safe.

To get a better view of what's going on, our technicians can do an in-pipe camera inspection.

If your drain is blocked and causing issues, emergency service is available.

Give Tritan Plumbing a call today, we'll get there fast!

815-630-1024

For more infomation >> Shorewood IL Sewer Repairs 815-630-1024 Shorewood IL Sewer Repair - Duration: 1:09.

-------------------------------------------

Video: Here's how you can help pets impacted by the hurricanes - Duration: 2:15.

For more infomation >> Video: Here's how you can help pets impacted by the hurricanes - Duration: 2:15.

-------------------------------------------

React & Azure Cosmos DB Part 5 - Cosmos DB Read And Create - Duration: 7:52.

I'm gonna create a new file let's go ahead and save it we'll call it hero

hero-service.js we'll stick it in the server folder good and then let's go

ahead and bring in our hero model which was

there we go and then I'm gonna bring in read preference as well which comes off

of the MongoDB package so we can say MongoDB and then read preference now the

reason why we're bringing in read preferences is we're gonna actually use

that here in a minute to optimize our query and we'll talk about that when we

get there and then we want to require in our Mongo file right which contains

contains our connection function and then just call connect and that connects

us to the cosmos DB instance now let's create a function which will get all of

our heroes out of the database we'll call it get and we'll just pass in the

request and the response from the route so instead of handling the request and

response on the route we're just gonna send them straight to the service which

is going to handle them and the first thing we're gonna do is we're gonna

define a new query so we'll call it doc query and we'll just say hero dot find

and then find as part of that nice Mongoose API we're not gonna pass in any

parameters to reach find everything and read preference nearest and what this

does is it set it just says simply tells MongoDB read from the nearest database

because cosmos DB is a globally scaled and replicatable database this one just

finds the nearest instance and reads from it makes it fast that's what we

want and then the next thing that we want to do is actually execute this

query so we say query.exec and that's going to return a promise which

will have our heroes in it which we then return as JSON and say that we're gonna

return our heroes and if we have any errors we'll catch those and let's

actually tell you what let's bring this catch down to the next line so it's

easier to read and we'll send an error and if we get one of those then we'll

just first thing we'll do set our service status to 500 which is a server

error and then we will send back the error and then I'm gonna format all this so it

looks nice and pretty there we go that's a lot more readable okay now that we've

got this in here we need to actually be able to call this from our route so

let's go back to our routes file which is index.js so let's take all of this out here we

don't need this anymore and then let's bring in our hero service

And that was from we're gonna have to go up one level and then hero service that should

be where it's at and then we should be able to say hero service dot and there

should be a get and then we're just gonna pass and the request in the

response because we're gonna let the service handle that if you remember

excellent okay so let's start the server if we don't have any errors it should

fire up just excellent and let's go over to our browser and if you recall the

server is running on port 3001 so if we come over here and say API/heroes

we should get back an empty array but we don't we get an error and that's because

we did not export so let's go back to our hero service this is another really

simple mistake that I make all the time I just don't export anything from my

modules so module dot exports equals and then we're just gonna export get for now

and then we'll restart the server head back over to the browser give it a

refresh and now we're getting an empty array so that's coming back I'm gonna

this as big as you can get in an array in chrome but there's no data in there

so that's what we get for now cool so let's define a way for us to put some

data in so that we can get it back out so we'll go back to our hero service and

go to hero service and now we just need to add in a create function so we'll say

create and again we'll pass on the request in the response and then we want

to get the ID the name and the saying from the body of the post request that's

going to come in and we can do that just by saying req body now this is called

destructuring it's new in JavaScript and it basically it's where JavaScript just

looks at req body and if it has an ID a name and a saying in it then it assigns

those values and do variables called ID name and saying so then we can use

them right so I can just use the variable name because it now exists

because it's been destructured from req body that's called these structuring

it's shorthand it's easier than us and manually mapping things

okay so let's create a here a new hero and we'll give it the ID the name and

the saying that came in from the mapping we'll say hero dot save that's gonna

return a promise and then what we'll do is we'll just send back we'll say res

dot JSON the new hero so we're just gonna send back the same thing that was sent

to us kind of like a act did you get it yes I got it here it is back and then

we'll do a catch as usual as per usual with an error which we will do res dot

status is 500 and then we'll send back the air as well there we go

okay we're ready to add this to our route so we can have a route for

creating a new hero so let's go back to our index file and we'll do router dot

and this is gonna be a post okay so it's gonna be a post and then we're not going

to create multiple heroes just one so we'll call the path hero and then that's

gonna give us a req and a res and a next the same as the get and what we'll

do is just a hero service alright dot create because that was the method that

we created and then we're just gonna pass in rec and res there we go and I

did make one mistake here we're not using fat arrows just functions okay

excellent there we are so we've now got a method for creating a hero let's go

ahead and restart the server and let's see if we can get a hero into our

database and now to do that we're gonna use postman postman is a free tool for

testing api's and it's pretty fabulous because when you're building api's you

don't really have a way to test them until you build the user interface

portion of your application which we've done but we haven't wired that up yet so

we can test our API with postman so let's do a new post request and then

we're gonna do 300/API/ hero and then we need to in the body send in

the new hero and I'm gonna send in some raw text here and we'll do an ID is 0

will do the name which was the tick and the saying which was spoon somebody

needs to tell me why that is the tick saying maybe I can just use Google ok

let's change this to JSON because that's what Express is gonna be

expecting us to send in so that's what we'll send it and then let's just click

send and scroll down and look at our body and as usual I did not explore the

create function I told you I do that a lot so let's go back here to our hero

service get and create save that restart the server to try this again in postman

send okay and we got back the hero and noticed that it has the ID that we sent

in and it's got a new ID as well which came from cosmos DB so we know that it

worked and just in case we're in question about that let's go back to our

application refresh of here and now the API is sending back the

tick and if we go back to our react app you can see we're still getting the tick

awesome ok so we're connected to cosmos DB we can read data and we can create

data and in the next video what we're gonna do is we're gonna update and

delete data and test them both of those methods and then we're going to tie all

of that back to the UI I'll see you then

For more infomation >> React & Azure Cosmos DB Part 5 - Cosmos DB Read And Create - Duration: 7:52.

-------------------------------------------

React & Azure Cosmos DB Part 6 - Azure Cosmos DB Delete and Update - Duration: 5:46.

back in our services file let's go ahead and build out the rest of our methods

here so we're gonna need a function for updating so I have an update function

like this and then we're gonna need a function for deleting which I'm going to

call destroy because delete is a reserved keyword in JavaScript so not to

get confused we'll call ours destroy sounds a little overdramatic but we are

destroying a record so we're good to go okay and then just like the others we're

gonna pass in a req here and a res same thing down here right for the delete

req and res and then in our update function what we're gonna do here is

we're gonna destructure like we did up here so I'm actually just gonna pull

this whole thing down so we can get all of these different variables here and

that we want to do is say hero.findOne so we're gonna find one okay and

then what normally what we do here is pass in the name of the field and then

the value that we want to find by but in our case we want to find the ID field

and we want to find it by the ID parameter which we have right here but

again with destructuring we have some shorthand this right here is the

same as typing this and this which is really nice we can just type this but

they're the same thing so we'll do find one and then that will return a promise

so say then and hopefully we'll have a hero in that promise and then we're just

gonna have to hit the heroes we're gonna say the name is equal to the name right

from our d structuring and the saying is equal to saying from the destructuring

and then finally we'll just call save it soul save and that gives us a promise

and in that promise we're just gonna return our hero that we

just updated right just like create that's what we returned you sent me a

hero I created it I'm sending you back the same hero that's how you know that

it's been updated and then we'll catch an error here if we have one and as

usual resident status server error 500 and then sending the air okay excellent

and then we'll reformat looking good all right let's implement the destroy do a

little bit more do structuring here so we're just this time we just need ID and

it's actually gonna come off req params so it's not in the request body it's

actually gonna be part of the URL that's how we're

implement the destroy function here well we'll see how that actually works here

in a second and we're gonna call hero.findOne and remove isn't Mongoose

nice some nice and find it by the ID that's gonna give us a promise which

will containing the hero that we deleted and we're just gonna send that back as

per usual and as per usual right catch it

alright so we've implemented our update and we've implemented our destroy we

just need to add them to the routes let's come back over to the index file

add in our routes so anytime we do an update we're gonna use a put verb so the

put http put verb you can see we're using different verbs here we're using a get a

post now a put alright so we're gonna put and this will be our update our hero

and then function req and res and next and all that good stuff and then down

below that hero service and then dot update and in true burke fashion I

forgot to export from the hero service yet again for the millionth time but at

least I caught it this time before we actually ran it to the error so we'll

put both of those there and then lastly router dot delete which is also an HTTP

verb and hero and remember I said we're gonna pass on the parameter a little bit

differently it's actually any part of the of the route here and this is just a

restful api that we're creating here this is a common pattern for deletes on

restful api so there we go and hero service dot delete

and destroy rather and now it's there we can pass in req and res and we're all

done ok let's fire up the server

and we're up and running and let's go over postman and see if our our new

routes and our new API methods are working all right here in postman what

we want to do is want to change this to a put and over here in our params here

let's see here scroll up we're going to just change

this right so let's update the tick to be Batman so we know that we've

definitely made a change and I'm Batman or even better I could say this all the

time they say where's the bomb okay now we can go ahead and send this and see

whether or not we've actually created a successful put method here in update so

this is our update sending and the response we got back right the ID the

name and the saying again we can go back to our application here and we can just

refresh to make sure that we're actually changing the data and we did right so

this actually pulls from the database so now we're pulling in a new hero here and

let's make sure that delete works so let's do it like this and delete and you

can see that that's all we need to provide because the ID of the here that

we're gonna delete is up here except for our ID is zero it's not one so let's

change this to zero raise started to it right and then we're gonna change this

to a delete over here on this side send look at the response we got back is

the hero that we wanted to delete so we know that it's been deleted go back to

the application refresh alright perfect so now we have create read update and

delete full crud all ready to tie this through to the front end of our

application we're going to do that next

Không có nhận xét nào:

Đăng nhận xét