Skip to content

Commit

Permalink
Release v0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronosXYZ authored Mar 30, 2020
2 parents 7ed33b8 + 149ff87 commit a8e66fc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
26 changes: 22 additions & 4 deletions internal/httpHandler/httpHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
)

const (
PutRoomError = 1
GetRoomsError = 2
GetRoomByRoomID = 3
UpdateRoomError = 4
PutRoomError = iota
GetRoomsError
GetRoomByRoomID
UpdateRoomError
DeleteRoomError
)

type HttpHandler struct {
Expand Down Expand Up @@ -174,6 +175,23 @@ func (h *HttpHandler) HandleUpdateRoomRequest(eCtx echo.Context) error {
return nil
}

func (h *HttpHandler) HandleDeleteRoomRequest(eCtx echo.Context) error {
roomIDStr := eCtx.Param("id")
roomID, err := strconv.Atoi(roomIDStr)
if err != nil {
logger.Errorf(err.Error())
eCtx.JSON(http.StatusBadRequest, makeHTTPError(DeleteRoomError, err.Error()))
return err
}
err = h.roomRepository.DeleteRoom(roomID)
if err != nil {
logger.Errorf(err.Error())
eCtx.JSON(http.StatusInternalServerError, makeHTTPError(DeleteRoomError, err.Error()))
return err
}
return eCtx.String(http.StatusOK, "")
}

func makeHTTPError(errCode int, errText string) *models.HTTPError {
return &models.HTTPError{
Ok: false,
Expand Down
22 changes: 22 additions & 0 deletions internal/repositories/roomRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,28 @@ func (rr *RoomRepository) UpdateRoom(room *models.Room) (*models.Room, error) {
return room, nil
}

func (rr *RoomRepository) DeleteRoom(id int) error {
stmt, err := rr.db.GetDatabaseConnection().Preparex("delete from roomschatcategorieslink where roomid = $1")
if err != nil {
return err
}

_, err = stmt.Exec(id)
if err != nil {
return err
}

args := map[string]interface{}{
"id": id,
}
_, err = rr.db.GetDatabaseConnection().NamedExec(
`delete from rooms where id = :id`, args)
if err != nil {
return err
}
return nil
}

func (rr *RoomRepository) getCategoriesByRoomID(id int) ([]models.ChatCategory, error) {
stmt, err := rr.db.GetDatabaseConnection().Preparex(`
SELECT cc.id, cc.categoryname
Expand Down
1 change: 1 addition & 0 deletions internal/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func New(cfg *utils.Config, db *database.Database) (*Webserver, error) {
webserver.echo.GET("/categories", httpHandler.HandleGetAllCategories)
webserver.echo.GET("/rooms/byParentGroupId/:parent_group_id", httpHandler.HandleGetRoomsByParentGroupID)
webserver.echo.PUT("/rooms/update", httpHandler.HandleUpdateRoomRequest)
webserver.echo.DELETE("/rooms/:id", httpHandler.HandleDeleteRoomRequest)

webserver.echo.HideBanner = true
go func() {
Expand Down

0 comments on commit a8e66fc

Please sign in to comment.