Handler for GetProject from db.go added in global_stage.go
This commit is contained in:
		
							parent
							
								
									2468fe8fab
								
							
						
					
					
						commit
						78f5415d9a
					
				
					 1 changed files with 22 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package handlers
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
	"ttime/internal/database"
 | 
			
		||||
	"ttime/internal/types"
 | 
			
		||||
| 
						 | 
				
			
			@ -225,3 +226,24 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
 | 
			
		|||
	// Return a success message
 | 
			
		||||
	return c.SendStatus(fiber.StatusOK)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetProject retrieves a specific project by its ID
 | 
			
		||||
func (gs *GState) GetProject(c *fiber.Ctx) error {
 | 
			
		||||
	// Extract the project ID from the request parameters or body
 | 
			
		||||
	projectID := c.Params("projectID")
 | 
			
		||||
 | 
			
		||||
	// Parse the project ID into an integer
 | 
			
		||||
	projectIDInt, err := strconv.Atoi(projectID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return c.Status(400).SendString("Invalid project ID")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get the project from the database by its ID
 | 
			
		||||
	project, err := gs.Db.GetProject(projectIDInt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return c.Status(500).SendString(err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Return the project as JSON
 | 
			
		||||
	return c.JSON(project)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue