mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-24 18:41:32 +00:00
rename lots of things
This commit is contained in:
28
backend-assemblyscript/step3-finished-app/assembly/main.ts
Normal file
28
backend-assemblyscript/step3-finished-app/assembly/main.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import {Action, decode, FetchRequest, PostRequest} from "./request";
|
||||
import {PostResponse, Message, FetchResponse, UnknownResponse} from "./response";
|
||||
import {addMessage, getMessages, getPostsCount, initTables} from "./database";
|
||||
|
||||
initTables();
|
||||
|
||||
// main handler for an application
|
||||
export function handler(input: string): string {
|
||||
|
||||
let request = decode(input);
|
||||
|
||||
if (request.action == Action.Post) {
|
||||
let post = request as PostRequest;
|
||||
addMessage(post.msg, post.username);
|
||||
let count = getPostsCount();
|
||||
|
||||
let response = new PostResponse(count);
|
||||
return response.serialize()
|
||||
} else if (request.action == Action.Fetch) {
|
||||
let fetch = request as FetchRequest;
|
||||
|
||||
let result = getMessages(fetch.username);
|
||||
return result;
|
||||
}
|
||||
|
||||
let response = new UnknownResponse();
|
||||
return response.serialize();
|
||||
}
|
Reference in New Issue
Block a user