fix find_citizen_opinions_by_target_ids.sql
change opinion_list.target to array
This commit is contained in:
@@ -8,7 +8,7 @@ begin
|
|||||||
delete from opinion_list;
|
delete from opinion_list;
|
||||||
|
|
||||||
insert into opinion_list (id, name, target)
|
insert into opinion_list (id, name, target)
|
||||||
select uuid_in(md5('opinion_list'||row_number() over ())::cstring), 'Opinion'||row_number() over (), 'article'
|
select uuid_in(md5('opinion_list'||row_number() over ())::cstring), 'Opinion'||row_number() over (), '{article}'
|
||||||
from generate_series(0,20);
|
from generate_series(0,20);
|
||||||
|
|
||||||
for i in 0..9 loop
|
for i in 0..9 loop
|
||||||
|
|||||||
@@ -5,14 +5,24 @@ create or replace function find_citizen_opinions_by_target_ids(
|
|||||||
) language plpgsql as
|
) language plpgsql as
|
||||||
$$
|
$$
|
||||||
begin
|
begin
|
||||||
|
select json_agg(t) into resource
|
||||||
|
from (
|
||||||
select
|
select
|
||||||
jsonb_agg(find_citizen_opinions_by_target_id(_citizen_id, o)) into resource
|
o.*,
|
||||||
from unnest(_ids) o
|
ol.name
|
||||||
|
from opinion as o
|
||||||
|
join opinion_list ol on o.opinion = ol.id
|
||||||
|
|
||||||
|
where target_id = any(_ids)
|
||||||
|
and created_by_id = _citizen_id
|
||||||
|
|
||||||
order by
|
order by
|
||||||
_ids
|
ol.name
|
||||||
limit 100;
|
limit 100
|
||||||
|
) t;
|
||||||
end;
|
end;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
-- drop function if exists find_citizen_votes_by_target_ids(uuid, uuid[], regclass);
|
-- drop function if exists find_citizen_votes_by_target_ids(uuid, uuid[], regclass);
|
||||||
|
|
||||||
|
-- select * from find_citizen_opinions_by_target_ids('045b6e9e-5a9e-d9b0-75d4-e51f0bc6cd21', '{32a18b25-507d-49d8-5168-7675fb6a7b8c, 429bfd8c-ebc2-09ac-227f-28bcdaa91d84, 550f4543-35a3-9910-e493-70d26b931473}')
|
||||||
@@ -506,8 +506,8 @@ create table resource_view
|
|||||||
create table opinion_list
|
create table opinion_list
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
name text not null,
|
name text not null unique,
|
||||||
target text null,
|
target text[] null,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
deleted_at timestamptz null
|
deleted_at timestamptz null
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -59,13 +59,13 @@ begin
|
|||||||
|
|
||||||
|
|
||||||
insert into opinion_list(id, name, target)
|
insert into opinion_list(id, name, target)
|
||||||
values (opinion1, 'Opinion1', (created_article->>'id')::uuid);
|
values (opinion1, 'Opinion1', '{article}');
|
||||||
|
|
||||||
insert into opinion_list(id, name, target)
|
insert into opinion_list(id, name, target)
|
||||||
values (opinion2, 'Opinion2', (created_article->>'id')::uuid);
|
values (opinion2, 'Opinion2', '{article}');
|
||||||
|
|
||||||
insert into opinion_list(name, target)
|
insert into opinion_list(name, target)
|
||||||
values ('Opinion3', (created_article->>'id')::uuid);
|
values ('Opinion3', '{article}');
|
||||||
|
|
||||||
perform opinion(
|
perform opinion(
|
||||||
reference => 'article'::regclass,
|
reference => 'article'::regclass,
|
||||||
@@ -84,12 +84,8 @@ begin
|
|||||||
from find_citizen_opinions_by_target_id(_citizen_id, (created_article->>'id')::uuid) o),
|
from find_citizen_opinions_by_target_id(_citizen_id, (created_article->>'id')::uuid) o),
|
||||||
'The opinion must have a name';
|
'The opinion must have a name';
|
||||||
|
|
||||||
raise notice '%', (
|
|
||||||
select o
|
|
||||||
from find_citizen_opinions_by_target_ids(_citizen_id, array[(created_article->>'id')::uuid]) o);
|
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
select (o#>>'{0, 0, name}') = 'Opinion1'
|
select (o#>>'{0, name}') = 'Opinion1'
|
||||||
from find_citizen_opinions_by_target_ids(_citizen_id, array[(created_article->>'id')::uuid]) o),
|
from find_citizen_opinions_by_target_ids(_citizen_id, array[(created_article->>'id')::uuid]) o),
|
||||||
'The first opinion must have a name';
|
'The first opinion must have a name';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user