diff --git a/Tithe-Spring/src/main/java/com/tithe/controller/query/TitheQueries.java b/Tithe-Spring/src/main/java/com/tithe/controller/query/TitheQueries.java new file mode 100755 index 0000000..53a027c --- /dev/null +++ b/Tithe-Spring/src/main/java/com/tithe/controller/query/TitheQueries.java @@ -0,0 +1,76 @@ +/** + * + */ +package com.tithe.controller.query; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.graphql.data.method.annotation.Argument; +import org.springframework.graphql.data.method.annotation.QueryMapping; +import org.springframework.stereotype.Controller; + +import com.tithe.model.AnnualTitheTotalInterface; +import com.tithe.service.query.TitheQueryService; + +/** + * @author Ashish Sam T George + * + */ +@Controller +public class TitheQueries { + + @Autowired + private TitheQueryService titheQueryService; + + @QueryMapping(name = "getCurrentYearPersonTitheTotal") + public Double getCurrentYearPersonTitheTotal(@Argument(name = "personId") Long personId){ + return titheQueryService.getCurrentYearPersonTitheTotal(personId); + } + + @QueryMapping(name = "getAnnualPersonTitheTotal") + public List getAnnualPersonTitheTotal(@Argument(name = "personId") Long personId){ + return titheQueryService.getAnnualPersonTitheTotal(personId); + } + + @QueryMapping(name = "getCurrentYearFamilyTitheTotal") + public Double getCurrentYearFamilyTitheTotal(@Argument(name = "familyId") Long familyId){ + return titheQueryService.getCurrentYearFamilyTitheTotal(familyId); + } + + @QueryMapping(name = "getAnnualFamilyTitheTotal") + public List getAnnualFamilyTitheTotal(@Argument(name = "familyId") Long familyId){ + return titheQueryService.getAnnualFamilyTitheTotal(familyId); + } + + @QueryMapping(name = "getCurrentYearKoottaymaTitheTotal") + public Double getCurrentYearKoottaymaTitheTotal(@Argument(name = "koottaymaId") Long koottaymaId){ + return titheQueryService.getCurrentYearKoottaymaTitheTotal(koottaymaId); + } + + @QueryMapping(name = "getAnnualKoottaymaTitheTotal") + public List getAnnualKoottaymaTitheTotal(@Argument(name = "koottaymaId") Long koottaymaId){ + return titheQueryService.getAnnualKoottaymaTitheTotal(koottaymaId); + } + + @QueryMapping(name = "getCurrentYearParishTitheTotal") + public Double getCurrentYearParishTitheTotal(@Argument(name = "parishId") Long parishId){ + return titheQueryService.getCurrentYearParishTitheTotal(parishId); + } + + @QueryMapping(name = "getAnnualParishTitheTotal") + public List getAnnualParishTitheTotal(@Argument(name = "parishId") Long parishId){ + return titheQueryService.getAnnualParishTitheTotal(parishId); + } + + @QueryMapping(name = "getCurrentYearForaneTitheTotal") + public Double getCurrentYearForaneTitheTotal(@Argument(name = "foraneId") Long foraneId){ + return titheQueryService.getCurrentYearForaneTitheTotal(foraneId); + } + + @QueryMapping(name = "getAnnualForaneTitheTotal") + public List getAnnualForaneTitheTotal(@Argument(name = "foraneId") Long foraneId){ + return titheQueryService.getAnnualForaneTitheTotal(foraneId); + } + +} diff --git a/Tithe-Spring/src/main/java/com/tithe/model/AnnualTitheTotalInterface.java b/Tithe-Spring/src/main/java/com/tithe/model/AnnualTitheTotalInterface.java new file mode 100755 index 0000000..90e757c --- /dev/null +++ b/Tithe-Spring/src/main/java/com/tithe/model/AnnualTitheTotalInterface.java @@ -0,0 +1,17 @@ +/** + * + */ +package com.tithe.model; + +import java.time.LocalDate; + +/** + * @author Ashish Sam T George + * + */ +public interface AnnualTitheTotalInterface { + + String getYear(); + Double getTitheTotal(); + +} diff --git a/Tithe-Spring/src/main/java/com/tithe/repository/TitheRepository.java b/Tithe-Spring/src/main/java/com/tithe/repository/TitheRepository.java index 2e820d5..4e7743e 100755 --- a/Tithe-Spring/src/main/java/com/tithe/repository/TitheRepository.java +++ b/Tithe-Spring/src/main/java/com/tithe/repository/TitheRepository.java @@ -3,10 +3,17 @@ */ package com.tithe.repository; + +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.tithe.entity.TitheEntity; +import com.tithe.model.AnnualTitheTotalInterface; + /** * @author Ashish Sam T George @@ -15,4 +22,60 @@ @Repository public interface TitheRepository extends JpaRepository { + @Query(value = "SELECT SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.person_id = :personId AND " + + "EXTRACT(YEAR FROM tt.time_stamp) = EXTRACT(YEAR FROM NOW())", nativeQuery = true) + Double findCurrentYearPersonTitheTotal(@Param("personId") Long personId); + + @Query(value = "SELECT EXTRACT(YEAR FROM time_stamp) AS year, " + + "SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.person_id = :personId GROUP BY EXTRACT(YEAR FROM time_stamp) " + + "ORDER BY EXTRACT(YEAR FROM time_stamp)", nativeQuery = true) + List findAnnualPersonTitheTotal(@Param("personId") Long personId); + + @Query(value = "SELECT SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.family_id = :familyId AND " + + "EXTRACT(YEAR FROM tt.time_stamp) = EXTRACT(YEAR FROM NOW())", nativeQuery = true) + Double findCurrentYearFamilyTitheTotal(@Param("familyId") Long familyId); + + @Query(value = "SELECT EXTRACT(YEAR FROM time_stamp) AS year, " + + "SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.family_id = :familyId GROUP BY EXTRACT(YEAR FROM time_stamp) " + + "ORDER BY EXTRACT(YEAR FROM time_stamp)", nativeQuery = true) + List findAnnualFamilyTitheTotal(@Param("familyId") Long familyId); + + @Query(value = "SELECT SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.koottayma_id = :koottaymaId AND " + + "EXTRACT(YEAR FROM tt.time_stamp) = EXTRACT(YEAR FROM NOW())", nativeQuery = true) + Double findCurrentYearKoottaymaTitheTotal(@Param("koottaymaId") Long koottaymaId); + + @Query(value = "SELECT EXTRACT(YEAR FROM time_stamp) AS year, " + + "SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.koottayma_id = :koottaymaId GROUP BY EXTRACT(YEAR FROM time_stamp) " + + "ORDER BY EXTRACT(YEAR FROM time_stamp)", nativeQuery = true) + List findAnnualKoottaymaTitheTotal( + @Param("koottaymaId") Long koottaymaId); + + @Query(value = "SELECT SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.parish_id = :parishId AND " + + "EXTRACT(YEAR FROM tt.time_stamp) = EXTRACT(YEAR FROM NOW())", nativeQuery = true) + Double findCurrentYearParishTitheTotal(@Param("parishId") Long parishId); + + @Query(value = "SELECT EXTRACT(YEAR FROM time_stamp) AS year, " + + "SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.parish_id = :parishId GROUP BY EXTRACT(YEAR FROM time_stamp) " + + "ORDER BY EXTRACT(YEAR FROM time_stamp)", nativeQuery = true) + List findAnnualParishTitheTotal(@Param("parishId") Long parishId); + + @Query(value = "SELECT SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.forane_id = :foraneId AND " + + "EXTRACT(YEAR FROM tt.time_stamp) = EXTRACT(YEAR FROM NOW())", nativeQuery = true) + Double findCurrentYearForaneTitheTotal(@Param("foraneId") Long foraneId); + + @Query(value = "SELECT EXTRACT(YEAR FROM time_stamp) AS year, " + + "SUM(tithe_amount) AS titheTotal FROM tithe_table tt " + + "WHERE tt.forane_id = :foraneId GROUP BY EXTRACT(YEAR FROM time_stamp) " + + "ORDER BY EXTRACT(YEAR FROM time_stamp)", nativeQuery = true) + List findAnnualForaneTitheTotal(@Param("foraneId") Long foraneId); + } diff --git a/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java b/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java index f8fce65..9d821a3 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java @@ -15,6 +15,9 @@ import com.tithe.repository.TitheRepository; import com.tithe.service.query.PersonQueryService; import com.tithe.service.query.TitheQueryService; +import com.tithe.utils.ObjectValidation; + +import graphql.GraphQLException; /** * @author Ashish Sam T George @@ -22,6 +25,9 @@ */ @Service public class TitheMutationService { + + @Autowired + private ObjectValidation objectValidation; @Autowired private PersonQueryService personQueryService; @@ -34,9 +40,18 @@ public class TitheMutationService { public List createManyTithes(Long personId, List titheMutationInputs) { + + objectValidation.validateObjects(titheMutationInputs); -// TODO Try adding @NotNull in the method parameter above - No Use + if(personId==null) { + throw new GraphQLException("Person Id is not valid"); + } + PersonEntity person = personQueryService.getOnePerson(personId); + if(person==null) { + throw new GraphQLException("Person does not exist"); + } + TitheBuilder titheBuilder = new TitheBuilder(); List tithes = titheBuilder.buildTithe(person, titheMutationInputs); return titheRepository.saveAll(tithes); diff --git a/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java b/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java index 5fd23c2..4862c47 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java @@ -3,8 +3,18 @@ */ package com.tithe.service.query; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.tithe.model.AnnualTitheTotalInterface; +import com.tithe.repository.TitheRepository; + +import graphql.GraphQLException; + + /** * @author Ashish Sam T George * @@ -12,4 +22,97 @@ @Service public class TitheQueryService { + @Autowired + private TitheRepository titheRepository; + + public Double getCurrentYearPersonTitheTotal(Long personId) { + if (personId == null) { + throw new GraphQLException("Person Id should be valid"); + } + Double titheTotal = titheRepository.findCurrentYearPersonTitheTotal(personId); + if (titheTotal != null && !titheTotal.isNaN()) { + return titheTotal; + } + return 0.0; + } + + public List getAnnualPersonTitheTotal(Long personId) { + if (personId == null) { + throw new GraphQLException("Person Id should be valid"); + } + return titheRepository.findAnnualPersonTitheTotal(personId); + } + + public Double getCurrentYearFamilyTitheTotal(Long familyId) { + if (familyId == null) { + throw new GraphQLException("Family Id should be valid"); + } + Double titheTotal = titheRepository.findCurrentYearFamilyTitheTotal(familyId); + if (titheTotal != null && !titheTotal.isNaN()) { + return titheTotal; + } + return 0.0; + } + + public List getAnnualFamilyTitheTotal(Long familyId) { + if (familyId == null) { + throw new GraphQLException("Family Id should be valid"); + } + return titheRepository.findAnnualFamilyTitheTotal(familyId); + } + + public Double getCurrentYearKoottaymaTitheTotal(Long koottaymaId) { + if (koottaymaId == null) { + throw new GraphQLException("Koottayma Id should be valid"); + } + Double titheTotal = titheRepository.findCurrentYearKoottaymaTitheTotal(koottaymaId); + if (titheTotal != null && !titheTotal.isNaN()) { + return titheTotal; + } + return 0.0; + } + + public List getAnnualKoottaymaTitheTotal(Long koottaymaId) { + if (koottaymaId == null) { + throw new GraphQLException("Koottayma Id should be valid"); + } + return titheRepository.findAnnualKoottaymaTitheTotal(koottaymaId); + } + + public Double getCurrentYearParishTitheTotal(Long parishId) { + if (parishId == null) { + throw new GraphQLException("Parish Id should be valid"); + } + Double titheTotal = titheRepository.findCurrentYearParishTitheTotal(parishId); + if (titheTotal != null && !titheTotal.isNaN()) { + return titheTotal; + } + return 0.0; + } + + public List getAnnualParishTitheTotal(Long parishId) { + if (parishId == null) { + throw new GraphQLException("Parish Id should be valid"); + } + return titheRepository.findAnnualParishTitheTotal(parishId); + } + + public Double getCurrentYearForaneTitheTotal(Long foraneId) { + if (foraneId == null) { + throw new GraphQLException("Forane Id should be valid"); + } + Double titheTotal = titheRepository.findCurrentYearForaneTitheTotal(foraneId); + if (titheTotal != null && !titheTotal.isNaN()) { + return titheTotal; + } + return 0.0; + } + + public List getAnnualForaneTitheTotal(Long foraneId) { + if (foraneId == null) { + throw new GraphQLException("Forane Id should be valid"); + } + return titheRepository.findAnnualForaneTitheTotal(foraneId); + } + } diff --git a/Tithe-Spring/src/main/resources/graphql/queries/TitheQueries.graphqls b/Tithe-Spring/src/main/resources/graphql/queries/TitheQueries.graphqls new file mode 100755 index 0000000..8682b50 --- /dev/null +++ b/Tithe-Spring/src/main/resources/graphql/queries/TitheQueries.graphqls @@ -0,0 +1,16 @@ +extend type Query{ + getCurrentYearPersonTitheTotal(personId: ID!): Float! + getAnnualPersonTitheTotal(personId: ID!): [AnnualTitheTotalSchema] + + getCurrentYearFamilyTitheTotal(familyId: ID!): Float! + getAnnualFamilyTitheTotal(familyId: ID!): [AnnualTitheTotalSchema] + + getCurrentYearKoottaymaTitheTotal(koottaymaId: ID!): Float! + getAnnualKoottaymaTitheTotal(koottaymaId: ID!): [AnnualTitheTotalSchema] + + getCurrentYearParishTitheTotal(parishId: ID!): Float! + getAnnualParishTitheTotal(parishId: ID!): [AnnualTitheTotalSchema] + + getCurrentYearForaneTitheTotal(foraneId: ID!): Float! + getAnnualForaneTitheTotal(foraneId: ID!): [AnnualTitheTotalSchema] +} diff --git a/Tithe-Spring/src/main/resources/graphql/types/Tithe.graphqls b/Tithe-Spring/src/main/resources/graphql/types/Tithe.graphqls index b83987e..cdf3a7c 100755 --- a/Tithe-Spring/src/main/resources/graphql/types/Tithe.graphqls +++ b/Tithe-Spring/src/main/resources/graphql/types/Tithe.graphqls @@ -13,3 +13,8 @@ input TitheMutationInput{ titheAmount: Float! timeStamp: LocalDate! } + +type AnnualTitheTotalSchema{ + year: String! + titheTotal: Float! +} diff --git a/Tithe-Vue/src/components/Charts/SingleEntityTitheChart.vue b/Tithe-Vue/src/components/Charts/SingleEntityTitheChart.vue new file mode 100755 index 0000000..6f3bca6 --- /dev/null +++ b/Tithe-Vue/src/components/Charts/SingleEntityTitheChart.vue @@ -0,0 +1,58 @@ + + + diff --git a/Tithe-Vue/src/components/Charts/chart.config.js b/Tithe-Vue/src/components/Charts/chart.config.js index cfbb33c..d6a6e9b 100644 --- a/Tithe-Vue/src/components/Charts/chart.config.js +++ b/Tithe-Vue/src/components/Charts/chart.config.js @@ -47,8 +47,8 @@ export const sampleChartData = (points = 9) => { labels, datasets: [ datasetObject("primary", points), - datasetObject("info", points), - datasetObject("danger", points), + // datasetObject("info", points), + // datasetObject("danger", points), ], }; }; diff --git a/Tithe-Vue/src/views/HomeView.vue b/Tithe-Vue/src/views/HomeView.vue index 35430e7..177edec 100644 --- a/Tithe-Vue/src/views/HomeView.vue +++ b/Tithe-Vue/src/views/HomeView.vue @@ -17,7 +17,8 @@ import gql from "graphql-tag"; import { useQuery, useLazyQuery } from "@vue/apollo-composable"; import * as chartConfig from "@/components/Charts/chart.config.js"; -import LineChart from "@/components/Charts/LineChart.vue"; +// import LineChart from "@/components/Charts/LineChart.vue"; +import SingleEntityTitheChart from "@/components/Charts/SingleEntityTitheChart.vue"; import SectionMain from "@/components/SectionMain.vue"; import CardBoxWidget from "@/components/CardBoxWidget.vue"; import CardBox from "@/components/CardBox.vue"; @@ -44,18 +45,50 @@ import { homepageActivePersonTableQuery, } from "@/externalized-data/graphqlQueries"; -const chartData = ref(null); - const tableTabTitle = homepageTableTabTitle; +// onMounted(() => { +// fillChartData(); +// }); + +const somanData = ref([]); + +somanData.value = [ + { + timeStamp: "2004", + titheAmount: 400, + }, + { + timeStamp: "2005", + titheAmount: 700, + }, + { + timeStamp: "2006", + titheAmount: 12000, + }, +]; + const fillChartData = () => { - chartData.value = chartConfig.sampleChartData(); + somanData.value = [ + { + timeStamp: "2004", + titheAmount: 400, + }, + { + timeStamp: "2005", + titheAmount: 800, + }, + { + timeStamp: "2006", + titheAmount: 12000, + }, + { + timeStamp: "2007", + titheAmount: 14000, + }, + ]; }; -onMounted(() => { - fillChartData(); -}); - // const mainStore = useMainStore(); // const clientBarItems = computed(() => mainStore.clients.slice(0, 4)); @@ -195,10 +228,14 @@ const getActivePersonRows = computed(() => { /> - + + + +