Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
240
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
U.D.C.S.WIJESOORIYA
240
Commits
95824fb9
Commit
95824fb9
authored
Oct 06, 2022
by
Malsha Rathnasiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
16228ea8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
12 deletions
+38
-12
MobileApp/api/Authentication.js
MobileApp/api/Authentication.js
+1
-0
MobileApp/api/api.js
MobileApp/api/api.js
+6
-1
MobileApp/api/constants.js
MobileApp/api/constants.js
+1
-1
MobileApp/screens/TabOneScreen.jsx
MobileApp/screens/TabOneScreen.jsx
+17
-3
backend/backend/cms/views.py
backend/backend/cms/views.py
+11
-4
backend/backend/settings.py
backend/backend/settings.py
+2
-3
backend/db.sqlite3
backend/db.sqlite3
+0
-0
No files found.
MobileApp/api/Authentication.js
View file @
95824fb9
...
@@ -88,6 +88,7 @@ export const login = async (username, password) => {
...
@@ -88,6 +88,7 @@ export const login = async (username, password) => {
// Actions.main();
// Actions.main();
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
console
.
log
(
'
error in login authentication
'
)
throw
Error
(
error
)
throw
Error
(
error
)
});
});
...
...
MobileApp/api/api.js
View file @
95824fb9
...
@@ -13,12 +13,17 @@ const getHeaders = async () => {
...
@@ -13,12 +13,17 @@ const getHeaders = async () => {
var
token
=
await
AsyncStorage
.
getItem
(
'
access_token
'
)
var
token
=
await
AsyncStorage
.
getItem
(
'
access_token
'
)
return
{
return
{
Authorization
:
`JWT
${
token
}
`
,
'
Content-Type
'
:
'
application/json
'
,
Authorization
:
`JWT
${
token
}
`
,
'
Content-Type
'
:
'
application/json
'
,
// "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS",
// "Access-Control-Allow-Headers": "Content-Type, Authorization, Access-Control-Allow-Methods",
// "Access-Control-Allow-Origin": "*",
}
}
}
}
export
const
create
=
async
(
resource
,
values
)
=>
{
export
const
create
=
async
(
resource
,
values
)
=>
{
const
headers
=
getHeaders
()
const
headers
=
await
getHeaders
()
console
.
log
({
headers
},
'
create
'
)
console
.
log
({
headers
},
'
create
'
)
console
.
log
({
values
})
try
{
try
{
return
fetch
(
`
${
BACKEND_URL
}
/
${
resource
}
/`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
values
),
headers
})
return
fetch
(
`
${
BACKEND_URL
}
/
${
resource
}
/`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
values
),
headers
})
// return Axios.post(`${BACKEND_URL}/${resource}/`, values)
// return Axios.post(`${BACKEND_URL}/${resource}/`, values)
...
...
MobileApp/api/constants.js
View file @
95824fb9
// export const BACKEND_URL = "http://192.168.8.103:8000"
// export const BACKEND_URL = "http://192.168.8.103:8000"
import
{
Platform
}
from
'
react-native
'
import
{
Platform
}
from
'
react-native
'
export
const
BACKEND_ADDRESS
=
Platform
.
OS
==
'
web
'
?
"
127.0.0.1:8000
"
:
"
93e8-2401-dd00-10-20-e170-748c-b618-e8f5.in
.ngrok.io
"
export
const
BACKEND_ADDRESS
=
Platform
.
OS
==
'
web
'
?
"
127.0.0.1:8000
"
:
"
0afe-112-134-223-169.ap
.ngrok.io
"
export
const
BACKEND_URL
=
`http://
${
BACKEND_ADDRESS
}
`
export
const
BACKEND_URL
=
`http://
${
BACKEND_ADDRESS
}
`
MobileApp/screens/TabOneScreen.jsx
View file @
95824fb9
...
@@ -15,6 +15,7 @@ import Slider from '@react-native-community/slider';
...
@@ -15,6 +15,7 @@ import Slider from '@react-native-community/slider';
import
{
PlayMessage
}
from
'
../components/PlayMessage
'
;
import
{
PlayMessage
}
from
'
../components/PlayMessage
'
;
import
{
Toast
}
from
'
native-base
'
;
import
{
Toast
}
from
'
native-base
'
;
import
{
ERROR_TOAST_PROPS
}
from
'
../util/util
'
;
import
{
ERROR_TOAST_PROPS
}
from
'
../util/util
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
export
default
function
ChatScreen
({
navigation
})
{
export
default
function
ChatScreen
({
navigation
})
{
...
@@ -97,7 +98,20 @@ export default function ChatScreen({ navigation }) {
...
@@ -97,7 +98,20 @@ export default function ChatScreen({ navigation }) {
return
res
.
json
()
return
res
.
json
()
}).
then
(
res
=>
{
}).
then
(
res
=>
{
console
.
log
(
res
)
console
.
log
(
res
)
setChatDetails
(
res
)
AsyncStorage
.
getItem
(
'
user_id
'
).
then
((
user_id
)
=>
{
console
.
log
(
'
chat details
'
,
user_id
)
//change from user and to user depending on the current user
if
(
res
.
from_user
==
user_id
)
{
setChatDetails
(
res
)
}
else
{
const
n_res
=
{
...
res
,
from_user
:
res
.
to_user
,
to_user
:
res
.
from_user
}
setChatDetails
(
n_res
)
}
})
})
})
}
}
...
@@ -117,7 +131,7 @@ export default function ChatScreen({ navigation }) {
...
@@ -117,7 +131,7 @@ export default function ChatScreen({ navigation }) {
const
onSendPress
=
()
=>
{
const
onSendPress
=
()
=>
{
try
{
try
{
create
(
'
chats
'
,
{
message
:
input
,
from_user
:
chatDetails
.
from_user
,
to_user
:
chatDetails
.
to_user
,
conversation
:
chatDetails
.
conversation_
id
}).
then
(
response
=>
{
create
(
'
chats
'
,
{
message
:
input
,
from_user
:
chatDetails
.
from_user
,
to_user
:
chatDetails
.
to_user
,
conversation
:
chatDetails
.
id
}).
then
(
response
=>
{
// console.log(response)
// console.log(response)
})
})
setLoading
(
true
)
setLoading
(
true
)
...
@@ -151,7 +165,7 @@ export default function ChatScreen({ navigation }) {
...
@@ -151,7 +165,7 @@ export default function ChatScreen({ navigation }) {
inverted
inverted
sections=
{
chats
}
sections=
{
chats
}
keyExtractor=
{
(
item
,
index
)
=>
item
+
index
}
keyExtractor=
{
(
item
,
index
)
=>
item
+
index
}
renderItem=
{
({
item
})
=>
{
renderItem=
{
({
item
})
=>
{
// console.log(
{
item
})
// console.log(
{
item
})
const
timeString
=
new
Date
(
item
.
timestamp
).
toLocaleTimeString
()
const
timeString
=
new
Date
(
item
.
timestamp
).
toLocaleTimeString
()
...
...
backend/backend/cms/views.py
View file @
95824fb9
...
@@ -178,12 +178,17 @@ class MlModelViewSet(viewsets.ViewSet):
...
@@ -178,12 +178,17 @@ class MlModelViewSet(viewsets.ViewSet):
class
ChatViewSet
(
viewsets
.
ModelViewSet
):
class
ChatViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Chat
.
objects
.
all
()
.
order_by
(
'-timestamp'
)
queryset
=
Chat
.
objects
.
all
()
.
order_by
(
'-timestamp'
)
serializer_class
=
ChatSerializer
serializer_class
=
ChatSerializer
permission_classes
=
[
permissions
.
IsAuthenticated
]
permission_classes
=
[
permissions
.
IsAuthenticated
]
#change to permissions.isAutheniticated
@
action
(
methods
=
'POST'
,
detail
=
True
)
@
action
(
methods
=
'POST'
,
detail
=
True
)
def
getChats
(
self
,
request
,
*
args
,
**
kwargs
):
def
getChats
(
self
,
request
,
*
args
,
**
kwargs
):
chats
=
Chat
.
objects
.
filter
(
Q
(
from_user__user_id
=
request
.
user
.
id
)
|
Q
(
#conversation_id hardcoded as we dont have many conversations at the moment
to_user__user_id
=
request
.
user
.
id
))
.
order_by
(
'-timestamp'
)
.
values
()
chats
=
Chat
.
objects
\
.
filter
(
conversation_id
=
1
)
\
.
filter
(
(
Q
(
from_user__user_id
=
request
.
user
.
id
)
|
Q
(
to_user__user_id
=
request
.
user
.
id
))
)
.
order_by
(
'-timestamp'
)
.
values
()
return
Response
({
chats
})
return
Response
({
chats
})
...
@@ -191,7 +196,9 @@ class ChatViewSet(viewsets.ModelViewSet):
...
@@ -191,7 +196,9 @@ class ChatViewSet(viewsets.ModelViewSet):
if
pk
==
None
:
if
pk
==
None
:
chats
=
Chat
.
objects
.
filter
(
Q
(
from_user_id
=
request
.
user
.
id
)
|
Q
(
chats
=
Chat
.
objects
\
.
filter
(
conversation_id
=
1
)
\
.
filter
(
Q
(
from_user_id
=
request
.
user
.
id
)
|
Q
(
to_user_id
=
request
.
user
.
id
))
to_user_id
=
request
.
user
.
id
))
else
:
else
:
chats
=
Chat
.
objects
.
get
(
id
=
pk
)
chats
=
Chat
.
objects
.
get
(
id
=
pk
)
...
...
backend/backend/settings.py
View file @
95824fb9
...
@@ -46,13 +46,12 @@ INSTALLED_APPS = [
...
@@ -46,13 +46,12 @@ INSTALLED_APPS = [
]
]
MIDDLEWARE
=
[
MIDDLEWARE
=
[
'corsheaders.middleware.CorsMiddleware'
,
'django.middleware.security.SecurityMiddleware'
,
'django.middleware.security.SecurityMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'django.middleware.common.CommonMiddleware'
,
'django.middleware.common.CommonMiddleware'
,
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'corsheaders.middleware.CorsMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
...
@@ -133,7 +132,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
...
@@ -133,7 +132,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
REST_FRAMEWORK
=
{
REST_FRAMEWORK
=
{
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.PageNumberPagination'
,
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.PageNumberPagination'
,
'PAGE_SIZE'
:
10
,
'PAGE_SIZE'
:
10
0
,
'DEFAULT_AUTHENTICATION_CLASSES'
:
[
'DEFAULT_AUTHENTICATION_CLASSES'
:
[
'rest_framework_simplejwt.authentication.JWTAuthentication'
,
'rest_framework_simplejwt.authentication.JWTAuthentication'
,
'rest_framework.authentication.SessionAuthentication'
,
'rest_framework.authentication.SessionAuthentication'
,
...
...
backend/db.sqlite3
View file @
95824fb9
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment