Skip to content

Commit

Permalink
Merge branch 'ft-health-check-url-158212394' of https://github.com/an…
Browse files Browse the repository at this point in the history
…dela/mrm_api into ft-health-check-url-158212394
  • Loading branch information
Deo Kamara authored and Deo Kamara committed Jun 14, 2018
2 parents 40bd926 + 67f2fca commit 5f2f147
Show file tree
Hide file tree
Showing 26 changed files with 520 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
- run:
name: Deploy to gcloud
command: gcloud beta compute instance-groups managed rolling-action replace mrm-backend-instance-group --max-unavailable=1 --min-ready=280 --zone=europe-west1-b
command: gcloud beta compute instance-groups managed rolling-action replace mrm-backend-instance-group --region europe-west1

workflows:
version: 2
Expand Down
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export SECRET_KEY="some-very-long-string-of-random-characters"
export DEV_DATABASE_URL="" # Db for Development.
export TEST_DATABASE_URL="" # Db for Testing
export DATABASE_URL="" # Db for Production
export API_KEY="" # Google API app Api key
export OOATH2_CLIENT_ID="" # Google API app ooath2_client_id
export OOATH2_CLIENT_SECRET="" # Google API app ooath2_client_secret

40 changes: 40 additions & 0 deletions alembic/versions/06c4fd428167_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""empty message
Revision ID: 06c4fd428167
Revises:
Create Date: 2018-06-05 12:29:10.404447
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '06c4fd428167'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('devices')
op.add_column('rooms', sa.Column('calendar_id', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('rooms', 'calendar_id')
op.create_table('devices',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('device_type', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('date_added', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('last_seen', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('resource_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['resource_id'], ['resources.id'], name='devices_resource_id_fkey'),
sa.PrimaryKeyConstraint('id', name='devices_pkey')
)
# ### end Alembic commands ###
40 changes: 40 additions & 0 deletions alembic/versions/16706f39418e_add_calndarid_field_to_room_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Add calndarId field to room table
Revision ID: 16706f39418e
Revises: c231314bba8d
Create Date: 2018-06-07 15:51:04.456452
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '16706f39418e'
down_revision = 'c231314bba8d'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('devices')
op.add_column('rooms', sa.Column('calendar_id', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('rooms', 'calendar_id')
op.create_table('devices',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('device_type', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('date_added', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('last_seen', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('resource_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['resource_id'], ['resources.id'], name='devices_resource_id_fkey'),
sa.PrimaryKeyConstraint('id', name='devices_pkey')
)
# ### end Alembic commands ###
40 changes: 40 additions & 0 deletions alembic/versions/21ca82d232ff_add_calendarid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Add calendarId
Revision ID: 21ca82d232ff
Revises: b3be355ffe21
Create Date: 2018-06-13 13:08:35.409236
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '21ca82d232ff'
down_revision = 'b3be355ffe21'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('devices')
op.add_column('rooms', sa.Column('calendar_id', sa.String(), nullable=False))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('rooms', 'calendar_id')
op.create_table('devices',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('device_type', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('date_added', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('last_seen', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('resource_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['resource_id'], ['resources.id'], name='devices_resource_id_fkey'),
sa.PrimaryKeyConstraint('id', name='devices_pkey')
)
# ### end Alembic commands ###
24 changes: 24 additions & 0 deletions alembic/versions/631fe5fea815_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""empty message
Revision ID: 631fe5fea815
Revises: b3be355ffe21, 06c4fd428167
Create Date: 2018-06-07 14:07:21.597872
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '631fe5fea815'
down_revision = ('b3be355ffe21', '06c4fd428167')
branch_labels = None
depends_on = None


def upgrade():
pass


def downgrade():
pass
40 changes: 40 additions & 0 deletions alembic/versions/a3a250e2805a_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""empty message
Revision ID: a3a250e2805a
Revises: 16706f39418e
Create Date: 2018-06-08 15:32:37.991700
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'a3a250e2805a'
down_revision = '16706f39418e'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('devices')
op.add_column('rooms', sa.Column('calendar_id', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('rooms', 'calendar_id')
op.create_table('devices',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('device_type', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('date_added', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('last_seen', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('resource_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['resource_id'], ['resources.id'], name='devices_resource_id_fkey'),
sa.PrimaryKeyConstraint('id', name='devices_pkey')
)
# ### end Alembic commands ###
2 changes: 2 additions & 0 deletions api/room/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Room(Base, Utility):
room_type = Column(String, nullable=False)
capacity = Column(Integer, nullable=False)
image_url = Column(String)
calendar_id = Column(String)
floor_id = Column(Integer, ForeignKey('floors.id'))
resources = relationship('Resource')

Expand All @@ -24,4 +25,5 @@ def __init__(self, **kwargs):
self.room_type = kwargs['room_type']
self.capacity = kwargs['capacity']
self.image_url = kwargs['image_url']
self.calendar_id = kwargs['calendar_id']
self.floor_id = kwargs['floor_id']
38 changes: 34 additions & 4 deletions api/room/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@

from api.room.models import Room as RoomModel
from utilities.utility import validate_empty_fields, update_entity_fields
from helpers.calendar.events import RoomSchedules


class Room(SQLAlchemyObjectType):
class Meta:
model = RoomModel


class Calendar(graphene.ObjectType):
events = graphene.String()


class CreateRoom(graphene.Mutation):
class Arguments:
name = graphene.String(required=True)
room_type = graphene.String(required=True)
capacity = graphene.Int(required=True)
image_url = graphene.String()
floor_id = graphene.Int(required=True)
calendar_id = graphene.String(required=True)
room = graphene.Field(Room)

def mutate(self, info, **kwargs):
Expand Down Expand Up @@ -50,9 +56,19 @@ def mutate(self, info, room_id, **kwargs):

class Query(graphene.ObjectType):
all_rooms = graphene.List(Room)
get_room_by_id = graphene.List(
lambda: Room,
get_room_by_id = graphene.Field(
Room,
room_id=graphene.Int()
)
room_schedule = graphene.Field(
Calendar,
calendar_id=graphene.String(),
days=graphene.Int(),
)
room_schedule = graphene.Field(
Calendar,
calendar_id=graphene.String(),
days=graphene.Int(),
)

def resolve_all_rooms(self, info):
Expand All @@ -64,8 +80,22 @@ def resolve_get_room_by_id(self, info, room_id):
check_room = query.filter(RoomModel.id == room_id).first()
if not check_room:
raise GraphQLError("Room not found")
result = query.filter(RoomModel.id == room_id)
return result
return check_room

def resolve_room_schedule(self, info, calendar_id, days):
query = Room.get_query(info)
check_calendar_id = query.filter(
RoomModel.calendar_id == calendar_id
).first()
if not check_calendar_id:
raise GraphQLError("CalendarId given not assigned to any room on converge") # noqa: E501
room_schedule = RoomSchedules.get_room_schedules(
self,
calendar_id,
days)
return Calendar(
events=room_schedule
)


class Mutation(graphene.ObjectType):
Expand Down
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask
from flask_cors import CORS
from flask_graphql import GraphQLView


Expand All @@ -10,8 +11,11 @@

def create_app(config_name):
app = Flask(__name__)
CORS(app)

app.config.from_object(config[config_name])
config[config_name].init_app(app)

app.add_url_rule(
'/mrm',
view_func=GraphQLView.as_view(
Expand Down
1 change: 1 addition & 0 deletions credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"access_token": "ya29.Gl3ZBUb8ewx_F9NdEtMIDxH1XPsKOJA64dJwSqd7I6SuDbynB-UHCDw58VtcbjgYZPFrEKrk_99kvJolLRGGuXAUXBRLzAZ85ZaRUkPen-ehtjsycrPbMefC6wV7rMo", "client_id": "753057157806-4n8rnuuvn9iagp7md6s6448omdqi0iif.apps.googleusercontent.com", "client_secret": "DV154Q4dUxR-gaGtiBmonItI", "refresh_token": "1/scqhTOtBcRLGoC5a5brOZElp6a__tUbdbe17p8R7o9g", "token_expiry": "2018-06-13T12:59:51Z", "token_uri": "https://www.googleapis.com/oauth2/v4/token", "user_agent": null, "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.Gl3ZBUb8ewx_F9NdEtMIDxH1XPsKOJA64dJwSqd7I6SuDbynB-UHCDw58VtcbjgYZPFrEKrk_99kvJolLRGGuXAUXBRLzAZ85ZaRUkPen-ehtjsycrPbMefC6wV7rMo", "token_type": "Bearer", "expires_in": 3600}, "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "token_info_uri": "https://www.googleapis.com/oauth2/v3/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}
24 changes: 12 additions & 12 deletions fixtures/location/all_locations_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@
}'''

expected_response_pass_an_arg = {
"errors": [
{
"message": "Unknown argument \"locationId\" on field \"allLocations\" of type \"Query\".", # noqa: E501
"locations": [
{
"line": 3,
"column": 22
}
]
}
]
}
"errors": [
{
"message": "Unknown argument \"locationId\" on field \"allLocations\" of type \"Query\".", # noqa: E501
"locations": [
{
"line": 3,
"column": 22
}
]
}
]
}

all_location_no_hierachy = '''{
allLocations{
Expand Down
Loading

0 comments on commit 5f2f147

Please sign in to comment.