<?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>DEV Community: Cristian Muñoz</title>
    <description>The latest articles on DEV Community by Cristian Muñoz (@arjeldev).</description>
    <link>https://dev.to/arjeldev</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%2F804037%2F6f7fe6c1-f238-457f-9a6a-5c3c0d64b53d.jpeg</url>
      <title>DEV Community: Cristian Muñoz</title>
      <link>https://dev.to/arjeldev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arjeldev"/>
    <language>en</language>
    <item>
      <title>Astro with hygraph</title>
      <dc:creator>Cristian Muñoz</dc:creator>
      <pubDate>Fri, 28 Jul 2023 23:05:46 +0000</pubDate>
      <link>https://dev.to/arjeldev/astro-with-hygraph-35ef</link>
      <guid>https://dev.to/arjeldev/astro-with-hygraph-35ef</guid>
      <description>&lt;h1&gt;
  
  
  How to integrate Hygraph CMS with Astro and Netlify?
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;First, create your proyect with the command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create astro@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go trough the installation process&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create your account in Hygraph and create a project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to your project dashboard in Hygraph, and select "Proyect settings"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can grab &amp;gt;&amp;gt;&lt;br&gt;
The Content API or the High Performance Read-only Content API for data visualization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then you need to add permision for this API to be accesible. Click on the "Add Permission" button on the Public Content API section. In this case we will use the Read permission.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create your data schema on hygraph. In my case i would create a blogPost with a title, a slug and content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a blog entry and complete the fields. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I created the title of a Single Line Text, the slug of Type URL and the content of Multi Line text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You could use Marked and some tailwindcss/ypography for styling the Markdown content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In astro, save your &lt;code&gt;HYGRAPH_ENDPOINT&lt;/code&gt; in a .env file on the project root. Then you could call this key with &lt;code&gt;import.meta.env.HYGRAPH_ENDPOINT&lt;/code&gt; in any of your files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For quering the blogPost data you could import into your index page like this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
      {
        blogPosts {
          id
          title
          slug
          content {
            markdown
          }
        }
      }`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;HYGRAPH_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code provided before can be on its own function or in the Astro &lt;code&gt;frontmatter&lt;/code&gt;. You should see the log of the posts on the server console. If not, then be sure to have published your blog post.&lt;/p&gt;

&lt;p&gt;And there is, you could find this working in this &lt;a href="https://github.com/camunoz2/example-astrowithhygraph"&gt;github repo&lt;/a&gt;.&lt;br&gt;
It has marked for parsing markdown content!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;See ya astronauts!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>astro</category>
      <category>hygraph</category>
      <category>api</category>
    </item>
    <item>
      <title>Mastering Go Web Development: Building a Flashcard App</title>
      <dc:creator>Cristian Muñoz</dc:creator>
      <pubDate>Sun, 23 Jul 2023 17:54:47 +0000</pubDate>
      <link>https://dev.to/arjeldev/mastering-go-web-development-building-a-flashcard-app-1kjf</link>
      <guid>https://dev.to/arjeldev/mastering-go-web-development-building-a-flashcard-app-1kjf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This project will provide valuable insights into Go's web development capabilities and best practices, whether you're a beginner or an experienced developer.&lt;/p&gt;

&lt;p&gt;By the end of this series, you'll have a solid foundation in Go web development and be equipped to create your own web applications&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Installation
&lt;/h3&gt;

&lt;p&gt;First we must install go for your operating system of choice. Im using wsl on windows and have no problem following the &lt;a href="https://go.dev/doc/install"&gt;official docs instructions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are gonna asume that you are using a go version &amp;gt; 1.16, so modules are enabled by default &lt;a href="https://go.dev/blog/go116-module-changes"&gt;(ref.)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: If you wanna understand the difference between modules and the legacy GOPATH, read &lt;a href="https://www.freecodecamp.org/news/golang-environment-gopath-vs-go-mod/"&gt;this&lt;/a&gt;&lt;/em&gt; great article&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Setting up the project.
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Note: I'm following the convention from &lt;a href="https://github.com/golang-standards/project-layout"&gt;this&lt;/a&gt; repository for the project structure.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2.1 Create the folder an initialize the project
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir flashcard-go
cd flashcard-go
go mod init github.com/&amp;lt;your_username&amp;gt;/flashcard-go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should have created a &lt;code&gt;go.mod&lt;/code&gt; file. This file has the name of the module and the go version. A module is identified by a &lt;u&gt;module path&lt;/u&gt;, which is declared in a go.mod file, together with information about the module’s dependencies. Typically, a module path consists of a repository root path, a directory within the repository (usually empty), and a major version suffix (only for major version 2 or higher)&lt;a href="https://go.dev/ref/mod#module-path"&gt;(ref.)&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2.2 Software architecture of the project
&lt;/h4&gt;

&lt;p&gt;There exist a numerous software architecture and patterns, model-view-controller (MVC), client-server, microservices, layered, hexagonal (Ports and Adapters), and various others. In our case i'm choosing a hexagonal approach. It is overkill, it is not neccesary, its impractical for our little project, but it is widely used and we can learn a lot from it.&lt;/p&gt;

&lt;p&gt;Our entry points are gonna be inside a cmd folder. Here we can have multiple entry points (for example separate the webapp from the cli) and you could keep everyone on its own folder (for testing purposes). The contents of the files inside this cmd should not be used by other parts of the webapp.&lt;/p&gt;

&lt;p&gt;The first thing we are gonna do is separate the core from our source code. As of Go 1.4 the go command introduces a mechanism to define "internal" packages that may not be imported by packages outside the source subtree in which they reside. To create such a package, place it in a directory named internal or in a subdirectory of a directory named internal &lt;a href="https://go.dev/doc/go1.4#internalpackages"&gt;(ref.)&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flashcard-app/
├─ cmd/
│  ├─ web/
│  │  ├─ // Main entry point
│  ├─ cli/
│  │  ├─ // Possibly another entry point
├─ internal/
│  ├─ // Business Logic
├─ site/
│  ├─ // Front End

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Defining the business.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Purpose of the App
&lt;/h4&gt;

&lt;p&gt;This webapp is gonna help users create quizzes using flashcards. Users can create, view, edit, and delete flashcards and quizzes. The primary goal is to provide a simple and intuitive interface for users to create educational quizzes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Identify Core Business Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Flashcard: An individual card used for learning. Each flashcard contains a question and its corresponding answer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quiz: A collection of multiple flashcards organized to test a user's knowledge on specific topics. A quiz should have a title, description, and a set of flashcards.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Model Business Rules and Relationships
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Flashcard must have a non-empty question and answer.&lt;/li&gt;
&lt;li&gt;Flashcards are associated with quizzes (many-to-one relationship), meaning multiple flashcards can belong to the same quiz.&lt;/li&gt;
&lt;li&gt;A Quiz must have a non-empty title.&lt;/li&gt;
&lt;li&gt;A Quiz must have a non-empty description.&lt;/li&gt;
&lt;li&gt;A Quiz can have zero or more flashcards associated with it (one-to-many relationship).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Entities
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Flashcard&lt;/li&gt;
&lt;li&gt;Quiz&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Use cases
&lt;/h4&gt;

&lt;p&gt;We are gonna make this thing simple and add these posible uses cases&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating, editing and deleting Flashcards&lt;/li&gt;
&lt;li&gt;Creating, editing and deleting a Quiz&lt;/li&gt;
&lt;li&gt;Taking a Quiz: Users can take a quiz, and the application will present each flashcard's question one by one, allowing users to answer&lt;/li&gt;
&lt;li&gt;Scoring a Quiz: After answering all the flashcards in a quiz, the application will calculate and display the user's score&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Start Coding
&lt;/h3&gt;

&lt;p&gt;With the foundation set, we lets begin our coding journey in our next blog post. &lt;/p&gt;

&lt;p&gt;Stay tuned as we delve into implementing the Hexagonal Architecture, organizing the project structure, and bringing our "Flashcard Quiz App" to life using the Go programming language!&lt;/p&gt;

</description>
      <category>go</category>
      <category>ddd</category>
      <category>hexagonal</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
