Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
fix: validate create raid use case (#97)
Browse files Browse the repository at this point in the history
* Fixes where needed
* Documentation
* Linting and tests
  • Loading branch information
tripledes committed Dec 26, 2019
1 parent cd958a3 commit 12c5cc1
Show file tree
Hide file tree
Showing 38 changed files with 266 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run: clean build
docker-compose up

lint:
pipenv run pycodestyle thesheriff
pipenv run pycodestyle thesheriff tests

tests:
pipenv run pytest
Expand Down
Binary file modified doc/build/doctrees/application.doctree
Binary file not shown.
Binary file modified doc/build/doctrees/domain.doctree
Binary file not shown.
Binary file modified doc/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified doc/build/doctrees/index.doctree
Binary file not shown.
Binary file modified doc/build/doctrees/infrastructure.doctree
Binary file not shown.
Binary file modified doc/build/doctrees/usage.doctree
Binary file not shown.
9 changes: 9 additions & 0 deletions doc/build/html/_sources/usage.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ Validating use cases
-H 'Content-Type: application/json'
{"name": "The best gang", "members": [], "created_raids": 0, "owner_id": 1, "id": 1}
- Create a Raid

.. code-block:: console
$ curl http://localhost:5000/api/v1/raid -X POST \
-H 'Content-Type: application/json' \
--data @examples/json/create_raid.json
{"message":"Raid created successfully","raid":{"id":1,"name":"Asalto 1"}}
- List all Gangs

.. code-block:: console
Expand Down
26 changes: 13 additions & 13 deletions doc/build/html/domain.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h2>Gang<a class="headerlink" href="#gang" title="Permalink to this headline">¶
<dd class="field-odd"><ul class="simple">
<li><p><strong>owner_id</strong> (<em>Integer</em>) – Outlaw’s Id, owner of the new Gang.</p></li>
<li><p><strong>name</strong> (<em>String</em>) – Given name of the Gang.</p></li>
<li><p><strong>id</strong> (<em>Integer</em>) – Optional, Gang Id.</p></li>
</ul>
</dd>
</dl>
Expand Down Expand Up @@ -122,15 +123,14 @@ <h2>Gang<a class="headerlink" href="#gang" title="Permalink to this headline">¶
<h2>Outlaw<a class="headerlink" href="#outlaw" title="Permalink to this headline"></a></h2>
<span class="target" id="module-thesheriff.domain.outlaw.outlaw"><span id="id2"></span></span><dl class="class">
<dt id="thesheriff.domain.outlaw.outlaw.Outlaw">
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.outlaw.outlaw.</code><code class="sig-name descname">Outlaw</code><span class="sig-paren">(</span><em class="sig-param">_id: int</em>, <em class="sig-param">name: str</em>, <em class="sig-param">email: str</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.outlaw.outlaw.</code><code class="sig-name descname">Outlaw</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">email: str</em>, <em class="sig-param">id: Optional[int] = None</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="Permalink to this definition"></a></dt>
<dd><p>Class Outlaw represents the Outlaw domain entity.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>id</strong> (<em>Integer</em>) – Optional, Outlaw Id.</p></li>
<li><p><strong>name</strong> (<em>String</em>) – Outlaw’s given name.</p></li>
<li><p><strong>email</strong> (<em>String</em>) – Outlaw’s email address.</p></li>
<li><p><strong>score</strong> (<em>Integer</em>) – Optional, Outlaw’s general score.</p></li>
</ul>
</dd>
</dl>
Expand All @@ -155,11 +155,11 @@ <h2>Outlaw<a class="headerlink" href="#outlaw" title="Permalink to this headline

<span class="target" id="module-thesheriff.domain.outlaw.outlaw_factory"><span id="outlaw-factory"></span></span><dl class="class">
<dt id="thesheriff.domain.outlaw.outlaw_factory.OutlawFactory">
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.outlaw.outlaw_factory.</code><code class="sig-name descname">OutlawFactory</code><span class="sig-paren">(</span><em class="sig-param">_id: int</em>, <em class="sig-param">name: str</em>, <em class="sig-param">email: str</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.outlaw.outlaw_factory.OutlawFactory" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.outlaw.outlaw_factory.</code><code class="sig-name descname">OutlawFactory</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">email: str</em>, <em class="sig-param">id: Optional[int] = None</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.outlaw.outlaw_factory.OutlawFactory" title="Permalink to this definition"></a></dt>
<dd><p>Class OutlawFactory produces Outlaws.</p>
<dl class="method">
<dt id="thesheriff.domain.outlaw.outlaw_factory.OutlawFactory.create">
<em class="property">static </em><code class="sig-name descname">create</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">email: str</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.outlaw.outlaw.Outlaw<a class="headerlink" href="#thesheriff.domain.outlaw.outlaw_factory.OutlawFactory.create" title="Permalink to this definition"></a></dt>
<em class="property">static </em><code class="sig-name descname">create</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">email: str</em>, <em class="sig-param">id: Optional[int] = None</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.outlaw.outlaw.Outlaw<a class="headerlink" href="#thesheriff.domain.outlaw.outlaw_factory.OutlawFactory.create" title="Permalink to this definition"></a></dt>
<dd><p>Method create, produces a Outlaw instance.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
Expand Down Expand Up @@ -191,18 +191,18 @@ <h2>Outlaw<a class="headerlink" href="#outlaw" title="Permalink to this headline
<h2>Raid<a class="headerlink" href="#raid" title="Permalink to this headline"></a></h2>
<span class="target" id="module-thesheriff.domain.raid.raid"><span id="id3"></span></span><dl class="class">
<dt id="thesheriff.domain.raid.raid.Raid">
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.raid.raid.</code><code class="sig-name descname">Raid</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">location: str</em>, <em class="sig-param">sheriff: thesheriff.domain.outlaw.sheriff.Sheriff</em>, <em class="sig-param">gang: thesheriff.domain.gang.gang.Gang</em>, <em class="sig-param">date: datetime.datetime</em>, <em class="sig-param">raid_id: Optional[int] = None</em>, <em class="sig-param">outlaws: Optional[thesheriff.domain.outlaw.outlaw.Outlaw] = []</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.raid.raid.Raid" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.raid.raid.</code><code class="sig-name descname">Raid</code><span class="sig-paren">(</span><em class="sig-param">name: str, members: List[thesheriff.domain.outlaw.outlaw.Outlaw], sheriff: thesheriff.domain.outlaw.sheriff.Sheriff, gang: thesheriff.domain.gang.gang.Gang, location: str, date: datetime.datetime, id: Optional[int] = None</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.raid.raid.Raid" title="Permalink to this definition"></a></dt>
<dd><p>Class Raid represents the Raid entity.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> (<em>String</em>) – The Raid given name.</p></li>
<li><p><strong>outlaws</strong> (<em>List</em><em>[</em><a class="reference internal" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw"><em>Outlaw</em></a><em>]</em>) – List of Outlaws invited to the Raid.</p></li>
<li><p><strong>location</strong> (<em>String</em>) – Restaurant location.</p></li>
<li><p><strong>members</strong> (<em>List</em><em>[</em><a class="reference internal" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw"><em>Outlaw</em></a><em>]</em>) – List of Outlaws invited to the Raid.</p></li>
<li><p><strong>sheriff</strong> (<em>Sheriff</em>) – The Raid organizer.</p></li>
<li><p><strong>gang</strong> (<a class="reference internal" href="#thesheriff.domain.gang.gang.Gang" title="thesheriff.domain.gang.gang.Gang"><em>Gang</em></a>) – Gang where the raid is organized.</p></li>
<li><p><strong>location</strong> (<em>String</em>) – Restaurant location.</p></li>
<li><p><strong>date</strong> (<em>datetime.datetime</em>) – Date and time when the raid happens.</p></li>
<li><p><strong>raid_id</strong> (<em>Integer</em>) – Optional, Raid Id.</p></li>
<li><p><strong>id</strong> (<em>Integer</em>) – Optional, Raid Id.</p></li>
</ul>
</dd>
</dl>
Expand Down Expand Up @@ -258,22 +258,22 @@ <h2>Raid<a class="headerlink" href="#raid" title="Permalink to this headline">¶

<span class="target" id="module-thesheriff.domain.raid.raid_factory"><span id="raid-factory"></span></span><dl class="class">
<dt id="thesheriff.domain.raid.raid_factory.RaidFactory">
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.raid.raid_factory.</code><code class="sig-name descname">RaidFactory</code><span class="sig-paren">(</span><em class="sig-param">name: str</em>, <em class="sig-param">location: str</em>, <em class="sig-param">sheriff: thesheriff.domain.outlaw.sheriff.Sheriff</em>, <em class="sig-param">gang: thesheriff.domain.gang.gang.Gang</em>, <em class="sig-param">date: datetime.datetime</em>, <em class="sig-param">raid_id: Optional[int] = None</em>, <em class="sig-param">outlaws: Optional[thesheriff.domain.outlaw.outlaw.Outlaw] = []</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.raid.raid_factory.RaidFactory" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">thesheriff.domain.raid.raid_factory.</code><code class="sig-name descname">RaidFactory</code><span class="sig-paren">(</span><em class="sig-param">name: str, members: List[thesheriff.domain.outlaw.outlaw.Outlaw], sheriff: thesheriff.domain.outlaw.sheriff.Sheriff, gang: thesheriff.domain.gang.gang.Gang, location: str, date: datetime.datetime, id: Optional[int] = None</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.domain.raid.raid_factory.RaidFactory" title="Permalink to this definition"></a></dt>
<dd><p>Class RaidFactory produces Raids.</p>
<dl class="method">
<dt id="thesheriff.domain.raid.raid_factory.RaidFactory.create">
<em class="property">static </em><code class="sig-name descname">create</code><span class="sig-paren">(</span><em class="sig-param">id: Optional[int], name: str, outlaws: List[thesheriff.domain.outlaw.outlaw.Outlaw], sheriff: thesheriff.domain.outlaw.sheriff.Sheriff, gang: thesheriff.domain.gang.gang.Gang, location: str, date: datetime.datetime</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.raid.raid.Raid<a class="headerlink" href="#thesheriff.domain.raid.raid_factory.RaidFactory.create" title="Permalink to this definition"></a></dt>
<em class="property">static </em><code class="sig-name descname">create</code><span class="sig-paren">(</span><em class="sig-param">name: str, members: List[thesheriff.domain.outlaw.outlaw.Outlaw], sheriff: thesheriff.domain.outlaw.sheriff.Sheriff, gang: thesheriff.domain.gang.gang.Gang, location: str, date: datetime.datetime, id: Optional[int] = None</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.raid.raid.Raid<a class="headerlink" href="#thesheriff.domain.raid.raid_factory.RaidFactory.create" title="Permalink to this definition"></a></dt>
<dd><p>Method create, produces a Raid instance.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>id</strong> (<em>Integer</em>) – Optional, Raid’s Id.</p></li>
<li><p><strong>name</strong> (<em>String</em>) – Outlaw’s given name.</p></li>
<li><p><strong>outlaws</strong> (<em>List</em><em>[</em><a class="reference internal" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw"><em>Outlaw</em></a><em>]</em>) – Outlaws invited to raid.</p></li>
<li><p><strong>location</strong> (<em>String</em>) – Location of the raid.</p></li>
<li><p><strong>members</strong> (<em>List</em><em>[</em><a class="reference internal" href="#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw"><em>Outlaw</em></a><em>]</em>) – Outlaws invited to raid.</p></li>
<li><p><strong>sheriff</strong> (<em>Sheriff</em>) – The Outlaw organizing the Raid.</p></li>
<li><p><strong>gang</strong> (<a class="reference internal" href="#thesheriff.domain.gang.gang.Gang" title="thesheriff.domain.gang.gang.Gang"><em>Gang</em></a>) – Gang this Raid is organized for.</p></li>
<li><p><strong>location</strong> (<em>String</em>) – Location of the raid.</p></li>
<li><p><strong>date</strong> (<em>datetime.datetime</em>) – Raid’s date and time.</p></li>
<li><p><strong>id</strong> (<em>Integer</em>) – Optional, Raid’s Id.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
Expand Down
4 changes: 4 additions & 0 deletions doc/build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ <h2 id="A">A</h2>
<li><a href="domain.html#thesheriff.domain.raid.raid.Raid.add_rate">add_rate() (thesheriff.domain.raid.raid.Raid method)</a>
</li>
<li><a href="infrastructure.html#thesheriff.infrastructure.repository.mysql_gang_repository.MySQLGangRepository.all">all() (thesheriff.infrastructure.repository.mysql_gang_repository.MySQLGangRepository method)</a>

<ul>
<li><a href="infrastructure.html#thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.all">(thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository method)</a>
</li>
</ul></li>
</ul></td>
</tr></table>

Expand Down
38 changes: 30 additions & 8 deletions doc/build/html/infrastructure.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ <h2>Repositories<a class="headerlink" href="#repositories" title="Permalink to t
<dd><p>MySQLGangRepository implements persistence for Gang on MySQL.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>database_uri</strong> (<em>String</em>) – URI for connecting to MySQL.</p>
<dd class="field-odd"><ul class="simple">
<li><p><strong>database_uri</strong> (<em>String</em>) – URI for connecting to MySQL.</p></li>
<li><p><strong>meta</strong> (<em>sqlalchemy.MetaData</em>) – MetaData object shared across all MySQL repositories.</p></li>
<li><p><strong>gang_table</strong> (<em>sqlalchemy.Table</em>) – Table object, represents the Gangs table in MySQL.</p></li>
</ul>
</dd>
</dl>
<dl class="method">
Expand Down Expand Up @@ -357,12 +361,16 @@ <h2>Repositories<a class="headerlink" href="#repositories" title="Permalink to t
<dd><p>MySQLOutlawRepository implements persistence for Outlaw on MySQL.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>database_uri</strong> (<em>String</em>) – URI for connecting to MySQL</p>
<dd class="field-odd"><ul class="simple">
<li><p><strong>database_uri</strong> (<em>String</em>) – URI for connecting to MySQL</p></li>
<li><p><strong>meta</strong> (<em>sqlalchemy.MetaData</em>) – MetaData object shared across all MySQL repositories.</p></li>
<li><p><strong>outlaw_table</strong> (<em>sqlalchemy.Table</em>) – Table object, represents the Outlaw table in MySQL.</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.add">
<code class="sig-name descname">add</code><span class="sig-paren">(</span><em class="sig-param">new_outlaw: thesheriff.domain.outlaw.outlaw.Outlaw</em><span class="sig-paren">)</span> &#x2192; NoReturn<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.add" title="Permalink to this definition"></a></dt>
<code class="sig-name descname">add</code><span class="sig-paren">(</span><em class="sig-param">new_outlaw: thesheriff.domain.outlaw.outlaw.Outlaw</em><span class="sig-paren">)</span> &#x2192; int<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.add" title="Permalink to this definition"></a></dt>
<dd><p>Method add persists a new Outlaw to MySQL.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
Expand All @@ -377,6 +385,20 @@ <h2>Repositories<a class="headerlink" href="#repositories" title="Permalink to t
</dl>
</dd></dl>

<dl class="method">
<dt id="thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.all">
<code class="sig-name descname">all</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; List[thesheriff.domain.outlaw.outlaw.Outlaw]<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.all" title="Permalink to this definition"></a></dt>
<dd><p>all returns all Outlaws stored on MySQL.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>List Outlaw objects.</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>List[<a class="reference internal" href="domain.html#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw">Outlaw</a>]</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.get_friends">
<code class="sig-name descname">get_friends</code><span class="sig-paren">(</span><em class="sig-param">outlaw_id: int</em><span class="sig-paren">)</span> &#x2192; List[thesheriff.domain.outlaw.outlaw.Outlaw]<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_outlaw_repository.MySQLOutlawRepository.get_friends" title="Permalink to this definition"></a></dt>
Expand Down Expand Up @@ -458,17 +480,17 @@ <h2>Repositories<a class="headerlink" href="#repositories" title="Permalink to t
</dl>
<dl class="method">
<dt id="thesheriff.infrastructure.repository.mysql_raid_repository.MySQLRaidRepository.add">
<code class="sig-name descname">add</code><span class="sig-paren">(</span><em class="sig-param">new_raid: thesheriff.domain.raid.raid.Raid</em><span class="sig-paren">)</span> &#x2192; NoReturn<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_raid_repository.MySQLRaidRepository.add" title="Permalink to this definition"></a></dt>
<dd><p>Method add persists a new Outlaw to MySQL.</p>
<code class="sig-name descname">add</code><span class="sig-paren">(</span><em class="sig-param">new_raid: thesheriff.domain.raid.raid.Raid</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.raid.raid.Raid<a class="headerlink" href="#thesheriff.infrastructure.repository.mysql_raid_repository.MySQLRaidRepository.add" title="Permalink to this definition"></a></dt>
<dd><p>Method add persists a new Raid to MySQL.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>new_outlaw</strong> (<a class="reference internal" href="domain.html#thesheriff.domain.outlaw.outlaw.Outlaw" title="thesheriff.domain.outlaw.outlaw.Outlaw"><em>Outlaw</em></a>) – Object with the Outlaw information.</p>
<dd class="field-odd"><p><strong>new_raid</strong> (<a class="reference internal" href="domain.html#thesheriff.domain.raid.raid.Raid" title="thesheriff.domain.raid.raid.Raid"><em>Raid</em></a>) – Object with the Raid information.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>No returned value.</p>
<dd class="field-even"><p>The inserted Raid with informed id attribute.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>NoReturn</p>
<dd class="field-odd"><p><a class="reference internal" href="domain.html#thesheriff.domain.raid.raid.Raid" title="thesheriff.domain.raid.raid.Raid">Raid</a></p>
</dd>
</dl>
</dd></dl>
Expand Down
Binary file modified doc/build/html/objects.inv
Binary file not shown.

0 comments on commit 12c5cc1

Please sign in to comment.