feat: Refactor activity and project handlers to use utility functions for ID parsing and response handling
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/oklog/ulid/v2"
|
||||
"github.com/timetracker/backend/internal/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -72,7 +71,7 @@ func GetProjectByID(ctx context.Context, id types.ULID) (*Project, error) {
|
||||
}
|
||||
|
||||
// GetProjectWithCustomer loads a project with the associated customer information
|
||||
func GetProjectWithCustomer(ctx context.Context, id ulid.ULID) (*Project, error) {
|
||||
func GetProjectWithCustomer(ctx context.Context, id types.ULID) (*Project, error) {
|
||||
var project Project
|
||||
result := GetEngine(ctx).Preload("Customer").Where("id = ?", id).First(&project)
|
||||
if result.Error != nil {
|
||||
@@ -105,9 +104,9 @@ func GetAllProjectsWithCustomers(ctx context.Context) ([]Project, error) {
|
||||
}
|
||||
|
||||
// GetProjectsByCustomerID returns all projects of a specific customer
|
||||
func GetProjectsByCustomerID(ctx context.Context, customerID ulid.ULID) ([]Project, error) {
|
||||
func GetProjectsByCustomerID(ctx context.Context, customerId types.ULID) ([]Project, error) {
|
||||
var projects []Project
|
||||
result := GetEngine(ctx).Where("customer_id = ?", customerID).Find(&projects)
|
||||
result := GetEngine(ctx).Where("customer_id = ?", customerId.ULID).Find(&projects)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
@@ -180,7 +179,7 @@ func UpdateProject(ctx context.Context, update ProjectUpdate) (*Project, error)
|
||||
}
|
||||
|
||||
// DeleteProject deletes a project by its ID
|
||||
func DeleteProject(ctx context.Context, id ulid.ULID) error {
|
||||
func DeleteProject(ctx context.Context, id types.ULID) error {
|
||||
// Here you could check if dependent entities exist
|
||||
result := GetEngine(ctx).Delete(&Project{}, id)
|
||||
if result.Error != nil {
|
||||
|
||||
Reference in New Issue
Block a user