diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/vweb/vweb_app_test.v | |
download | cli-tools-windows-master.tar.gz cli-tools-windows-master.tar.bz2 cli-tools-windows-master.zip |
Diffstat (limited to 'v_windows/v/vlib/vweb/vweb_app_test.v')
-rw-r--r-- | v_windows/v/vlib/vweb/vweb_app_test.v | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/v_windows/v/vlib/vweb/vweb_app_test.v b/v_windows/v/vlib/vweb/vweb_app_test.v new file mode 100644 index 0000000..b2f9145 --- /dev/null +++ b/v_windows/v/vlib/vweb/vweb_app_test.v @@ -0,0 +1,66 @@ +module main + +import vweb +import time +import sqlite + +struct App { + vweb.Context +pub mut: + db sqlite.DB + user_id string +} + +struct Article { + id int + title string + text string +} + +fn test_a_vweb_application_compiles() { + go fn () { + time.sleep(2 * time.second) + exit(0) + }() + vweb.run(&App{}, 18081) +} + +/* +/TODO +pub fn (mut app App) init_server_old() { + app.db = sqlite.connect('blog.db') or { panic(err) } + app.db.create_table('article', [ + 'id integer primary key', + "title text default ''", + "text text default ''", + ]) +} +*/ + +pub fn (mut app App) before_request() { + app.user_id = app.get_cookie('id') or { '0' } +} + +['/new_article'; post] +pub fn (mut app App) new_article() vweb.Result { + title := app.form['title'] + text := app.form['text'] + if title == '' || text == '' { + return app.text('Empty text/title') + } + article := Article{ + title: title + text: text + } + println('posting article') + println(article) + sql app.db { + insert article into Article + } + + return app.redirect('/') +} + +fn (mut app App) time() { + app.text(time.now().format()) +} |