Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: 'Lint Code'

on:
on:
workflow_dispatch:
push:
branches: [master, main]
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
IBM_CLOUD_REGION: us-south
IBM_CLOUD_GROUP: default
IBM_CLOUD_SPACE: dev
IBM_CLOUD_ORG:
# IBM_CLOUD_ORG:
MANIFEST_NAME: manifest.yml
IBM_CLOUD_API: ${{secrets.IBM_CLOUD_API_KEY}}

Expand Down
5 changes: 3 additions & 2 deletions functions/.creds-sample.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"COUCH_URL": "",
"IAM_API_KEY": ""
"COUCH_URL": "https://28059ad8-d624-49da-9bc2-b47b4fe4f5cf-bluemix.cloudantnosqldb.appdomain.cloud",
"IAM_API_KEY": "TSgWbTjzq6jssiS84dyhno1-8Ndsegw233QlFv51JGLw",
"COUCH_USERNAME":"28059ad8-d624-49da-9bc2-b47b4fe4f5cf-bluemix"
}
70 changes: 70 additions & 0 deletions functions/get-dealerships.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function main(params) {
// console.log(params);
return new Promise(function (resolve, reject) {
const { CloudantV1 } = require('@ibm-cloud/cloudant');
const { IamAuthenticator } = require('ibm-cloud-sdk-core');
const authenticator = new IamAuthenticator({ apikey: "TSgWbTjzq6jssiS84dyhno1-8Ndsegw233QlFv51JGLw" })
const cloudant = CloudantV1.newInstance({
authenticator: authenticator
});
cloudant.setServiceUrl("https://28059ad8-d624-49da-9bc2-b47b4fe4f5cf-bluemix.cloudantnosqldb.appdomain.cloud");
if (params.st) {
// return dealership with this state
cloudant.postFind({db:'dealerships',selector:{st:params.st}})
.then((result)=>{
// console.log(result.result.docs);
let code = 200;
if (result.result.docs.length == 0) {
code = 404;
}
resolve({
statusCode: code,
headers: { 'Content-Type': 'application/json' },
body: result.result.docs
});
}).catch((err)=>{
reject(err);
})
} else if (params.id) {
id = parseInt(params.dealerId)
// return dealership with this state
cloudant.postFind({
db: 'dealerships',
selector: {
id: parseInt(params.id)
}
})
.then((result)=>{
// console.log(result.result.docs);
let code = 200;
if (result.result.docs.length == 0) {
code = 404;
}
resolve({
statusCode: code,
headers: { 'Content-Type': 'application/json' },
body: result.result.docs
});
}).catch((err)=>{
reject(err);
})
} else {
// return all documents
cloudant.postAllDocs({ db: 'dealerships', includeDocs: true })
.then((result)=>{
// console.log(result.result.rows);
let code = 200;
if (result.result.rows.length == 0) {
code = 404;
}
resolve({
statusCode: code,
headers: { 'Content-Type': 'application/json' },
body: result.result.rows
});
}).catch((err)=>{
reject(err);
})
}
}
)}
24 changes: 24 additions & 0 deletions functions/get-review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
from ibmcloudant.cloudant_v1 import CloudantV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

def main(dict):
authenticator = IAMAuthenticator("TSgWbTjzq6jssiS84dyhno1-8Ndsegw233QlFv51JGLw")
service = CloudantV1(authenticator=authenticator)
service.set_service_url("https://28059ad8-d624-49da-9bc2-b47b4fe4f5cf-bluemix.cloudantnosqldb.appdomain.cloud")
response = service.post_find(
db='reviews',
selector={'dealership': {'$eq': int(dict['dealerId'])}},
).get_result()
try:
# result_by_filter=my_database.get_query_result(selector,raw_result=True)
result= {
'headers': {'Content-Type':'application/json'},
'body': {'data':response}
}
return result
except:
return {
'statusCode': 404,
'message': 'Something went wrong'
}
Loading