forked from vieter-v/vieter
				
			feat(server): partial implementation of BuildLog API filter
							parent
							
								
									596da100b6
								
							
						
					
					
						commit
						31e903ebeb
					
				|  | @ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| ### Added | ||||
| 
 | ||||
| * Database migrations | ||||
| * Query parameters for GitRepo API to filter responses | ||||
| * Respective CLI flags for new GitRepo API parameters | ||||
| 
 | ||||
| ### Changed | ||||
| 
 | ||||
| * Refactor of main types into `models` module | ||||
| 
 | ||||
| ## [0.3.0-alpha.2](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0-alpha.2) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,13 +1,37 @@ | |||
| module db | ||||
| 
 | ||||
| import models { BuildLog } | ||||
| import models { BuildLog, BuildLogFilter } | ||||
| import time | ||||
| 
 | ||||
| // get_build_logs returns all BuildLog's in the database. | ||||
| pub fn (db &VieterDb) get_build_logs() []BuildLog { | ||||
| 	res := sql db.conn { | ||||
| 		select from BuildLog order by id | ||||
| pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog { | ||||
| 	mut where_parts := []string{} | ||||
| 
 | ||||
| 	if filter.repo != 0 { | ||||
| 		where_parts << 'repo_id == $filter.repo' | ||||
| 	} | ||||
| 
 | ||||
| 	if filter.before != time.Time{} { | ||||
| 		where_parts << 'start_time < $filter.before.unix_time()' | ||||
| 	} | ||||
| 
 | ||||
| 	if filter.after != time.Time{} { | ||||
| 		where_parts << 'start_time < $filter.after.unix_time()' | ||||
| 	} | ||||
| 
 | ||||
| 	where_str := if where_parts.len > 0 { | ||||
| 		' where ' + where_parts.map('($it)').join(' and ') | ||||
| 	} else { | ||||
| 		'' | ||||
| 	} | ||||
| 
 | ||||
| 	query := 'select from BuildLog' + where_str | ||||
| 	res := db.conn.exec(query) | ||||
| 
 | ||||
| /* 	res := sql db.conn { */ | ||||
| /* 		select from BuildLog where filter.repo == 0 || repo_id == filter.repo order by id */ | ||||
| /* 	} */ | ||||
| 
 | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,3 +26,16 @@ pub fn (bl &BuildLog) str() string { | |||
| 
 | ||||
| 	return str | ||||
| } | ||||
| 
 | ||||
| [params] | ||||
| pub struct BuildLogFilter { | ||||
| pub mut: | ||||
| 	limit                u64 = 25 | ||||
| 	offset               u64 | ||||
| 	repo                 int | ||||
| 	before               time.Time | ||||
| 	after                time.Time | ||||
| 	exit_codes_whitelist []u8 | ||||
| 	exit_codes_blacklist []u8 | ||||
| 	arch                 string | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue