<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jss475</title>
    <description>The latest articles on Forem by jss475 (@jss475).</description>
    <link>https://forem.com/jss475</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F859990%2F3423e133-1174-4861-a845-10f57b356507.png</url>
      <title>Forem: jss475</title>
      <link>https://forem.com/jss475</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jss475"/>
    <language>en</language>
    <item>
      <title>Creating Seed Data in AWS Amplify/Studio</title>
      <dc:creator>jss475</dc:creator>
      <pubDate>Mon, 24 Oct 2022 21:53:23 +0000</pubDate>
      <link>https://forem.com/jss475/creating-seed-data-in-aws-amplifystudio-2ndb</link>
      <guid>https://forem.com/jss475/creating-seed-data-in-aws-amplifystudio-2ndb</guid>
      <description>&lt;p&gt;Hey everyone!&lt;/p&gt;

&lt;p&gt;I just started trying to use AWS Amplify to deploy one of my old projects and boy did I have some trouble haha.&lt;/p&gt;

&lt;p&gt;AWS Amplify uses GraphQL or allows use to use a REST API. I wanted to learn more about GraphQL so I went with that route for my personal project. Understanding the basic concepts of GraphQL were not too difficult and luckily AWS has plenty of documentation to help with that as well. Here's a link to one of the documentation that helped me a lot: &lt;a href="https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/js/"&gt;https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/js/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you set up your project and your backend, you may want to have some seed data. For my project specifically, I wanted to add in restaurants for my "Food Journal" project. A nice visual way to set that up is by using Amplify Studio. With your backend schema already set up, you can go to the page below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dwXr_ASe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6ksb97xrkk1upjqoirj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dwXr_ASe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6ksb97xrkk1upjqoirj.png" alt="AWS Amplify Backend Environment" width="880" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you're at the backend environment, click "Actions" and then "Launch Studio." This should take you the following page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--68iMqDz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im1g00mb8nnb67yolb43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--68iMqDz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im1g00mb8nnb67yolb43.png" alt="AWS Amplify Studio" width="880" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to the "Content" link under "Manage" in the sidebar on the left.&lt;/p&gt;

&lt;p&gt;Once there, you can click on "Action" to "Auto Generate Data" (when you want to seed more than one instance with fake data) or click "Create (table name)".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K14HXPhe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4czdvycnpkdyrsawmim6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K14HXPhe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4czdvycnpkdyrsawmim6.png" alt="Seed your data!" width="880" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should now be able to seed your data!&lt;/p&gt;

&lt;p&gt;Hope this helped!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Google Maps with React</title>
      <dc:creator>jss475</dc:creator>
      <pubDate>Tue, 12 Jul 2022 02:41:47 +0000</pubDate>
      <link>https://forem.com/jss475/google-maps-with-react-4n1o</link>
      <guid>https://forem.com/jss475/google-maps-with-react-4n1o</guid>
      <description>&lt;p&gt;Today I'll be showing you how I used Google Maps with react to create a dynamic map on a webpage.&lt;/p&gt;

&lt;p&gt;The first thing you need to do is install this package:&lt;br&gt;
&lt;code&gt;npm i @react-google-maps/api&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;More information on this can be found here: &lt;a href="https://www.npmjs.com/package/@react-google-maps/api"&gt;https://www.npmjs.com/package/@react-google-maps/api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes you may have to end --legacy-peer-deps at the end of npm install. You can read more about that on google/stackoverflow. &lt;/p&gt;

&lt;p&gt;Once you've installed the package:&lt;br&gt;
Let's say I'm in my React component&lt;/p&gt;

&lt;p&gt;I'm going to first import the below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import {GoogleMap, useLoadScript, Marker} from "@react-google-maps/api"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, I will need the following code&lt;br&gt;
&lt;code&gt;const {isLoaded} = useLoadScript({googleMapsApiKey: process.env.REACT_APP_NEXT_PUBLIC_GOOGLE_MAPS_API_KEY})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What this piece of code here is we use the useLoadScript hook to load in our Google Maps API key. Once that's loaded, isLoaded is a truthy value. You can read more about how to create a Google Maps API key on Google's official documentation. The process.env portion here is referencing a .env.local file that has REACT_APP_NEXT_PUBLIC_GOOGLE_MAPS_API_KEY = YOUR_API_KEY. The reason we do this is to ensure our API key is hidden. Just make sure you don't push the .env.local file to Github!!!!&lt;/p&gt;

&lt;p&gt;The next piece of code is where we make the map itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//creating the google map
    //here i'm just initializing a variable called map that will hold the Google Map instance
    let map
    //if our useLoadScript hasn't completed, return "Loading..."
    if(!isLoaded){
        map = &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;
    //if it is loaded, create the map
    }else{
        map = &amp;lt;GoogleMap zoom={13} center={{lat: YOUR_LATITUDE, lng: YOUR_LONGITUDE}} mapContainerClassName="map-container"&amp;gt;

            &amp;lt;Marker position={{lat: YOUR_LATITUDE, lng: YOUR_LONGITUDE}} label="SL"  /&amp;gt;
        &amp;lt;/GoogleMap&amp;gt;
    }

return (
     &amp;lt;&amp;gt;
          {map}
     &amp;lt;/&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The zoom on GoogleMap is just how far zoomed you are in on the map when it renders on the webpage. You can experiment with what you like! The center takes in a lat, lng of where you want the center of your map to be. I also added a marker on the map at the center location here!&lt;/p&gt;

&lt;p&gt;Below is what you should see!&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--naDy5GMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nu82wukzlqac1n6e7fac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--naDy5GMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nu82wukzlqac1n6e7fac.png" alt="Image description" width="880" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Creating Custom Methods in Rails</title>
      <dc:creator>jss475</dc:creator>
      <pubDate>Tue, 12 Jul 2022 02:13:22 +0000</pubDate>
      <link>https://forem.com/jss475/creating-custom-methods-in-rails-3lb2</link>
      <guid>https://forem.com/jss475/creating-custom-methods-in-rails-3lb2</guid>
      <description>&lt;p&gt;I wanted to cover making custom methods in rails today. Rails is quite the powerful tool and can accomplish a lot of the actions you may want to do on the front end.&lt;/p&gt;

&lt;p&gt;Let's go over an example that I've worked on:&lt;/p&gt;

&lt;p&gt;I have three tables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User&lt;/li&gt;
&lt;li&gt;Restaurant&lt;/li&gt;
&lt;li&gt;UserRestaurant - the joiner table for User and restaurant&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The UserRestaurant table belongs to both the user and restaurant. It also holds the following information:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;upvoted? (boolean)&lt;/li&gt;
&lt;li&gt;downvoted? (boolean)&lt;/li&gt;
&lt;li&gt;Review (string)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, when a user leaves an upvote, downvote and/or review on a restaurant it's handled by the UserRestaurant table.&lt;/p&gt;

&lt;p&gt;Now, when a user upvotes a restaurant, a UserRestaurant instance is created and the upvoted? attribute is set to true on the backend. However, what happens when this same user wants to leave a review on the same restaurant? You have to first find the original instance and then update it. You can do this on the frontend by using filters and what not or you can accomplish the same on the backend. Or what if the user leaves a review first and then upvotes? You'll have to create a UserRestaurant instance with a review and then update the upvoted? attribute.&lt;/p&gt;

&lt;p&gt;This is where creating a custom method can help.&lt;/p&gt;

&lt;p&gt;Here's a bit of code I wrote to accomplish let's say making an upvote first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_update
        # I'm just taking the params that were sent with the post request here and setting them with different variable names 
        #ur_params here permit the following attributes: user_id, restaurant_id, upvoted?, downvoted?, and review
        user_id =ur_params[:user_id]
        restaurant_id = ur_params[:restaurant_id]

        # I then check to see if this instance exists
        ur_found = UserRestaurant.find_by user_id: user_id, restaurant_id: restaurant_id

        # If the UserRestaurant exists for this specific pair, just update it
        if ur_found
            ur_instance = ur_w_all
            ur_instance.update(ur_params)
        # If the UserRestaurant doesn't exist, create it!
        else
            ur_instance = UserRestaurant.create(ur_params)
        end
        render json: ur_instance, status: :created
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using this custom method, it can handle both an update and create when necessary!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Phase 3 - GET requesting Multiple Pieces of Data</title>
      <dc:creator>jss475</dc:creator>
      <pubDate>Wed, 08 Jun 2022 00:30:42 +0000</pubDate>
      <link>https://forem.com/jss475/phase-3-get-requesting-multiple-pieces-of-data-3509</link>
      <guid>https://forem.com/jss475/phase-3-get-requesting-multiple-pieces-of-data-3509</guid>
      <description>&lt;p&gt;While working on one of my projects recently, I wanted a way to use a GET request to send more than just one piece of data from my database. For example, I have a GET request for a specific product (i.e iPhone) and I wanted to have the information for the product and the seller sent to my frontend. &lt;/p&gt;

&lt;p&gt;I had learned in my bootcamp, that you typically just send the information of the product when doing a GET request without any other information. However, while working on the frontend portion of my project, I found it annoying to use .filter methods all the time, or .group and .join methods, to find out who the seller of the product was. It got me thinking because using ruby, you can easily find the seller of a specific product as long as they have a one to many relationship or many to many relationship. &lt;/p&gt;

&lt;p&gt;I wanted to leverage that capability and send this information back to my frontend. I had figured out that you can do this by literally just adding a comma between the two pieces of data you want to send back. I'm posting an example of my application controller below to illustrate what I'm talking about&lt;/p&gt;

&lt;p&gt;&lt;code&gt;get '/products/:id' do&lt;br&gt;
        prod = Product.find(params[:id])&lt;br&gt;
        seller_of_prod = prod.seller&lt;br&gt;
        combo = prod, seller_of_prod&lt;br&gt;
        combo.to_json&lt;br&gt;
    end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This piece of code allows you to get information about the product while also getting the seller at the same time. The resulting combo here is a json formatted object with the product and seller. Hope this helps!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
      <category>programming</category>
    </item>
    <item>
      <title>Phase 2 of Flatiron</title>
      <dc:creator>jss475</dc:creator>
      <pubDate>Mon, 09 May 2022 17:15:12 +0000</pubDate>
      <link>https://forem.com/jss475/phase-2-of-flatiron-4dkm</link>
      <guid>https://forem.com/jss475/phase-2-of-flatiron-4dkm</guid>
      <description>&lt;p&gt;React has been quite the journey. It started out with lots of frustrations after dealing with only vanilla Javascript. However, I can see now why React is such a powerful framework/library. The use of components is quite elegant and it has definitely made my code a lot cleaner. I'm currently trying to use React to make a website where you can like restaurants near you, order from said restaurant, and save the items that you ordered. You can then go back to the items and like/dislike them to keep a record of your food journey. I always forget what I got at a restaurant unless I order from them all the time, so this will be cool to do. Ideally, this would be synced up to the restaurant side of things such that your order information is automatically added to our database if you eat in person. Maybe you can even take a picture of your receipt and it's added in that way. Right now, I don't have the ability to do the back-end work necessary to make this happen. I'm just focusing on the front-end portion of how this website would work with my partner Hyun currently.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
  </channel>
</rss>
