Handler for GetProject from db.go added in global_stage.go
This commit is contained in:
		
							parent
							
								
									581209742a
								
							
						
					
					
						commit
						018dc24516
					
				
					 1 changed files with 22 additions and 0 deletions
				
			
		|  | @ -1,6 +1,7 @@ | ||||||
| package handlers | package handlers | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"strconv" | ||||||
| 	"time" | 	"time" | ||||||
| 	"ttime/internal/database" | 	"ttime/internal/database" | ||||||
| 	"ttime/internal/types" | 	"ttime/internal/types" | ||||||
|  | @ -225,3 +226,24 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error { | ||||||
| 	// Return a success message | 	// Return a success message | ||||||
| 	return c.SendStatus(fiber.StatusOK) | 	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
	
	 dDogge
						dDogge