Full fix for getProject route, testing, integration testing and frontend-API code
This commit is contained in:
parent
741ad50ccf
commit
0c2617d0cb
7 changed files with 82 additions and 2 deletions
|
@ -106,7 +106,10 @@ func (d *Db) GetAllProjects() ([]types.Project, error) {
|
|||
// GetProject retrieves a specific project by its ID.
|
||||
func (d *Db) GetProject(projectId int) (types.Project, error) {
|
||||
var project types.Project
|
||||
err := d.Select(&project, "SELECT * FROM projects WHERE id = ?")
|
||||
err := d.Get(&project, "SELECT * FROM projects WHERE id = ?", projectId)
|
||||
if err != nil {
|
||||
println("Error getting project: ", err)
|
||||
}
|
||||
return project, err
|
||||
}
|
||||
|
||||
|
|
|
@ -536,3 +536,33 @@ func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
|||
t.Error("Expected SignWeeklyReport to fail with a project manager who is not in the project, but it didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Add a user
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add a project
|
||||
err = db.AddProject("testproject", "description", "testuser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the added project
|
||||
project, err := db.GetProject(1)
|
||||
if err != nil {
|
||||
t.Error("GetProject failed:", err)
|
||||
}
|
||||
|
||||
// Check if the retrieved project matches the expected values
|
||||
if project.Name != "testproject" {
|
||||
t.Errorf("Expected Name to be testproject, got %s", project.Name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ type GlobalState interface {
|
|||
SubmitWeeklyReport(c *fiber.Ctx) error
|
||||
GetWeeklyReport(c *fiber.Ctx) error
|
||||
SignReport(c *fiber.Ctx) error
|
||||
GetProject(c *fiber.Ctx) error
|
||||
// GetProject(c *fiber.Ctx) error // To get a specific project
|
||||
// UpdateProject(c *fiber.Ctx) error // To update a project
|
||||
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
||||
|
|
|
@ -66,6 +66,10 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
|
|||
func (gs *GState) GetProject(c *fiber.Ctx) error {
|
||||
// Extract the project ID from the request parameters or body
|
||||
projectID := c.Params("projectID")
|
||||
if projectID == "" {
|
||||
return c.Status(400).SendString("No project ID provided")
|
||||
}
|
||||
println("Getting project with ID: ", projectID)
|
||||
|
||||
// Parse the project ID into an integer
|
||||
projectIDInt, err := strconv.Atoi(projectID)
|
||||
|
@ -80,6 +84,7 @@ func (gs *GState) GetProject(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
// Return the project as JSON
|
||||
println("Returning project: ", project.Name)
|
||||
return c.JSON(project)
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ func main() {
|
|||
server.Post("/api/loginrenew", gs.LoginRenew)
|
||||
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
||||
server.Post("/api/project", gs.CreateProject)
|
||||
server.Get("/api/project/:projectId", gs.GetProject)
|
||||
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||
|
||||
// Announce the port we are listening on and start the server
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue