The Sheriff Infrastructure¶
This part of the documentation covers all interfaces on thesheriff.infrastructure package.
Controllers¶
thesheriff.infrastructure.controllers.gang_controller¶
This module implements the RESTful part of the Gang use cases.
-
thesheriff.infrastructure.controllers.gang_controller.
gang_controller
(join_gang: thesheriff.application.outlaw.join_gang.JoinGang, create_gang: thesheriff.application.outlaw.create_gang.CreateGang, list_gangs: thesheriff.application.gang.list_gangs.ListGangs) → flask.blueprints.Blueprint¶ gang_controller holds the blueprint for all gang routes.
- Parameters
join_gang (JoinGang) – Join Gang use case implementation.
create_gang (CreateGang) – Create Gang use case implementation.
list_gangs (ListGangs) – List Gangs use case implementation.
- Returns
Flask Blueprint.
- Return type
Blueprint
Implements the following routes:
/<prefix>/gang (GET)
Request Example:
$ curl localhost:5000/api/<version>/gang
Response Example:
{ "message": "Success", "gangs": { "gang1": {}, "gang2": {} } }
/<prefix>/gang (POST)
Request Example:
$ curl localhost:5000/api/<version>/gang \ -X POST --data @examples/json/create_gang.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Gang successfully created", "gang": {} }
/<prefix>/gang/<int:gang_id>/join (PUT)
Request Example:
$ curl localhost:5000/api/<version>/gang/1/join \ -X PUT --data @examples/json/join_gang.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Joined Gang successfully" }
thesheriff.infrastructure.controllers.outlaw_controller¶
This module implements the RESTful part of the Outlaw use cases.
-
thesheriff.infrastructure.controllers.outlaw_controller.
outlaw_controller
(create_outlaw: thesheriff.application.outlaw.create_outlaw.CreateOutlaw, list_friends: thesheriff.application.outlaw.list_friends.ListFriends, list_gangs: thesheriff.application.outlaw.list_gangs.ListGangs, invite_friend: thesheriff.application.outlaw.invite_friend.InviteFriend) → flask.blueprints.Blueprint¶ outlaw_controller holds the blueprint for all outlaw routes.
- Parameters
create_outlaw (CreateOutlaw) – Create Outlaw use case implementation.
list_friends (ListFriends) – List Friends use case implementation.
list_gangs (ListGangs) – List Gangs use case implementation.
invite_friend (InviteFriend) – InviteFiend use case implementation.
- Returns
Flask Blueprint.
- Return type
Blueprint
Implements the following routes:
/<prefix>/outlaw/ (POST)
Request Example:
$ curl localhost:5000/api/<version>/outlaw/ \ -X POST --data @examples/json/create_outlaw.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Outlaw created successfully", "outlaw": { "id": 1, "name": "outlaw 1", "email": "outlaw1@domain.net" } }
/<prefix>/outlaw/<int:outlaw_id>/friends (GET)
Request Example:
$ curl localhost:5000/api/<version>/outlaw/1/friends
Response Example:
{ "message": "Success", "friends": [ { "id": 1, "name": "Outlaw1", "email": "outlaw1@domain.net" }, { "id": 2, "name": "Outlaw2", "email": "outlaw2@domain.net" } ] }
/<prefix>/outlaw/<int:outlaw_id>/gangs (GET)
Request Example:
$ curl localhost:5000/api/<version>/outlaw/1/gangs
Response Example:
{ "message": "Success", "gangs": [ {"id": 1, "name": "The Band 1"}, {"id": 2, "name": "The Band 2"} ] }
/<prefix>/outlaw/invite_friend (POST)
Request Example:
$ curl localhost:5000/api/<version>/outlaw/1/invite_friend \ -X POST --data @examples/json/invite_friend.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Invitation sent successfully" }
thesheriff.infrastructure.controllers.raid_controller¶
This module implements the RESTful part of the Raid use cases.
-
thesheriff.infrastructure.controllers.raid_controller.
raid_controller
(create_raid: thesheriff.application.raid.create_raid.CreateRaid, rate_raid: thesheriff.application.outlaw.rate_raid.RateRaid, grade_raid: thesheriff.application.raid.grade_raid.GradeRaid, end_raid: thesheriff.application.raid.end_raid.EndRaid) → flask.blueprints.Blueprint¶ raid_controller holds the blueprint for all raid routes.
- Parameters
create_raid (CreateRaid) – CreateRaid use case implementation.
rate_raid (RateRaid) – RateRaid use case implementation.
grade_raid (GradeRaid) – GradeRaid use case implementation.
end_raid (EndRaid) – EndRaid use case implementation.
- Returns
Flask Blueprint.
- Return type
Blueprint
Implements the following routes:
/<prefix>/raid (POST)
Request Example:
$ curl localhost:5000/api/<version>/raid \ -X POST --data @examples/json/create_raid.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Raid created successfully", "raid": {} }
/<prefix>/raid/<int:raid_id>/rate (PUT)
Request Example:
$ curl localhost:5000/api/<version>/raid/1/rate \ -X PUT --data @examples/json/rate_raid.json \ -H 'Content-Type: application/json'
Response Example:
{ "message": "Raid rated successfully" }
/<prefix>/raid/<int:raid_id>/end/ (PUT)
Request Example:
$ curl localhost:5000/api/<version>/raid/1/end \ -H 'Content-Type: application/json'
Response Example:
{ "message": "raid finished successfully", "score": "Gang's score: 10. Sheriff's score on raid 'raid': 10" }
Repositories¶
-
class
thesheriff.infrastructure.repository.mysql_gang_repository.
MySQLGangRepository
(database_uri: str, meta: sqlalchemy.sql.schema.MetaData, gang_table: sqlalchemy.sql.schema.Table)¶ MySQLGangRepository implements persistence for Gang on MySQL.
- Parameters
database_uri (String) – URI for connecting to MySQL.
meta (sqlalchemy.MetaData) – MetaData object shared across all MySQL repositories.
gang_table (sqlalchemy.Table) – Table object, represents the Gangs table in MySQL.
-
add
(new_gang: thesheriff.domain.gang.gang.Gang) → thesheriff.domain.gang.gang.Gang¶ Method add persists a new Gang to MySQL.
-
all
() → List[thesheriff.domain.gang.gang.Gang]¶ all returns all Gangs stored on MySQL.
- Returns
List Gang objects.
- Return type
List[Gang]
-
of_id
(gang_id: int) → thesheriff.domain.gang.gang.Gang¶ of_id searches for a Gang matching gang_id.
- Parameters
gang_id (Integer) – ID of the Gang to be returned.
- Returns
Gang object.
- Return type
-
remove
(gang_id: int) → NoReturn¶ Method remove deletes existing Gang.
- Parameters
gang_id (Integer) – Id of the Gang to be removed.
- Returns
No returned value.
- Return type
NoReturn
-
class
thesheriff.infrastructure.repository.mysql_outlaw_repository.
MySQLOutlawRepository
(database_uri: str, meta: sqlalchemy.sql.schema.MetaData, outlaw_table: sqlalchemy.sql.schema.Table)¶ MySQLOutlawRepository implements persistence for Outlaw on MySQL.
- Parameters
database_uri (String) – URI for connecting to MySQL
meta (sqlalchemy.MetaData) – MetaData object shared across all MySQL repositories.
outlaw_table (sqlalchemy.Table) – Table object, represents the Outlaw table in MySQL.
-
add
(new_outlaw: thesheriff.domain.outlaw.outlaw.Outlaw) → thesheriff.domain.outlaw.outlaw.Outlaw¶ Method add persists a new Outlaw to MySQL.
-
all
() → List[thesheriff.domain.outlaw.outlaw.Outlaw]¶ all returns all Outlaws stored on MySQL.
- Returns
List Outlaw objects.
- Return type
List[Outlaw]
-
get_friends
(outlaw_id: int) → List[thesheriff.domain.outlaw.outlaw.Outlaw]¶ Method get_Friends lists outlaw’s friends.
- Parameters
outlaw_id (Integer) – Id of the Outlaw to list his friends
- Returns
List of outlaw friends.
- Return type
List[Outlaw]
-
of_id
(outlaw_id: int) → thesheriff.domain.outlaw.outlaw.Outlaw¶ of_id searches for a Outlaw matching outlaw_id.
- Parameters
outlaw_id (Integer) – ID of the Outlaw to be returned.
- Returns
Outlaw object.
- Return type
-
remove
(outlaw_id: int) → NoReturn¶ Method remove deletes existing Outlaw.
- Parameters
outlaw_id (Integer) – Id of the Outlaw to be removed.
- Returns
No returned value.
- Return type
NoReturn
-
class
thesheriff.infrastructure.repository.mysql_raid_repository.
MySQLRaidRepository
(database_uri: str, meta: sqlalchemy.sql.schema.MetaData, raid_table: sqlalchemy.sql.schema.Table)¶ MySQLRaidRepository implements persistence for Raid on MySQL.
- Parameters
database_uri (String) – URI for connecting to MySQL
meta (sqlalchemy.MetaData) – MetaData object shared across all MySQL repositories.
outlaw_table (sqlalchemy.Table) – Table object, represents the Raid table in MySQL.
-
add
(new_raid: thesheriff.domain.raid.raid.Raid) → thesheriff.domain.raid.raid.Raid¶ Method add persists a new Raid to MySQL.
-
of_id
(raid_id: int) → thesheriff.domain.raid.raid.Raid¶ Method of_id searches for an Raid matching raid_id.
- Parameters
raid_id (Integer) – Id of the Raid to be returned.
- Returns
The Raid matching raid_id.
- Return type
-
update
(mod_raid: thesheriff.domain.raid.raid.Raid) → NoReturn¶ Method update updates an existing Raid.
- Parameters
mod_raid (Raid.) – Object with the Raid information
- Returns
No returned value.
- Return type
NoReturn