Add front- end backend for new category-group

This commit is contained in:
Jan Bader 2022-09-23 19:12:10 +00:00
parent 99979a35b0
commit 403544e99f
5 changed files with 98 additions and 2 deletions

View File

@ -0,0 +1,35 @@
package server
import (
"net/http"
"git.javil.eu/jacob1123/budgeteer/postgres"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
type newCategoryGroupInformation struct {
BudgetID uuid.UUID `json:"budgetId"`
Group string `json:"group"`
}
func (h *Handler) newCategoryGroup(c echo.Context) error {
var newCategory newCategoryGroupInformation
if err := c.Bind(&newCategory); err != nil {
return echo.NewHTTPError(http.StatusNotAcceptable, err)
}
if newCategory.Group == "" {
return echo.NewHTTPError(http.StatusBadRequest, "category group is required")
}
budget, err := h.Service.CreateCategoryGroup(c.Request().Context(), postgres.CreateCategoryGroupParams{
BudgetID: newCategory.BudgetID,
Name: newCategory.Group,
})
if err != nil {
return err
}
return c.JSON(http.StatusOK, budget)
}

View File

@ -56,6 +56,9 @@ func (h *Handler) LoadRoutes(router *echo.Echo) {
category := authenticated.Group("/category") category := authenticated.Group("/category")
category.POST("/new", h.newCategory) category.POST("/new", h.newCategory)
categoryGroup := authenticated.Group("/category-group")
categoryGroup.POST("/new", h.newCategoryGroup)
budget := authenticated.Group("/budget") budget := authenticated.Group("/budget")
budget.POST("/new", h.newBudget) budget.POST("/new", h.newBudget)
budget.GET("/:budgetid", h.budget) budget.GET("/:budgetid", h.budget)

View File

@ -0,0 +1,45 @@
<script lang="ts" setup>
import { ref } from 'vue';
import Modal from '../components/Modal.vue';
import Input from '../components/Input.vue';
import { useCategoryStore } from '../stores/category';
const categoryStore = useCategoryStore();
const categoryGroupName = ref("");
const error = ref("");
function createCategoryGroup(e : {cancel:boolean}) : boolean {
error.value = "";
categoryStore.CreateCategoryGroup(categoryGroupName.value);
return true;
}
</script>
<template>
<Modal
button-text="Create Category"
@submit="createCategoryGroup"
>
<template #placeholder>
<button class="px-2 py-0 w-full bg-slate-400 rounded-md mt-4">Add Group</button>
</template>
<div class="mt-2 px-7 py-3">
<Input
v-model="categoryGroupName"
class="border-2 dark:border-gray-700"
type="text"
placeholder="Category name"
required
/>
</div>
<div
v-if="error != ''"
class="dark:text-red-300 text-red-700"
>
{{ error }}
</div>
</Modal>
</template>

View File

@ -9,6 +9,7 @@ import { POST } from "../api";
import CreateCategory from "../dialogs/CreateCategory.vue"; import CreateCategory from "../dialogs/CreateCategory.vue";
import BudgetingSummary from "../components/BudgetingSummary.vue"; import BudgetingSummary from "../components/BudgetingSummary.vue";
import { Category } from "../stores/category"; import { Category } from "../stores/category";
import CreateCategoryGroup from "../dialogs/CreateCategoryGroup.vue";
const props = defineProps<{ const props = defineProps<{
budgetid: string, budgetid: string,
@ -57,7 +58,6 @@ onMounted(() => {
useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year); useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year);
}) })
const expandedGroups = ref<Map<string, boolean>>(new Map<string, boolean>()) const expandedGroups = ref<Map<string, boolean>>(new Map<string, boolean>())
function toggleGroup(group: { Name: string, Expand: boolean }) { function toggleGroup(group: { Name: string, Expand: boolean }) {
@ -169,6 +169,6 @@ function assignedChanged(e : Event, category : Category){
</div> </div>
</template> </template>
</template> </template>
<button class="px-2 py-0 w-full bg-slate-400 rounded-md mt-4">Add Group</button> <CreateCategoryGroup />
</div> </div>
</template> </template>

View File

@ -24,6 +24,19 @@ export const useCategoryStore = defineStore("category", {
getters: { getters: {
}, },
actions: { actions: {
async CreateCategoryGroup(
group: string,
) {
const result = await POST(
"/category-group/new",
JSON.stringify({
budgetId: useBudgetsStore().CurrentBudgetID,
group: group,
})
);
const response = await result.json();
useCategoryStore().AddCategory(response);
},
async CreateCategory( async CreateCategory(
group: string, group: string,
name: string, name: string,