Skip to content

Commit

Permalink
Merge pull request #40 from cf15-t5/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lutfianRhdn authored Aug 24, 2023
2 parents fa01eed + d0b9b1f commit ad9917a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
12 changes: 9 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ DEBUG=True

DATABASE_URL="mysql+pymysql://username:password@localhost:3306/se_ticket"


JWT_ACCESS_TOKEN_EXPIRES=604800
JWT_ACCESS_TOKEN_SECRET="secret"
JWT_ACCESS_TOKEN_ALGORITHM="HS256"


MAIL_SERVER='smtp.gmail.com'
MAIL_PORT = 587
MAIL_USERNAME = '[email protected]'
MAIL_PASSWORD = 'duewujqfideibbkm'
MAIL_PORT = 465
MAIL_USERNAME = ' '
MAIL_PASSWORD = ''
MAIL_USE_TLS = False
MAIL_USE_SSL = True
2 changes: 0 additions & 2 deletions src/config/mail.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from flask_mail import Mail
from src.config.config import MAIL_PORT,MAIL_SERVER,MAIL_USE_SSL,MAIL_USE_TLS,MAIL_USERNAME,MAIL_PASSWORD
def mailConfig(app):
print(MAIL_SERVER,MAIL_PORT,MAIL_USE_SSL,MAIL_USE_TLS,MAIL_USERNAME,MAIL_PASSWORD)
print(type(MAIL_SERVER),type(MAIL_PORT),type(MAIL_USE_SSL),type(MAIL_USE_TLS),type(MAIL_USERNAME),type(MAIL_PASSWORD))
app.config['MAIL_SERVER']= MAIL_SERVER
app.config['MAIL_PORT'] = MAIL_PORT
app.config['MAIL_USE_TLS'] = MAIL_USE_TLS == 'True'
Expand Down
1 change: 0 additions & 1 deletion src/middlewares/AuthMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def wrapper(*args, **kwargs):
is_have_access = check_role_is_have_access(user.role, request.path)
if not is_have_access:
return response.error(message="Forbidden", errors=None, status_code=403)
print(user)
g.user = queryResultToDict([user])[0]
return func(*args, **kwargs)
except jwt.jwt.InvalidKeyError as e:
Expand Down
1 change: 0 additions & 1 deletion src/repositories/EventRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def getAllEvent(self):
def getAllEventFiltered(self,filters):

events = Event.query.all()
# print('filters',filters)

filtered_events = [event for event in events if
(not filters['province'] or event.address.split(',')[3].strip()== filters['province']) and
Expand Down
1 change: 0 additions & 1 deletion src/services/AuthService.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def login(self,data):
isPasswordMatch = bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8') )
if not user or not isPasswordMatch:
return self.failedOrSuccessRequest('failed', 400, 'user not found')
print(user.status)
if(user.status == 'INACTIVE'):return self.failedOrSuccessRequest('failed', 400, 'user not verified')
user_dict = queryResultToDict([user])[0]

Expand Down
25 changes: 16 additions & 9 deletions src/services/EventService.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def failedOrSuccessRequest(status, code, data):
'data': data,
}

def _count_ticket_and_attendace(self,events:list):
for event in events:
event['ticket_count'] = len(event['tickets'])
event['attendances_count'] = len([ticket for ticket in event['tickets'] if ticket['is_attended']])
event.pop('tickets')
return events
def getAllEvent(self,filter):
try:
if( any(value is not None for value in filter.values())):
Expand All @@ -25,11 +31,9 @@ def getAllEvent(self,filter):
data = eventRepository.getAllEvent()
# add ticket count to each event
data_dict = queryResultToDict(data,['user','category','tickets'])
for event in data_dict:
event['ticket_count'] = len(event['tickets'])
event['attendances_count'] = len([ticket for ticket in event['tickets'] if ticket['is_attended']])
event.pop('tickets')
return EventService.failedOrSuccessRequest('success', 200,data_dict )
result = self._count_ticket_and_attendace(data_dict)

return EventService.failedOrSuccessRequest('success', 200,result )
except Exception as e:
print(e)
return EventService.failedOrSuccessRequest('failed', 500, str(e))
Expand All @@ -38,7 +42,9 @@ def getEventById(self,id):
event = eventRepository.getEventById(id)
if not event:
return EventService.failedOrSuccessRequest('failed', 404, 'Event not found')
return EventService.failedOrSuccessRequest('success', 200, queryResultToDict([event],['user','category'])[0])
data_dict = queryResultToDict([event],['user','category'])[0]
result = self._count_ticket_and_attendace([data_dict])[0]
return EventService.failedOrSuccessRequest('success', 200, result)
except Exception as e:
return EventService.failedOrSuccessRequest('failed', 500, str(e))

Expand Down Expand Up @@ -69,13 +75,11 @@ def updateEvent(self,id,data,file ,user_id):
event_copied = queryResultToDict([event])[0]

if file:
print(event)
event_copied['poster_path'] = upload_file(file['poster'])
event_copied.update(data_dict)
event_copied.pop('user_id')
event_copied.pop('status')

print(event_copied,file=sys.stderr)
eventUpdated = eventRepository.updateEvent(**event_copied)
return EventService.failedOrSuccessRequest('success', 201, queryResultToDict([eventUpdated])[0])
except ValueError as e:
Expand Down Expand Up @@ -112,6 +116,9 @@ def verifyEvent(self,data):
def getMyEvent(self,user_id):
try:
data = eventRepository.getAllEventByUserId(user_id)
return EventService.failedOrSuccessRequest('success', 200, queryResultToDict(data,['user','category']))
data_dict = queryResultToDict(data,['user','category','tickets'])
result = self._count_ticket_and_attendace(data_dict)

return EventService.failedOrSuccessRequest('success', 200,result)
except Exception as e:
return EventService.failedOrSuccessRequest('failed', 500, str(e))
1 change: 0 additions & 1 deletion src/services/TransactionService.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def failedOrSuccessRequest(status, code, data):
def getAllTransactions(self):
try:
data = TransactionRepository.getAllTransaction()
print(data)
return self.failedOrSuccessRequest('success', 200, queryResultToDict(data,['user','ticket']))
except Exception as e:
return self.failedOrSuccessRequest('failed', 500, str(e))
Expand Down

0 comments on commit ad9917a

Please sign in to comment.