diff --git a/backend/internal/dto/wishList.go b/backend/internal/dto/wishList.go new file mode 100644 index 0000000..67cce6a --- /dev/null +++ b/backend/internal/dto/wishList.go @@ -0,0 +1,55 @@ +// Copyright (c) 2025 Nikolai Papin +// +// This file is part of Easywish +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +// the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package dto + +type WishListDto struct { + Guid string `json:"guid"` + Name string `json:"name"` + Hidden bool `json:"hidden"` + IconName string `json:"icon_name"` + Color string `json:"color"` + ColorGrad string `json:"color_grad"` +} + +type NewWishListDto struct { + Name string `json:"name" binding:"required" validate:"max=32"` + Hidden bool `json:"hidden"` + IconName string `json:"icon_name" validate:"omitempty,max=64"` + Color string `json:"color" validate:"omitempty,color_hex"` + ColorGrad string `json:"color_grad" validate:"omitempty,color_hex"` +} + +type WishDto struct { + Guid string `json:"guid"` + WishListGuid string `json:"wish_list_guid"` + Name string `json:"name"` + Description string `json:"description"` + PictureUrl string `json:"picture_url"` + Stars int `json:"stars"` + CreationDate int64 `json:"creation_date"` + Fulfilled bool `json:"fulfilled"` + FulfilledDate int64 `json:"fulfilled_date"` +} + +type NewWishDto struct { + WishListGuid string `json:"wish_list_guid" binding:"required" validate:"guid"` + Name string `json:"name" binding:"required" validate:"max=64"` + Description string `json:"description" validate:"omitempty,max=1000"` + PictureUploadId string `json:"picture_upload_id" validate:"omitempty,upload_id=image"` + Stars int `json:"stars" validate:"min=1,max=5"` +} diff --git a/backend/internal/services/wishlist.go b/backend/internal/services/wishlist.go new file mode 100644 index 0000000..b65975c --- /dev/null +++ b/backend/internal/services/wishlist.go @@ -0,0 +1,27 @@ +// Copyright (c) 2025 Nikolai Papin +// +// This file is part of Easywish +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +// the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package services + +import "easywish/internal/dto" + +type WishListService interface { + CreateWishList(cinfo dto.ClientInfo, object dto.NewWishListDto) (*dto.WishListDto, error) + CreateWish(cinfo dto.ClientInfo, object dto.NewWishDto) (*dto.WishDto, error) + GetWishListByGuid(cinfo dto.ClientInfo, guid string) (*dto.WishListDto, error) + GetUserWishListsPaginated(cinfo dto.ClientInfo, amount int, page int) (*[]dto.WishListDto, error) +} diff --git a/backend/internal/validation/custom.go b/backend/internal/validation/custom.go index a230b19..d748805 100644 --- a/backend/internal/validation/custom.go +++ b/backend/internal/validation/custom.go @@ -42,6 +42,13 @@ func GetCustomHandlers() []CustomValidatorHandler { return regexp.MustCompile(`^[a-zA-Z0-9_]{3,20}$`).MatchString(username) }}, + { + FieldName: "guid", + Function: func(fl validator.FieldLevel) bool { + guid := fl.Field().String() + return regexp.MustCompile(`^([{(]?([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})[})]?)$`).MatchString(guid) + }}, + { FieldName: "name", Function: func(fl validator.FieldLevel) bool { diff --git a/sqlc/schema.sql b/sqlc/schema.sql index 831e3b5..6648e11 100644 --- a/sqlc/schema.sql +++ b/sqlc/schema.sql @@ -111,7 +111,7 @@ CREATE TABLE IF NOT EXISTS "wishes" ( id BIGSERIAL PRIMARY KEY, guid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(), wish_list_id BIGINT UNIQUE NOT NULL REFERENCES wish_lists(id) ON DELETE CASCADE, - name VARCHAR(32) NOT NULL DEFAULT 'New wish', + name VARCHAR(64) NOT NULL DEFAULT 'New wish', description VARCHAR(1000) NOT NULL DEFAULT '', picture_url VARCHAR(512) NOT NULL DEFAULT '', stars SMALLINT NOT NULL DEFAULT 3 CHECK (stars BETWEEN 1 AND 5),