Skip to content

Commit

Permalink
Deployed c4c7ad1 with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dunossauro committed Feb 4, 2024
1 parent f7e1847 commit 4ccd242
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
13 changes: 9 additions & 4 deletions 03/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1760,14 +1760,19 @@ <h2 id="implementando-a-rota-put">Implementando a Rota PUT</h2>
</span><span id="__span-26-4"><a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a>
</span><span id="__span-26-5"><a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="nd">@app</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="s1">'/users/</span><span class="si">{user_id}</span><span class="s1">'</span><span class="p">,</span> <span class="n">response_model</span><span class="o">=</span><span class="n">UserPublic</span><span class="p">)</span>
</span><span id="__span-26-6"><a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="k">def</span> <span class="nf">update_user</span><span class="p">(</span><span class="n">user_id</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">user</span><span class="p">:</span> <span class="n">UserSchema</span><span class="p">):</span>
</span><span id="__span-26-7"><a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a> <span class="k">if</span> <span class="n">user_id</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">database</span><span class="p">)</span> <span class="ow">or</span> <span class="n">user_id</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
</span><span id="__span-26-8"><a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a> <span class="k">raise</span> <span class="n">HTTPException</span><span class="p">(</span><span class="n">status_code</span><span class="o">=</span><span class="mi">404</span><span class="p">,</span> <span class="n">detail</span><span class="o">=</span><span class="s1">'User not found'</span><span class="p">)</span>
</span><span id="__span-26-7"><a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a> <span class="k">if</span> <span class="n">user_id</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">database</span><span class="p">)</span> <span class="ow">or</span> <span class="n">user_id</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span> <span class="c1">#(1)!</span>
</span><span id="__span-26-8"><a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a> <span class="k">raise</span> <span class="n">HTTPException</span><span class="p">(</span><span class="n">status_code</span><span class="o">=</span><span class="mi">404</span><span class="p">,</span> <span class="n">detail</span><span class="o">=</span><span class="s1">'User not found'</span><span class="p">)</span> <span class="c1">#(2)!</span>
</span><span id="__span-26-9"><a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a>
</span><span id="__span-26-10"><a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a> <span class="n">user_with_id</span> <span class="o">=</span> <span class="n">UserDB</span><span class="p">(</span><span class="o">**</span><span class="n">user</span><span class="o">.</span><span class="n">model_dump</span><span class="p">(),</span> <span class="nb">id</span><span class="o">=</span><span class="n">user_id</span><span class="p">)</span>
</span><span id="__span-26-11"><a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a> <span class="n">database</span><span class="p">[</span><span class="n">user_id</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_with_id</span>
</span><span id="__span-26-11"><a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a> <span class="n">database</span><span class="p">[</span><span class="n">user_id</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_with_id</span> <span class="c1">#(3)!</span>
</span><span id="__span-26-12"><a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a>
</span><span id="__span-26-13"><a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a> <span class="k">return</span> <span class="n">user_with_id</span>
</span></code></pre></div>
<ol>
<li>Aqui fazemos uma validação simples, verificamos se o id não é maior que o tamanho da lista <code class="language-python highlight"><span class="n">user_id</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">database</span><span class="p">)</span></code> e o número enviado para o <code>user)id</code> é um valor positivo <code class="language-python highlight"><span class="n">user_id</span> <span class="o">&lt;</span> <span class="mi">1</span></code>.</li>
<li>Levantamos um erro do tipo <code>HTTPException</code> para dizer que o usuário não existe na base de dados. Esse modelo já está presente no swagger com <code>HTTPValidationError</code>.</li>
<li>Nessa linha estamos substituindo a posição (<code>user_id - 1</code>) na lista pelo novo objeto.</li>
</ol>
<h4 id="implementando-o-teste-da-rota-de-put">Implementando o teste da rota de PUT</h4>
<p>Nosso teste da rota PUT precisa verificar se a atualização de um usuário existente funciona corretamente. Enviamos uma solicitação PUT com as novas informações do usuário para a rota <code>/users/{user_id}</code>. Em seguida, verificamos se a resposta tem o status HTTP 200 (OK) e se a resposta contém o usuário atualizado.</p>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">tests/test_app.py</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-27-39">39</a></span>
Expand Down Expand Up @@ -1911,7 +1916,7 @@ <h2 id="conclusao">Conclusão</h2>
<span class="md-icon" title="Última atualização">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">February 3, 2024</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">February 4, 2024</span>
</span>


Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,72 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://fastapidozero.dunossauro.com/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/01/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/02/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/03/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/04/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/05/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/06/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/07/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/08/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/09/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/10/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/11/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/12/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://fastapidozero.dunossauro.com/13/</loc>
<lastmod>2024-02-03</lastmod>
<lastmod>2024-02-04</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 4ccd242

Please sign in to comment.