update postgresjson
This commit is contained in:
@@ -15,6 +15,7 @@ import fr.dcproject.routes.*
|
||||
import fr.dcproject.security.voter.ArticleVoter
|
||||
import fr.dcproject.security.voter.AuthorizationVoter
|
||||
import fr.dcproject.security.voter.CitizenVoter
|
||||
import fr.dcproject.security.voter.CommentVoter
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import io.ktor.application.Application
|
||||
import io.ktor.application.call
|
||||
@@ -104,7 +105,8 @@ fun Application.module() {
|
||||
install(AuthorizationVoter) {
|
||||
voters = mutableListOf(
|
||||
ArticleVoter(),
|
||||
CitizenVoter()
|
||||
CitizenVoter(),
|
||||
CommentVoter()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,4 +15,4 @@ class Article(
|
||||
UuidEntity(id),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
CreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
@@ -12,7 +12,7 @@ class Constitution(
|
||||
): UuidEntity(id),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
CreatedBy<Citizen> by EntityCreatedByImp(createdBy) {
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy) {
|
||||
|
||||
init{
|
||||
titles.forEachIndexed { index, title ->
|
||||
@@ -28,5 +28,5 @@ class Constitution(
|
||||
createdBy: Citizen? = null
|
||||
): UuidEntity(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
CreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.*
|
||||
import java.util.*
|
||||
|
||||
interface ExtraI <T: EntityI<UUID>>:
|
||||
EntityI<UUID>,
|
||||
EntityCreatedAt {
|
||||
var citizen: Citizen
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<Citizen>{
|
||||
var target: T
|
||||
}
|
||||
|
||||
abstract class Extra<T: EntityI<UUID>>(
|
||||
id: UUID? = UUID.randomUUID(),
|
||||
override var citizen: Citizen
|
||||
createdBy: Citizen
|
||||
):
|
||||
ExtraI<T>,
|
||||
UuidEntity(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp()
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
@@ -4,6 +4,6 @@ import java.util.*
|
||||
|
||||
class Follow <T: UuidEntity> (
|
||||
id: UUID = UUID.randomUUID(),
|
||||
citizen: Citizen,
|
||||
createdBy: Citizen,
|
||||
override var target: T
|
||||
): Extra<T>(id, citizen)
|
||||
): Extra<T>(id, createdBy)
|
||||
|
||||
@@ -28,7 +28,7 @@ open class Follow <T: UuidEntity>(override var requester: Requester): Repository
|
||||
return requester.run {
|
||||
getFunction("find_follows_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
"created_by_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ open class Follow <T: UuidEntity>(override var requester: Requester): Repository
|
||||
.sendQuery(
|
||||
"reference" to reference,
|
||||
"target_id" to follow.target.id,
|
||||
"citizen_id" to follow.citizen.id
|
||||
"created_by_id" to follow.createdBy?.id
|
||||
)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ open class Follow <T: UuidEntity>(override var requester: Requester): Repository
|
||||
.sendQuery(
|
||||
"reference" to reference,
|
||||
"target_id" to follow.target.id,
|
||||
"citizen_id" to follow.citizen.id
|
||||
"created_by_id" to follow.createdBy?.id
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class FollowArticle (requester: Requester): Follow<ArticleEntity>(requester) {
|
||||
return requester.run {
|
||||
getFunction("find_follows_article_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
"created_by_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class FollowConstitution (requester: Requester): Follow<ConstitutionEntity>(requ
|
||||
return requester.run {
|
||||
getFunction("find_follows_constitution_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
"created_by_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ object FollowArticlePaths {
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.followArticle(repo: FollowArticleRepository) {
|
||||
post<FollowArticlePaths.ArticleFollowRequest> {
|
||||
repo.follow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
repo.follow(FollowEntity(target = it.article, createdBy = currentCitizen))
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
|
||||
delete<FollowArticlePaths.ArticleFollowRequest> {
|
||||
repo.unfollow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
repo.unfollow(FollowEntity(target = it.article, createdBy = currentCitizen))
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ object FollowConstitutionPaths {
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.followConstitution(repo: FollowConstitutionRepository) {
|
||||
post<FollowConstitutionPaths.ConstitutionFollowRequest> {
|
||||
repo.follow(FollowEntity(target = it.constitution, citizen = currentCitizen2))
|
||||
repo.follow(FollowEntity(target = it.constitution, createdBy = currentCitizen2))
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
|
||||
delete<FollowConstitutionPaths.ConstitutionFollowRequest> {
|
||||
repo.unfollow(FollowEntity(target = it.constitution, citizen = currentCitizen2))
|
||||
repo.unfollow(FollowEntity(target = it.constitution, createdBy = currentCitizen2))
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ declare
|
||||
begin
|
||||
delete from follow;
|
||||
|
||||
insert into follow_article (id, citizen_id, target_id)
|
||||
insert into follow_article (id, created_by_id, target_id)
|
||||
select
|
||||
uuid_in(md5('follow_article'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -13,7 +13,7 @@ begin
|
||||
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5)) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into follow_constitution (id, citizen_id, target_id)
|
||||
insert into follow_constitution (id, created_by_id, target_id)
|
||||
select
|
||||
uuid_in(md5('follow_constitution'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -21,7 +21,7 @@ begin
|
||||
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5)) z
|
||||
join (select *, row_number() over () rn from constitution) a using (rn);
|
||||
|
||||
insert into follow_citizen (id, citizen_id, target_id)
|
||||
insert into follow_citizen (id, created_by_id, target_id)
|
||||
select
|
||||
uuid_in(md5('follow_citizen'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
|
||||
@@ -5,7 +5,7 @@ declare
|
||||
begin
|
||||
delete from comment;
|
||||
|
||||
insert into comment_on_article (id, citizen_id, target_id, content)
|
||||
insert into comment_on_article (id, created_by_id, target_id, content)
|
||||
select
|
||||
uuid_in(md5('comment_on_article'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -14,7 +14,7 @@ begin
|
||||
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into comment_on_article (id, citizen_id, target_id, content, parent_id)
|
||||
insert into comment_on_article (id, created_by_id, target_id, content, parent_id)
|
||||
select
|
||||
uuid_in(md5('comment_on_article_2'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -24,7 +24,7 @@ begin
|
||||
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article) a using (rn);
|
||||
|
||||
insert into comment_on_article (id, citizen_id, target_id, content, parent_id)
|
||||
insert into comment_on_article (id, created_by_id, target_id, content, parent_id)
|
||||
select
|
||||
uuid_in(md5('comment_on_article_3'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -34,7 +34,7 @@ begin
|
||||
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article where parent_id is not null) a using (rn);
|
||||
|
||||
insert into comment_on_constitution (id, citizen_id, target_id, content)
|
||||
insert into comment_on_constitution (id, created_by_id, target_id, content)
|
||||
select
|
||||
uuid_in(md5('comment_on_constitution'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
|
||||
@@ -8,7 +8,7 @@ begin
|
||||
delete from vote_for_comment_on_article;
|
||||
delete from vote_for_comment_on_constitution;
|
||||
raise notice '%', article_count;
|
||||
insert into vote_for_article (id, citizen_id, target_id, note, anonymous)
|
||||
insert into vote_for_article (id, created_by_id, target_id, note, anonymous)
|
||||
select
|
||||
uuid_in(md5('vote_for_article'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -18,7 +18,7 @@ raise notice '%', article_count;
|
||||
from (select *, row_number() over ()+g % (article_count+7) rn, g from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into vote_for_constitution (id, citizen_id, target_id, note, anonymous)
|
||||
insert into vote_for_constitution (id, created_by_id, target_id, note, anonymous)
|
||||
select
|
||||
uuid_in(md5('vote_for_constitution'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -28,7 +28,7 @@ raise notice '%', article_count;
|
||||
from (select *, row_number() over () % (article_count+7) rn, g from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from constitution) a using (rn);
|
||||
|
||||
insert into vote_for_comment_on_article (id, citizen_id, target_id, note, anonymous)
|
||||
insert into vote_for_comment_on_article (id, created_by_id, target_id, note, anonymous)
|
||||
select
|
||||
uuid_in(md5('vote_for_comment_on_article'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
@@ -38,7 +38,7 @@ raise notice '%', article_count;
|
||||
from (select *, row_number() over () % (article_count+7) rn, g from citizen, lateral generate_series(1, 3) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article) a using (rn);
|
||||
|
||||
insert into vote_for_comment_on_constitution (id, citizen_id, target_id, note, anonymous)
|
||||
insert into vote_for_comment_on_constitution (id, created_by_id, target_id, note, anonymous)
|
||||
select
|
||||
uuid_in(md5('vote_for_comment_on_constitution'||row_number() over ())::cstring),
|
||||
z.id,
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
create or replace function comment(reference regclass, target_id uuid, citizen_id uuid, content text, parent_id uuid default null, out id uuid)
|
||||
create or replace function comment(reference regclass, target_id uuid, created_by_id uuid, content text, parent_id uuid default null, out id uuid)
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_citizen_id alias for citizen_id;
|
||||
_created_by_id alias for created_by_id;
|
||||
_target_id alias for target_id;
|
||||
_content alias for content;
|
||||
_parent_id alias for parent_id;
|
||||
_id alias for id;
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
insert into comment_on_article (citizen_id, target_id, content, parent_id)
|
||||
values (_citizen_id, _target_id, _content, _parent_id)
|
||||
insert into comment_on_article (created_by_id, target_id, content, parent_id)
|
||||
values (_created_by_id, _target_id, _content, _parent_id)
|
||||
returning comment_on_article.id into _id;
|
||||
elseif reference = 'constitution'::regclass then
|
||||
insert into comment_on_constitution (citizen_id, target_id, content, parent_id)
|
||||
values (_citizen_id, _target_id, _content, _parent_id)
|
||||
insert into comment_on_constitution (created_by_id, target_id, content, parent_id)
|
||||
values (_created_by_id, _target_id, _content, _parent_id)
|
||||
returning comment_on_constitution.id into _id;
|
||||
else
|
||||
raise exception 'comment with target as "%", is no implemented', reference::text;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
create or replace function find_comment_by_id(
|
||||
_id uuid,
|
||||
out resource json
|
||||
) language plpgsql as
|
||||
$$
|
||||
begin
|
||||
select to_json(t)
|
||||
into resource
|
||||
from (
|
||||
select
|
||||
com.*,
|
||||
json_build_object('id', com.target_id) as target,
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from "comment" as com
|
||||
where id = _id
|
||||
) as t;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists find_comment_by_id(uuid, out json);
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_comments_article_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -13,9 +13,9 @@ begin
|
||||
select
|
||||
com.*,
|
||||
find_article_by_id(com.target_id) as target,
|
||||
find_citizen_by_id(com.citizen_id) as citizen
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from comment as com
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
and target_reference = 'article'::regclass
|
||||
order by created_at desc,
|
||||
com.created_at desc
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_comments_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -7,15 +7,15 @@ create or replace function find_comments_by_citizen(
|
||||
) language plpgsql as
|
||||
$$
|
||||
begin
|
||||
select json_agg(t), (select count(id) from "comment" where citizen_id = _citizen_id)
|
||||
select json_agg(t), (select count(id) from "comment" where created_by_id = _created_by_id)
|
||||
into resource, total
|
||||
from (
|
||||
select
|
||||
com.*,
|
||||
json_build_object('id', com.target_id) as target,
|
||||
find_citizen_by_id(com.citizen_id) as citizen
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from "comment" as com
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
order by created_at desc,
|
||||
com.created_at desc
|
||||
limit "limit" offset "offset"
|
||||
|
||||
@@ -13,7 +13,7 @@ begin
|
||||
select
|
||||
com.*,
|
||||
json_build_object('id', com.target_id) as target,
|
||||
find_citizen_by_id(com.citizen_id) as citizen
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from "comment" as com
|
||||
where com.parents_ids @> array[_parent_id]
|
||||
order by com.parents_ids nulls first, created_at desc,
|
||||
|
||||
@@ -13,7 +13,7 @@ begin
|
||||
select
|
||||
com.*,
|
||||
json_build_object('id', com.target_id) as target,
|
||||
find_citizen_by_id(com.citizen_id) as citizen
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from "comment" as com
|
||||
where com.target_id = _target_id
|
||||
order by com.parents_ids nulls first, created_at desc,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_comments_constitution_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -13,9 +13,9 @@ begin
|
||||
select
|
||||
com.*,
|
||||
find_constitution_by_id(com.target_id) as target,
|
||||
find_citizen_by_id(com.citizen_id) as citizen
|
||||
find_citizen_by_id(com.created_by_id) as created_by
|
||||
from comment as com
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
and target_reference = 'constitution'::regclass
|
||||
order by created_at desc,
|
||||
com.created_at desc
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_follows_article_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -13,9 +13,9 @@ begin
|
||||
select
|
||||
f.*,
|
||||
find_article_by_id(f.target_id) as target,
|
||||
find_citizen_by_id(f.citizen_id) as citizen
|
||||
find_citizen_by_id(f.created_by_id) as created_by
|
||||
from follow as f
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
order by created_at desc,
|
||||
f.created_at desc
|
||||
limit "limit" offset "offset"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_follows_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -13,9 +13,9 @@ begin
|
||||
select
|
||||
f.*,
|
||||
json_build_object('id', f.target_id) as target,
|
||||
find_citizen_by_id(f.citizen_id) as citizen
|
||||
find_citizen_by_id(f.created_by_id) as created_by
|
||||
from follow as f
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
order by created_at desc,
|
||||
f.created_at desc
|
||||
limit "limit" offset "offset"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create or replace function find_follows_constitution_by_citizen(
|
||||
_citizen_id uuid,
|
||||
_created_by_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
@@ -13,9 +13,9 @@ begin
|
||||
select
|
||||
f.*,
|
||||
find_constitution_by_id(f.target_id) as target,
|
||||
find_citizen_by_id(f.citizen_id) as citizen
|
||||
find_citizen_by_id(f.created_by_id) as created_by
|
||||
from follow as f
|
||||
where citizen_id = _citizen_id
|
||||
where created_by_id = _created_by_id
|
||||
order by created_at desc,
|
||||
f.created_at desc
|
||||
limit "limit" offset "offset"
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
create or replace function follow(reference regclass, _target_id uuid, _citizen_id uuid) returns void
|
||||
create or replace function follow(reference regclass, _target_id uuid, _created_by_id uuid) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
insert into follow_article (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id)
|
||||
on conflict (citizen_id, target_id) do nothing;
|
||||
insert into follow_article (created_by_id, target_id)
|
||||
values (_created_by_id, _target_id)
|
||||
on conflict (created_by_id, target_id) do nothing;
|
||||
elseif reference = 'constitution'::regclass then
|
||||
insert into follow_constitution (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id)
|
||||
on conflict (citizen_id, target_id) do nothing;
|
||||
insert into follow_constitution (created_by_id, target_id)
|
||||
values (_created_by_id, _target_id)
|
||||
on conflict (created_by_id, target_id) do nothing;
|
||||
elseif reference = 'citizen'::regclass then
|
||||
insert into follow_citizen (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id)
|
||||
on conflict (citizen_id, target_id) do nothing;
|
||||
insert into follow_citizen (created_by_id, target_id)
|
||||
values (_created_by_id, _target_id)
|
||||
on conflict (created_by_id, target_id) do nothing;
|
||||
else
|
||||
raise exception '% no implemented', reference::text;
|
||||
end if;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
create or replace function unfollow(reference regclass, _target_id uuid, _citizen_id uuid) returns void
|
||||
create or replace function unfollow(reference regclass, _target_id uuid, _created_by_id uuid) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
begin
|
||||
delete
|
||||
from follow f
|
||||
where f.citizen_id = _citizen_id
|
||||
where f.created_by_id = _created_by_id
|
||||
and f.target_id = _target_id
|
||||
and f.target_reference = reference;
|
||||
end;
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
create or replace function vote(reference regclass, _target_id uuid, _citizen_id uuid, _note int, _anonymous bool default true) returns void
|
||||
create or replace function vote(reference regclass, _target_id uuid, _created_by_id uuid, _note int, _anonymous bool default true) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
insert into vote_for_article (citizen_id, target_id, note, anonymous)
|
||||
values (_citizen_id, _target_id, _note, _anonymous)
|
||||
on conflict (citizen_id, target_id) do update set
|
||||
insert into vote_for_article (created_by_id, target_id, note, anonymous)
|
||||
values (_created_by_id, _target_id, _note, _anonymous)
|
||||
on conflict (created_by_id, target_id) do update set
|
||||
note = excluded.note,
|
||||
anonymous = excluded.anonymous;
|
||||
elseif reference = 'constitution'::regclass then
|
||||
insert into vote_for_constitution (citizen_id, target_id, note, anonymous)
|
||||
values (_citizen_id, _target_id, _note, _anonymous)
|
||||
on conflict (citizen_id, target_id) do update set
|
||||
insert into vote_for_constitution (created_by_id, target_id, note, anonymous)
|
||||
values (_created_by_id, _target_id, _note, _anonymous)
|
||||
on conflict (created_by_id, target_id) do update set
|
||||
note = excluded.note,
|
||||
anonymous = excluded.anonymous;
|
||||
elseif reference = 'comment_on_article'::regclass then
|
||||
insert into vote_for_comment_on_article (citizen_id, target_id, note, anonymous)
|
||||
values (_citizen_id, _target_id, _note, _anonymous)
|
||||
on conflict (citizen_id, target_id) do update set
|
||||
insert into vote_for_comment_on_article (created_by_id, target_id, note, anonymous)
|
||||
values (_created_by_id, _target_id, _note, _anonymous)
|
||||
on conflict (created_by_id, target_id) do update set
|
||||
note = excluded.note,
|
||||
anonymous = excluded.anonymous;
|
||||
elseif reference = 'comment_on_constitution'::regclass then
|
||||
insert into vote_for_comment_on_constitution (citizen_id, target_id, note, anonymous)
|
||||
values (_citizen_id, _target_id, _note, _anonymous)
|
||||
on conflict (citizen_id, target_id) do update set
|
||||
insert into vote_for_comment_on_constitution (created_by_id, target_id, note, anonymous)
|
||||
values (_created_by_id, _target_id, _note, _anonymous)
|
||||
on conflict (created_by_id, target_id) do update set
|
||||
note = excluded.note,
|
||||
anonymous = excluded.anonymous;
|
||||
else
|
||||
|
||||
@@ -186,43 +186,43 @@ create table extra
|
||||
(
|
||||
id uuid default uuid_generate_v4() not null primary key,
|
||||
created_at timestamptz default now() not null,
|
||||
citizen_id uuid not null references citizen (id),
|
||||
created_by_id uuid not null references citizen (id),
|
||||
target_id uuid not null,
|
||||
target_reference regclass not null
|
||||
);
|
||||
|
||||
create table follow
|
||||
(
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (extra);
|
||||
|
||||
create table follow_article
|
||||
(
|
||||
target_reference regclass default 'article'::regclass not null,
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
foreign key (target_id) references article (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (follow);
|
||||
|
||||
create table follow_constitution
|
||||
(
|
||||
target_reference regclass default 'constitution'::regclass not null,
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
foreign key (target_id) references constitution (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (follow);
|
||||
|
||||
create table follow_citizen
|
||||
(
|
||||
target_reference regclass default 'citizen'::regclass not null,
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
foreign key (target_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (follow);
|
||||
|
||||
|
||||
@@ -231,9 +231,9 @@ create table comment
|
||||
(
|
||||
updated_at timestamptz default now() not null check ( updated_at >= created_at ),
|
||||
"content" text not null check ( content != '' and length(content) < 4096),
|
||||
parent_id uuid references comment (id),
|
||||
parent_id uuid references comment (id),
|
||||
parents_ids uuid[],
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id)
|
||||
) inherits (extra);
|
||||
|
||||
@@ -244,7 +244,7 @@ create or replace function set_comment_parents_ids() returns trigger
|
||||
language plpgsql as
|
||||
$$
|
||||
begin
|
||||
if(new.parent_id is not null) then
|
||||
if (new.parent_id is not null) then
|
||||
new.parents_ids = (
|
||||
select com.parents_ids || com.id
|
||||
from "comment" com
|
||||
@@ -267,7 +267,7 @@ execute procedure set_comment_parents_ids();
|
||||
create table comment_on_article
|
||||
(
|
||||
target_reference regclass default 'article'::regclass not null,
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
foreign key (target_id) references article (id),
|
||||
foreign key (parent_id) references comment_on_article (id),
|
||||
primary key (id)
|
||||
@@ -285,7 +285,7 @@ execute procedure set_comment_parents_ids();
|
||||
create table comment_on_constitution
|
||||
(
|
||||
target_reference regclass default 'constitution'::regclass not null,
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
foreign key (target_id) references constitution (id),
|
||||
foreign key (parent_id) references comment_on_constitution (id),
|
||||
primary key (id)
|
||||
@@ -306,45 +306,45 @@ create table vote
|
||||
(
|
||||
anonymous boolean default true not null,
|
||||
note int not null check ( note >= -1 and note <= 1 ),
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (extra);
|
||||
|
||||
create table vote_for_article
|
||||
(
|
||||
target_reference regclass default 'article'::regclass not null,
|
||||
foreign key (target_id) references article (id),
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (vote);
|
||||
|
||||
create table vote_for_constitution
|
||||
(
|
||||
target_reference regclass default 'constitution'::regclass not null,
|
||||
foreign key (target_id) references constitution (id),
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (vote);
|
||||
|
||||
create table vote_for_comment_on_article
|
||||
(
|
||||
target_reference regclass default 'comment_on_article'::regclass not null,
|
||||
foreign key (target_id) references comment_on_article (id),
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (vote);
|
||||
|
||||
create table vote_for_comment_on_constitution
|
||||
(
|
||||
target_reference regclass default 'comment_on_constitution'::regclass not null,
|
||||
foreign key (target_id) references comment_on_constitution (id),
|
||||
foreign key (citizen_id) references citizen (id),
|
||||
foreign key (created_by_id) references citizen (id),
|
||||
primary key (id),
|
||||
unique (citizen_id, target_id)
|
||||
unique (created_by_id, target_id)
|
||||
) inherits (vote);
|
||||
|
||||
-- Stats
|
||||
|
||||
@@ -21,7 +21,7 @@ class FollowTest {
|
||||
@Language("JSON")
|
||||
private val followJson: String = """{
|
||||
"id":"bae81585-d985-4d7a-9b58-3a13e911688a",
|
||||
"citizen":{
|
||||
"created_by":{
|
||||
"id":"4a87ad24-187a-46a8-97ab-00b30a24e561",
|
||||
"name":{
|
||||
"first_name":"Jaque",
|
||||
@@ -76,7 +76,7 @@ class FollowTest {
|
||||
createdBy = citizen
|
||||
)
|
||||
val follow = Follow(
|
||||
citizen = citizen,
|
||||
createdBy = citizen,
|
||||
target = article
|
||||
)
|
||||
follow.serialize().contains("""Hello world!""") shouldBe true
|
||||
|
||||
@@ -36,7 +36,7 @@ Feature: Auth routes
|
||||
When I send a POST request to "/login" with body:
|
||||
"""
|
||||
{
|
||||
"name": "username1",
|
||||
"name": "username-1",
|
||||
"password": "azerty"
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -50,7 +50,7 @@ begin
|
||||
select "comment"(
|
||||
reference => 'article'::regclass,
|
||||
target_id => (created_article->>'id')::uuid,
|
||||
citizen_id => _citizen_id,
|
||||
created_by_id => _citizen_id,
|
||||
content => 'Ho my god !'::text
|
||||
) into _comment_id;
|
||||
assert (select count(*) = 1 from "comment"), 'comment must be inserted';
|
||||
@@ -86,7 +86,7 @@ begin
|
||||
select "comment"(
|
||||
reference => 'article'::regclass,
|
||||
target_id => (created_article->>'id')::uuid,
|
||||
citizen_id => _citizen_id,
|
||||
created_by_id => _citizen_id,
|
||||
content => 'God not exist'::text,
|
||||
parent_id => _comment_id::uuid
|
||||
) into _comment_id_response;
|
||||
@@ -94,7 +94,7 @@ begin
|
||||
select "comment"(
|
||||
reference => 'article'::regclass,
|
||||
target_id => (created_article->>'id')::uuid,
|
||||
citizen_id => _citizen_id,
|
||||
created_by_id => _citizen_id,
|
||||
content => 'are you really sure ?'::text,
|
||||
parent_id => _comment_id_response::uuid
|
||||
) into _comment_id_response2;
|
||||
|
||||
@@ -41,7 +41,7 @@ begin
|
||||
perform vote(
|
||||
reference => 'article'::regclass,
|
||||
_target_id => (created_article->>'id')::uuid,
|
||||
_citizen_id => _citizen_id,
|
||||
_created_by_id => _citizen_id,
|
||||
_note => 1
|
||||
);
|
||||
assert (select count(*) = 1 from vote_for_article), 'vote must be inserted';
|
||||
@@ -50,7 +50,7 @@ begin
|
||||
perform vote(
|
||||
reference => 'article'::regclass,
|
||||
_target_id => (created_article->>'id')::uuid,
|
||||
_citizen_id => _citizen_id,
|
||||
_created_by_id => _citizen_id,
|
||||
_note => -1
|
||||
);
|
||||
assert (select count(*) = 1 from vote_for_article), 'vote must be inserted';
|
||||
@@ -60,7 +60,7 @@ begin
|
||||
perform vote(
|
||||
reference => 'article'::regclass,
|
||||
_target_id => (created_article->>'id')::uuid,
|
||||
_citizen_id => _citizen_id,
|
||||
_created_by_id => _citizen_id,
|
||||
_note => -10
|
||||
);
|
||||
assert false, 'vote must be throw exception if note is not -1, 0 or 1';
|
||||
|
||||
Reference in New Issue
Block a user