This is simple API create with support of Spring Boot, maven and Java.
################################################### ####### PLEASE READ THIS FILE WHOLE FIRST ######### ###################################################
1. sub-topics : do we have here only topic OR topic and sub-topic entity both
2. Topic which are linked with : a Topic can have multiple parents or not
. I assumed the assessment with single entity Topic which can have multiple children and multiple parents. I have solved assessment following this only.
1. create table topic (id integer generated by default as identity, name varchar(255), primary key (id));
2. create table topic_references_to (references_from_id integer not null, references_to_id integer not null, primary key (references_from_id, references_to_id));
3. alter table topic_references_to add constraint FKml4w8u5l3lml9qs3kmwiy2x4h foreign key (references_to_id) references topic
4. alter table topic_references_to add constraint FKdtfrnjhltngh7lbjn869dhx13 foreign key (references_from_id) references topic
INSERT INTO topic(id,name) VALUES (1, 'first');
INSERT INTO topic(id,name) VALUES (2, 'second');
INSERT INTO topic(id,name) VALUES (3, 'third');
insert into TOPIC(id,name) values (4, 'fourth');
insert into TOPIC(id,name) values (5, 'fifth');
insert into TOPIC(id,name) values (6, 'sixth');
insert into TOPIC(id,name) values (7, 'seventh');
insert into TOPIC(id,name) values (8, 'eighth');
insert into TOPIC(id,name) values (9, 'nine');
insert into TOPIC(id,name) values (10, 'ten');
insert into TOPIC(id,name) values (11, 'eleven');
insert into TOPIC_REFERENCES_TO values(1,2);
insert into TOPIC_REFERENCES_TO values(1,3);
insert into TOPIC_REFERENCES_TO values(4,3);
insert into TOPIC_REFERENCES_TO values(5,3);
insert into TOPIC_REFERENCES_TO values(3,4);
insert into TOPIC_REFERENCES_TO values(5,4);
insert into TOPIC_REFERENCES_TO values(1,4);
insert into TOPIC_REFERENCES_TO values(2,5);
insert into TOPIC_REFERENCES_TO values(5,1);
insert into TOPIC_REFERENCES_TO values(6,4);
insert into TOPIC_REFERENCES_TO values(5,6);
insert into TOPIC_REFERENCES_TO values(7,8);
insert into TOPIC_REFERENCES_TO values(8,9);
insert into TOPIC_REFERENCES_TO values(7,10);
insert into TOPIC_REFERENCES_TO values(10,11);
1) find all Topic which are linked with at least three Topics :
select * from TOPIC where id in (select ft.REFERENCES_TO_ID from TOPIC_REFERENCES_TO ft group by ft.REFERENCES_TO_ID having count(distinct ft.REFERENCES_FROM_ID) > 2);
2) find all Topic which are having one child and one parent :
select * from TOPIC where id in (select ft.REFERENCES_TO_ID from TOPIC_REFERENCES_TO ft group by ft.REFERENCES_TO_ID having count(distinct ft.REFERENCES_FROM_ID) = 1) and
id in (select ft.REFERENCES_FROM_ID from TOPIC_REFERENCES_TO ft group by ft.REFERENCES_FROM_ID having count(distinct ft.REFERENCES_TO_ID) = 1);
3) find all Topic which are placed at 3rd level in the hierarchy :
select * from TOPIC t where t.ID in (select trt4.REFERENCES_TO_ID from TOPIC_REFERENCES_TO trt4 where trt4.REFERENCES_FROM_ID in (select trt1.REFERENCES_TO_ID from TOPIC_REFERENCES_TO trt1 where trt1.REFERENCES_FROM_ID not in (select distinct trt2.REFERENCES_TO_ID from TOPIC_REFERENCES_TO trt2)));
. please hit http://localhost:8080/topics first to have automatic dummy data creation happen with blank body
1) find all Topic which are linked with at least three Topics :
http://localhost:8080/linkedTopicsWithThree
2) find all Topic which are having one child and one parent :
http://localhost:8080/oneParentOneChild
3) find all Topic which are placed at 3rd level in the hierarchy :
http://localhost:8080/topicsAtThirdPlace
. To get Swagger UI hit below URL :
http://localhost:8080/swagger-ui.html
. Under Topic Controller Tab :
please hit POST : topics first to have automatic dummy data creation happen with blank body
1) find all Topic which are linked with at least three Topics :
GET : linkedTopicsWithThree
2) find all Topic which are having one child and one parent :
GET : oneParentOneChild
3) find all Topic which are placed at 3rd level in the hierarchy :
GET : topicsAtThirdPlace
4) find all topics
GET : list
- through eclipse : run as Java Application : com.topic.TopicApplication file
- through maven : a. mvn clean install b. Execute from command line : java -jar TopicApp-0.0.1-SNAPSHOT.jar