refactor: moved BuildLog to models
							parent
							
								
									6bd5b7cb48
								
							
						
					
					
						commit
						2fc25f1afe
					
				| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
module client
 | 
					module client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import db { BuildLog }
 | 
					import models { BuildLog }
 | 
				
			||||||
import net.http { Method }
 | 
					import net.http { Method }
 | 
				
			||||||
import response { Response }
 | 
					import response { Response }
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,8 @@ module logs
 | 
				
			||||||
import cli
 | 
					import cli
 | 
				
			||||||
import env
 | 
					import env
 | 
				
			||||||
import client
 | 
					import client
 | 
				
			||||||
import db
 | 
					 | 
				
			||||||
import console
 | 
					import console
 | 
				
			||||||
 | 
					import models { BuildLog }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Config {
 | 
					struct Config {
 | 
				
			||||||
	address string [required]
 | 
						address string [required]
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ pub fn cmd() cli.Command {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// print_log_list prints a list of logs.
 | 
					// print_log_list prints a list of logs.
 | 
				
			||||||
fn print_log_list(logs []db.BuildLog) ? {
 | 
					fn print_log_list(logs []BuildLog) ? {
 | 
				
			||||||
	data := logs.map([it.id.str(), it.repo_id.str(), it.start_time.str(),
 | 
						data := logs.map([it.id.str(), it.repo_id.str(), it.start_time.str(),
 | 
				
			||||||
		it.exit_code.str()])
 | 
							it.exit_code.str()])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
module db
 | 
					module db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sqlite
 | 
					import sqlite
 | 
				
			||||||
import models
 | 
					import models { BuildLog, GitRepo }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct VieterDb {
 | 
					struct VieterDb {
 | 
				
			||||||
	conn sqlite.DB
 | 
						conn sqlite.DB
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,6 +66,7 @@ pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	values_str := values.join(', ')
 | 
						values_str := values.join(', ')
 | 
				
			||||||
 | 
						// I think this is actual SQL & not the ORM language
 | 
				
			||||||
	query := 'update GitRepo set $values_str where id == $repo_id'
 | 
						query := 'update GitRepo set $values_str where id == $repo_id'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	db.conn.exec_none(query)
 | 
						db.conn.exec_none(query)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,31 +1,6 @@
 | 
				
			||||||
module db
 | 
					module db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import time
 | 
					import models { BuildLog }
 | 
				
			||||||
 | 
					 | 
				
			||||||
pub struct BuildLog {
 | 
					 | 
				
			||||||
pub:
 | 
					 | 
				
			||||||
	id         int       [primary; sql: serial]
 | 
					 | 
				
			||||||
	repo_id    int       [nonull]
 | 
					 | 
				
			||||||
	start_time time.Time [nonull]
 | 
					 | 
				
			||||||
	end_time   time.Time [nonull]
 | 
					 | 
				
			||||||
	arch       string    [nonull]
 | 
					 | 
				
			||||||
	exit_code  int       [nonull]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// str returns a string representation.
 | 
					 | 
				
			||||||
pub fn (bl &BuildLog) str() string {
 | 
					 | 
				
			||||||
	mut parts := [
 | 
					 | 
				
			||||||
		'id: $bl.id',
 | 
					 | 
				
			||||||
		'repo id: $bl.repo_id',
 | 
					 | 
				
			||||||
		'start time: $bl.start_time',
 | 
					 | 
				
			||||||
		'end time: $bl.end_time',
 | 
					 | 
				
			||||||
		'arch: $bl.arch',
 | 
					 | 
				
			||||||
		'exit code: $bl.exit_code',
 | 
					 | 
				
			||||||
	]
 | 
					 | 
				
			||||||
	str := parts.join('\n')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return str
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// get_build_logs returns all BuildLog's in the database.
 | 
					// get_build_logs returns all BuildLog's in the database.
 | 
				
			||||||
pub fn (db &VieterDb) get_build_logs() []BuildLog {
 | 
					pub fn (db &VieterDb) get_build_logs() []BuildLog {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					module models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub struct BuildLog {
 | 
				
			||||||
 | 
					pub:
 | 
				
			||||||
 | 
						id         int       [primary; sql: serial]
 | 
				
			||||||
 | 
						repo_id    int       [nonull]
 | 
				
			||||||
 | 
						start_time time.Time [nonull]
 | 
				
			||||||
 | 
						end_time   time.Time [nonull]
 | 
				
			||||||
 | 
						arch       string    [nonull]
 | 
				
			||||||
 | 
						exit_code  int       [nonull]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// str returns a string representation.
 | 
				
			||||||
 | 
					pub fn (bl &BuildLog) str() string {
 | 
				
			||||||
 | 
						mut parts := [
 | 
				
			||||||
 | 
							'id: $bl.id',
 | 
				
			||||||
 | 
							'repo id: $bl.repo_id',
 | 
				
			||||||
 | 
							'start time: $bl.start_time',
 | 
				
			||||||
 | 
							'end time: $bl.end_time',
 | 
				
			||||||
 | 
							'arch: $bl.arch',
 | 
				
			||||||
 | 
							'exit code: $bl.exit_code',
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
						str := parts.join('\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return str
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ import web
 | 
				
			||||||
import net.http
 | 
					import net.http
 | 
				
			||||||
import response { new_data_response, new_response }
 | 
					import response { new_data_response, new_response }
 | 
				
			||||||
import db
 | 
					import db
 | 
				
			||||||
import models { GitRepoArch }
 | 
					import models { GitRepo, GitRepoArch, GitRepoFilter }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// get_repos returns the current list of repos.
 | 
					// get_repos returns the current list of repos.
 | 
				
			||||||
['/api/repos'; get]
 | 
					['/api/repos'; get]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import db
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import util
 | 
					import util
 | 
				
			||||||
 | 
					import models { BuildLog }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// get_logs returns all build logs in the database. A 'repo' query param can
 | 
					// get_logs returns all build logs in the database. A 'repo' query param can
 | 
				
			||||||
// optionally be added to limit the list of build logs to that repository.
 | 
					// optionally be added to limit the list of build logs to that repository.
 | 
				
			||||||
| 
						 | 
					@ -97,7 +98,7 @@ fn (mut app App) post_log() web.Result {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Store log in db
 | 
						// Store log in db
 | 
				
			||||||
	log := db.BuildLog{
 | 
						log := BuildLog{
 | 
				
			||||||
		repo_id: repo_id
 | 
							repo_id: repo_id
 | 
				
			||||||
		start_time: start_time
 | 
							start_time: start_time
 | 
				
			||||||
		end_time: end_time
 | 
							end_time: end_time
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue