01/03: amelioration de la reponse json en mettant toutes les infos dans un objet 'info'
This is an automated email from the git hooks/post-receive script. New commit to branch bow-v2-go in repository bow. See https://gitlab.nuiton.org/chorem/bow.git commit e67e1d35bf6b8672ec9a9b8ec68e5306e735ccc2 Author: Benjamin <poussin@codelutin.com> Date: Wed May 20 22:56:37 2020 +0200 amelioration de la reponse json en mettant toutes les infos dans un objet 'info' --- pkg/repository/bookmarkRepository.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/repository/bookmarkRepository.go b/pkg/repository/bookmarkRepository.go index 8e1db09..978e8e5 100644 --- a/pkg/repository/bookmarkRepository.go +++ b/pkg/repository/bookmarkRepository.go @@ -47,22 +47,19 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags string, q := &query{sql: `WITH __all AS (select * from bookmark where uri=$1) SELECT json_agg(__all.*) as j FROM __all`} result, err = q.QueryString(currentUser, uri) } else { - tagsJSON := "{" + strings.Join(strings.Fields(tags), ",") + "}" + tagsJoined := strings.Join(strings.Fields(tags), ",") q := &query{sql: fmt.Sprintf(`WITH - __query AS (select * from bookmark where tags @> $1::text[]), - __orderby AS (select '%[1]s' as orderby), - __orderdesc AS (select to_json('%[2]s' = 'desc') as orderdesc), - __first AS (select %[3]d as first), - __limit AS (select %[4]d as limit), - __total AS (select count(id) as total from __query), + __query AS (select * from bookmark where tags @> string_to_array($1, ',')), + __info AS (select %[3]d as first, %[4]d as limit, count(id) as total, '%[1]s' as orderby, to_json('%[2]s' = 'desc') as orderdesc, $2::TEXT as tags, $3::TEXT as fulltext from __query), + __infoJson AS (select row_to_json(i.*) as info from __info i), __allTags AS (select unnest(tags) as tag from __query), __tags AS (select tag, count(tag) from __allTags group by tag order by 2 desc), __jsonTags AS (select ('[' || json_agg(a.tag) || ', ' || json_agg(a.count) || ']')::json as tags from __tags a), __result AS (select * from __query order by %[1]s %[2]s OFFSET %[3]d LIMIT %[4]d), __jsonResult AS (SELECT json_agg(r.*) as result FROM __result r) - select row_to_json(v) from (select * from __first, __limit, __total, __orderby, __orderdesc, __jsonTags, __jsonResult) v; + select row_to_json(v) from (select * from __infoJson, __jsonTags, __jsonResult) v; `, orderBy, orderDirection, first, maxResult)} - result, err = q.QueryString(currentUser, tagsJSON) + result, err = q.QueryString(currentUser, tagsJoined, tags, fulltext) } if err != nil { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm