Skip to content

Commit

Permalink
init chat model
Browse files Browse the repository at this point in the history
  • Loading branch information
lastlink committed Mar 6, 2021
1 parent 0cca6f1 commit ae4a33d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
40 changes: 28 additions & 12 deletions model/conversations-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,44 @@ function getConversation($conversationId)
return $prodInfo;
}

function addMessage($input){
function getMessage($id)
{
$db = acmeConnect();
$sql = 'SELECT c.* FROM conversations c where c.id = :id';
$stmt = $db->prepare($sql);
$stmt->bindValue(':id', $id, PDO::PARAM_STR);
$stmt->execute();
$prodInfo = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $prodInfo;
}

function sendMessage($conversationId, $message)
{
// $id = generateUuid();
// Create a connection object using the acme connection function
$db = acmeConnect();
// The SQL statement
$sql = 'INSERT INTO `reviews` (`reviewText`, `reviewDate`, `invId`, `clientId`) VALUES (:reviewText, :reviewDate, :invId, :clientId)';
$sql = 'INSERT INTO `conversations`(`threadId`, `message`)
VALUES (:parentId, :message)';
// echo $sql;
$stmt = $db->prepare($sql);

// $stmt->bindValue(':id', $id, PDO::PARAM_STR);
$stmt->bindValue(':parentId', $conversationId, PDO::PARAM_STR);
$stmt->bindValue(':message', $message, PDO::PARAM_STR);


// // Create the prepared statement using the acme connection
$stmt = $db->prepare($sql);
// // The next four lines replace the placeholders in the SQL
// // statement with the actual values in the variables
// // and tells the database the type of data it is
// $stmt->bindValue(':reviewText', $reviewText, PDO::PARAM_STR);
// $stmt->bindValue(':reviewDate', $reviewDate, PDO::PARAM_STR);
// $stmt->bindValue(':invId', $invId, PDO::PARAM_INT);
// $stmt->bindValue(':clientId', $clientId, PDO::PARAM_INT);

// Insert the data
$stmt->execute();
// Ask how many rows changed as a result of our insert
$rowsChanged = $stmt->rowCount();
$id = $db->lastinsertid();
// Close the database interaction
$stmt->closeCursor();
// Return the indication of success (rows changed)
return $rowsChanged;
}
$result = array('rowsChanged' => $rowsChanged, 'lastId' => $id);
return $result;
}
5 changes: 2 additions & 3 deletions rest/conversations.rest
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ content-type: application/json
Accept: application/json

{
"threadId": "xxx"
"threadId": "effba2487ece11eb8e3a0242ac110002"
}

### send charset
POST http://127.0.0.1:8000/conversations/?action=submit HTTP/1.1
content-type: application/json
Accept: application/json
Authorization: Bearer {{token}}

{
"threadId": "xxx",
"threadId": "effba2487ece11eb8e3a0242ac110002",
"message": "test comment"
}

0 comments on commit ae4a33d

Please sign in to comment.