-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from zbyju/dev
Add support for issues and maintenances
- Loading branch information
Showing
50 changed files
with
8,445 additions
and
3,145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/zbyju/babybox-dashboard/apps/babybox-service/internal/domain" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
// CreateIssue inserts a new BabyboxIssue | ||
func (app *Application) CreateIssue(c echo.Context) error { | ||
issue := new(domain.BabyboxIssue) | ||
if err := c.Bind(issue); err != nil { | ||
return err | ||
} | ||
|
||
now := time.Now().In(app.DBService.TimeLocation) | ||
issue.CreatedAt = &now | ||
|
||
result, err := app.DBService.InsertIssue(*issue) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusCreated, ReturnOk(result)) | ||
} | ||
|
||
// UpdateIssue updates an existing BabyboxIssue | ||
func (app *Application) UpdateIssue(c echo.Context) error { | ||
idStr := c.Param("id") | ||
|
||
issue := new(domain.BabyboxIssue) | ||
if err := c.Bind(issue); err != nil { | ||
return err | ||
} | ||
|
||
updatedIssue, err := app.DBService.UpdateIssue(*issue) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return c.JSON(http.StatusNotFound, ReturnErr(fmt.Sprintf("Issue with ID: '%s' was not found.", idStr))) | ||
} | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(updatedIssue)) | ||
} | ||
|
||
// DeleteIssue deletes a BabyboxIssue by its ID | ||
func (app *Application) DeleteIssue(c echo.Context) error { | ||
id := c.Param("id") | ||
|
||
err := app.DBService.DeleteIssue(id) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return c.JSON(http.StatusNotFound, ReturnErr(fmt.Sprintf("Issue with ID: '%s' was not found.", id))) | ||
} | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.NoContent(http.StatusNoContent) | ||
} | ||
|
||
// GetAllIssues gets all BabyboxIssues | ||
func (app *Application) GetAllIssues(c echo.Context) error { | ||
issues, err := app.DBService.FindAllIssues() | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(issues)) | ||
} | ||
|
||
// GetIssuesBySlug finds all BabyboxIssues with a specific slug | ||
func (app *Application) GetIssuesBySlug(c echo.Context) error { | ||
slug := c.Param("slug") | ||
|
||
issues, err := app.DBService.FindIssuesBySlug(slug) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(issues)) | ||
} | ||
|
||
// GetIssuesByUsername finds all BabyboxIssues assigned to a specific user | ||
func (app *Application) GetIssuesByUsername(c echo.Context) error { | ||
username := c.Param("username") | ||
|
||
issues, err := app.DBService.FindIssuesByUsername(username) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(issues)) | ||
} | ||
|
||
func (app *Application) GetIssuesUnsolved(c echo.Context) error { | ||
issues, err := app.DBService.FindMaintenancesUnsolvedOptionallyBySlug("") | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(issues)) | ||
} | ||
|
||
func (app *Application) GetIssuesUnsolvedBySlug(c echo.Context) error { | ||
slug := c.Param("slug") | ||
|
||
issues, err := app.DBService.FindMaintenancesUnsolvedOptionallyBySlug(slug) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(issues)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/zbyju/babybox-dashboard/apps/babybox-service/internal/domain" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
// CreateMaintenance inserts a new BabyboxMaintenance | ||
func (app *Application) CreateMaintenance(c echo.Context) error { | ||
maintenance := new(domain.BabyboxMaintenance) | ||
if err := c.Bind(maintenance); err != nil { | ||
return err | ||
} | ||
|
||
result, err := app.DBService.InsertMaintenance(*maintenance) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusCreated, ReturnOk(result)) | ||
} | ||
|
||
// UpdateMaintenance updates an existing BabyboxMaintenance | ||
func (app *Application) UpdateMaintenance(c echo.Context) error { | ||
idStr := c.Param("id") | ||
|
||
maintenance := new(domain.BabyboxMaintenance) | ||
if err := c.Bind(maintenance); err != nil { | ||
return err | ||
} | ||
|
||
updatedMaintenance, err := app.DBService.UpdateMaintenance(*maintenance) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return c.JSON(http.StatusNotFound, ReturnErr(fmt.Sprintf("Maintenance with ID: '%s' was not found.", idStr))) | ||
} | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(updatedMaintenance)) | ||
} | ||
|
||
// DeleteMaintenance deletes a BabyboxMaintenance by its ID | ||
func (app *Application) DeleteMaintenance(c echo.Context) error { | ||
id := c.Param("id") | ||
|
||
err := app.DBService.DeleteMaintenance(id, false) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return c.JSON(http.StatusNotFound, ReturnErr(fmt.Sprintf("Maintenance with ID: '%s' was not found.", id))) | ||
} | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.NoContent(http.StatusNoContent) | ||
} | ||
|
||
// GetAllMaintenances gets all BabyboxMaintenances | ||
func (app *Application) GetAllMaintenances(c echo.Context) error { | ||
maintenances, err := app.DBService.FindAllMaintenances() | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(maintenances)) | ||
} | ||
|
||
// GetMaintenancesBySlug finds all BabyboxMaintenances with a specific slug | ||
func (app *Application) GetMaintenancesBySlug(c echo.Context) error { | ||
slug := c.Param("slug") | ||
|
||
maintenances, err := app.DBService.FindMaintenancesBySlug(slug) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, ReturnErr(err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, ReturnOk(maintenances)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.