New search for members + contacts on list + csv export

This commit is contained in:
William Bouzourène 2025-03-26 18:41:23 +01:00
parent 8044cb975a
commit e6c698c98d
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
5 changed files with 133 additions and 271 deletions

View file

@ -45,15 +45,7 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
// SQL qeury for results
sqlQuery := `--sql
SELECT people.id,
people.is_member,
people.is_contact,
people.first_name,
people.last_name,
people.address1,
people.postal_code,
people.city,
people.section_id,
SELECT people.*,
sections.name AS Section__name
FROM people
INNER JOIN sections
@ -328,6 +320,16 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
params.PageNumber,
)
var sqlPagination string
if params.PageSize > 0 {
sqlPagination = `--sql
LIMIT @pagination_limit
OFFSET @pagination_offset
`
sqlParams = append(sqlParams, sql.Named("pagination_limit", results.Pagination.PageSize))
sqlParams = append(sqlParams, sql.Named("pagination_offset", results.Pagination.Offset))
}
// Build and run paginated result query
sqlQuery = fmt.Sprintf(`--sql
%s
@ -335,12 +337,8 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
%s
GROUP BY people.id
ORDER BY CONCAT(people.last_name, people.first_name) COLLATE NOCASE ASC
LIMIT @pagination_limit
OFFSET @pagination_offset
`, sqlQuery, sqlFieldJoins, sqlFilters)
sqlParams = append(sqlParams, sql.Named("pagination_limit", results.Pagination.PageSize))
sqlParams = append(sqlParams, sql.Named("pagination_offset", results.Pagination.Offset))
%s
`, sqlQuery, sqlFieldJoins, sqlFilters, sqlPagination)
sqlResult := db.Raw(sqlQuery, sqlParams...).Scan(&results.Results)
if sqlResult.Error != nil {