Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create util function for to read ticket records from database #1978

Closed
5 tasks
Tracked by #1967
humansinstitute opened this issue Nov 27, 2024 · 2 comments · Fixed by #1989 or #1992
Closed
5 tasks
Tracked by #1967

Create util function for to read ticket records from database #1978

humansinstitute opened this issue Nov 27, 2024 · 2 comments · Fixed by #1989 or #1992
Assignees
Labels

Comments

@humansinstitute
Copy link
Contributor

humansinstitute commented Nov 27, 2024

Ticket Name: Implement Get Ticket Database Function

Context

To support the ticket API endpoint's read operation, we need to implement a database utility function that retrieves ticket records by UUID.

Task

Create a utility function that retrieves ticket records from the database using GORM.
This will interface with Ticket table at: #1971
and will be called by: #1976

Outcome

A utility function that can reliably fetch ticket records by UUID with proper error handling.

Design

// utils/ticket.go
package utils

import (
    "fmt"
    "gorm.io/gorm"
)

func GetTicket(uuid string) (*Ticket, error) {
    var ticket Ticket
    result := db.Where("uuid = ?", uuid).First(&ticket)
    if result.Error != nil {
        if errors.Is(result.Error, gorm.ErrRecordNotFound) {
            return nil, fmt.Errorf("ticket not found: %w", result.Error)
        }
        return nil, fmt.Errorf("failed to get ticket: %w", result.Error)
    }
    return &ticket, nil
}

Acceptance Criteria

  • Function correctly retrieves ticket data by UUID
  • Proper error handling for non-existent tickets
  • Proper error handling for database errors
  • Function returns complete ticket struct with all fields
  • Unit tests implemented with test cases for:
    • Successful retrieval
    • Non-existent UUID
    • Invalid UUID format
    • Database connection errors
@MuhammadUmer44
Copy link
Contributor

@humansinstitute Please assign me

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Nov 27, 2024

@humansinstitute please assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment