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
2022-240
240
Commits
f40a894b
Commit
f40a894b
authored
Oct 12, 2022
by
Malsha Rathnasiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix chat send
parent
a9219204
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
3 deletions
+42
-3
MobileApp/api/api.js
MobileApp/api/api.js
+13
-0
MobileApp/api/constants.js
MobileApp/api/constants.js
+1
-1
MobileApp/screens/TabOneScreen.jsx
MobileApp/screens/TabOneScreen.jsx
+2
-2
backend/backend/cms/views.py
backend/backend/cms/views.py
+26
-0
backend/db.sqlite3
backend/db.sqlite3
+0
-0
backend/output.m4a
backend/output.m4a
+0
-0
No files found.
MobileApp/api/api.js
View file @
f40a894b
...
@@ -20,6 +20,19 @@ const getHeaders = async () => {
...
@@ -20,6 +20,19 @@ const getHeaders = async () => {
}
}
}
}
export
const
addChats
=
async
(
values
)
=>
{
const
headers
=
await
getHeaders
()
console
.
log
({
headers
},
'
create
'
)
console
.
log
({
values
})
try
{
return
fetch
(
`
${
BACKEND_URL
}
/chats/add_chats/`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
values
),
headers
})
// return Axios.post(`${BACKEND_URL}/${resource}/`, values)
}
catch
(
e
)
{
console
.
log
(
e
)
}
}
export
const
create
=
async
(
resource
,
values
)
=>
{
export
const
create
=
async
(
resource
,
values
)
=>
{
const
headers
=
await
getHeaders
()
const
headers
=
await
getHeaders
()
console
.
log
({
headers
},
'
create
'
)
console
.
log
({
headers
},
'
create
'
)
...
...
MobileApp/api/constants.js
View file @
f40a894b
// 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
'
?
"
http://127.0.0.1:8000
"
:
"
https://
438c-2401-dd00-10-20-ccb8-3726-acbd-ade4
.ap.ngrok.io
"
export
const
BACKEND_ADDRESS
=
Platform
.
OS
==
'
web
'
?
"
http://127.0.0.1:8000
"
:
"
https://
cbc3-2401-dd00-10-20-7542-a875-30e7-8931
.ap.ngrok.io
"
export
const
BACKEND_URL
=
`
${
BACKEND_ADDRESS
}
`
export
const
BACKEND_URL
=
`
${
BACKEND_ADDRESS
}
`
MobileApp/screens/TabOneScreen.jsx
View file @
f40a894b
...
@@ -6,7 +6,7 @@ import _ from 'lodash'
...
@@ -6,7 +6,7 @@ import _ from 'lodash'
import
EditScreenInfo
from
'
../components/EditScreenInfo
'
;
import
EditScreenInfo
from
'
../components/EditScreenInfo
'
;
// import { Text, View } from '../components/Themed';
// import { Text, View } from '../components/Themed';
import
{
RootTabScreenProps
}
from
'
../types
'
;
import
{
RootTabScreenProps
}
from
'
../types
'
;
import
{
create
,
getList
,
getOne
}
from
'
../api/api
'
;
import
{
addChats
,
create
,
getList
,
getOne
}
from
'
../api/api
'
;
import
{
BACKEND_ADDRESS
}
from
'
../api/constants
'
;
import
{
BACKEND_ADDRESS
}
from
'
../api/constants
'
;
import
Ionicons
from
'
@expo/vector-icons/Ionicons
'
;
import
Ionicons
from
'
@expo/vector-icons/Ionicons
'
;
import
{
CONVO_DEFAULT_ICON_COLOR
,
styles
}
from
'
../util/styles
'
;
import
{
CONVO_DEFAULT_ICON_COLOR
,
styles
}
from
'
../util/styles
'
;
...
@@ -132,7 +132,7 @@ export default function ChatScreen({ navigation }) {
...
@@ -132,7 +132,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
.
id
}).
then
(
response
=>
{
addChats
({
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
)
...
...
backend/backend/cms/views.py
View file @
f40a894b
from
sre_constants
import
SUCCESS
from
tkinter
import
N
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
from
grpc
import
Status
from
rest_framework
import
viewsets
from
rest_framework
import
viewsets
from
rest_framework
import
permissions
from
rest_framework
import
permissions
from
backend.cms.serializers
import
MyTokenObtainPairSerializer
from
backend.cms.serializers
import
MyTokenObtainPairSerializer
...
@@ -9,6 +12,7 @@ from rest_framework.decorators import action
...
@@ -9,6 +12,7 @@ from rest_framework.decorators import action
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
import
os
import
os
from
rest_framework.parsers
import
MultiPartParser
from
rest_framework.parsers
import
MultiPartParser
from
rest_framework
import
serializers
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
...
@@ -176,6 +180,28 @@ class ChatViewSet(viewsets.ModelViewSet):
...
@@ -176,6 +180,28 @@ class ChatViewSet(viewsets.ModelViewSet):
return
result_set
return
result_set
@
action
(
methods
=
[
'POST'
],
detail
=
False
)
def
send_chat
(
self
,
request
,
pk
=
None
):
try
:
print
(
request
.
data
)
return
Response
({
'success'
:
True
})
except
(
e
):
return
Response
({
'success'
:
False
})
@
action
(
methods
=
[
'POST'
],
detail
=
False
)
def
add_chats
(
self
,
request
):
item
=
ChatSerializer
(
data
=
request
.
data
)
# validating for already existing data
if
Chat
.
objects
.
filter
(
**
request
.
data
)
.
exists
():
raise
serializers
.
ValidationError
(
'This data already exists'
)
if
item
.
is_valid
():
item
.
save
()
return
Response
(
item
.
data
)
else
:
return
Response
(
status
=
Status
.
HTTP_404_NOT_FOUND
)
class
ConversationViewSet
(
viewsets
.
ModelViewSet
):
class
ConversationViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Conversation
.
objects
.
all
()
.
order_by
(
'id'
)
queryset
=
Conversation
.
objects
.
all
()
.
order_by
(
'id'
)
serializer_class
=
ConversationSerializer
serializer_class
=
ConversationSerializer
...
...
backend/db.sqlite3
View file @
f40a894b
No preview for this file type
backend/output.m4a
View file @
f40a894b
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