Skip to content

Commit

Permalink
#157385654 View room schedule (#30)
Browse files Browse the repository at this point in the history
* Add untracked  files after merge

* [Fix] Pull Updated changes to develop

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Fix #157385654]Remove _pycache_ files

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add latest changes from develop

* [fix #157385654]Fix flake8 issues

* [Fix #157385654] Fix failing test.

* [Feature #157385654]Add tests for events

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add latest changes from develop

* [Fix #157385654] Fix failing test.

* [Feature #157385654]Add tests for events

* [Fix #157385654]Run migrations with calendar_id field

* [Fix #157385654]Pull remote changes

* [Fix #157385654]Fix failing test fixtures

* [Fix #157385654]Fix flake8 errors

* [Fix #157385654]Fix migration issues

* [Fix #157385654] Add descriptive error

This commit enables raising of a more descriptive error when a calandarId given on the query is not assigned to any calendar on  ocnverge

* [Fix]Add google api credentials to .env example

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654]Add latest changes from develop

* [Fix #157385654] Fix failing test.

* [Feature #157385654]Add tests for events

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add tests

Add tests for the RoomSchedule query that contains google calendar intergration

* [Feature #157385654] Add getRoomSchedule query

* [Feature #157385654]Add view room schedule functionality

This commit  enables a user to view room schedule from the google calendar api. One is able to specify the calendar_id and the number of days they need and will then receive information containing the event start time and summary of the event

* [Feature #157385654]Add latest changes from develop

* [Fix #157385654] Fix failing test.

* [Feature #157385654]Add tests for events

* [Fix #157385654]Run migrations with calendar_id field

* [Fix #157385654]Pull remote changes

* [Fix #157385654]Fix failing test fixtures

* [Fix #157385654]Fix flake8 errors

* [Fix #157385654]Fix migration issues

* [Fix #157385654] Add descriptive error

This commit enables raising of a more descriptive error when a calandarId given on the query is not assigned to any calendar on  ocnverge

* [Fix]Add google api credentials to .env example

* [fix] Add new changes from develop

* [fix] Add new changes from develop

* [Fix]Fix failing test
  • Loading branch information
owenbob authored and Shem Ogumbe committed Jun 13, 2018
1 parent 9c03d6d commit d5cc963
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 31 deletions.
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']
31 changes: 31 additions & 0 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 @@ -53,6 +59,16 @@ class Query(graphene.ObjectType):
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 @@ -66,6 +82,21 @@ def resolve_get_room_by_id(self, info, room_id):
raise GraphQLError("Room not found")
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):
create_room = CreateRoom.Field()
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
69 changes: 55 additions & 14 deletions fixtures/room/room_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mutation {
createRoom(
name: "Mbarara", roomType: "Meeting", capacity: 4, floorId: 1,
calendarId:"andela.com_3836323338323230343935@resource.calendar.google.com",
imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg") { # noqa: E501
room {
name
Expand Down Expand Up @@ -73,24 +74,64 @@
}


room_query_by_nonexistant_id = '''{
room_with_non_existant_id = '''{
getRoomById(roomId: 100) {
id
name
}
}
'''

room_query_by_nonexistant_id_response = {
"errors": [{
"message": "Room not found",
"locations": [{
"line": 2,
"column": 5
}
]
}],
"data": {
"getRoomById": null
}
}
room_query_with_non_existant_id_response = {
"errors": [
{
"message": "Room not found",
"locations": [
{
"line": 2,
"column": 5
}
]
}
],
"data": {
"getRoomById": null
}
}

room_schedule_query = '''
{
roomSchedule(
calendarId:"andela.com_3836323338323230343935@resource.calendar.google.com",
days:7){
events
}
}
'''

room_schedule_query_with_non_existant_calendar_id = '''
{
roomSchedule(
calendarId:"andela.com_38363230343935@resource.calendar.google.com",
days:7){
events
}
}
'''

room_schedule_of_non_existant_calendar_id_response = {
"errors": [
{
"message": "CalendarId given not assigned to any room on converge", # noqa: E501
"locations": [
{
"line": 1,
"column": 2
}
]
}
],
"data": {
"roomSchedule": null
}
}
Empty file added helpers/calendar/__init__.py
Empty file.
Loading

0 comments on commit d5cc963

Please sign in to comment.