Skip to content

Commit

Permalink
Merge pull request #103 from moevm/99-worker-update
Browse files Browse the repository at this point in the history
99-worker-update
  • Loading branch information
D1mitrii authored Dec 19, 2024
2 parents 6e5b08a + e1137f8 commit d563959
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 28 deletions.
85 changes: 85 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,88 @@ const docTemplate = `{
}
}
},
"/api/v1/orders/{id}/complete": {
"post": {
"description": "Worker complete order",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Orders"
],
"summary": "Worker complete order",
"parameters": [
{
"type": "string",
"description": "Order id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
}
}
}
},
"/api/v1/orders/{id}/take": {
"post": {
"description": "Worker take order",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Orders"
],
"summary": "Worker take order",
"parameters": [
{
"type": "string",
"description": "Order id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
}
}
}
},
"/api/v1/services": {
"get": {
"description": "Get array of services info from database",
Expand Down Expand Up @@ -1531,6 +1613,9 @@ const docTemplate = `{
"name": {
"type": "string"
},
"orders_count": {
"type": "integer"
},
"password": {
"type": "string"
},
Expand Down
85 changes: 85 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,88 @@
}
}
},
"/api/v1/orders/{id}/complete": {
"post": {
"description": "Worker complete order",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Orders"
],
"summary": "Worker complete order",
"parameters": [
{
"type": "string",
"description": "Order id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
}
}
}
},
"/api/v1/orders/{id}/take": {
"post": {
"description": "Worker take order",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Orders"
],
"summary": "Worker take order",
"parameters": [
{
"type": "string",
"description": "Order id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
}
}
}
},
"/api/v1/services": {
"get": {
"description": "Get array of services info from database",
Expand Down Expand Up @@ -1520,6 +1602,9 @@
"name": {
"type": "string"
},
"orders_count": {
"type": "integer"
},
"password": {
"type": "string"
},
Expand Down
56 changes: 56 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ definitions:
type: string
name:
type: string
orders_count:
type: integer
password:
type: string
patronymic:
Expand Down Expand Up @@ -546,6 +548,60 @@ paths:
summary: Update order
tags:
- Orders
/api/v1/orders/{id}/complete:
post:
consumes:
- application/json
description: Worker complete order
parameters:
- description: Order id
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
"400":
description: Bad Request
schema:
$ref: '#/definitions/httputil.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/httputil.HTTPError'
summary: Worker complete order
tags:
- Orders
/api/v1/orders/{id}/take:
post:
consumes:
- application/json
description: Worker take order
parameters:
- description: Order id
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
"400":
description: Bad Request
schema:
$ref: '#/definitions/httputil.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/httputil.HTTPError'
summary: Worker take order
tags:
- Orders
/api/v1/services:
get:
description: Get array of services info from database
Expand Down
18 changes: 7 additions & 11 deletions backend/dump/dump.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"surname": "Петров",
"patronymic": "Иванович",
"email": "[email protected]",
"orders_count": 2,
"password": "$2a$10$dC8NSVsldxLdQbSzW9DPCO4LWoP1ZJDzdH0tbW5aPdUG.XOyIe596",
"phone_number": "+7 (999) 010-10-22",
"user_type": "WORKER",
Expand All @@ -61,6 +62,7 @@
"surname": "Смирнова",
"patronymic": "Викторовна",
"email": "[email protected]",
"orders_count": 2,
"password": "$2a$10$bh0Y3bOB4lkIImrXwvDhL2gnzLf0pX6r0kO2ja13kR5LdyKD9yROO",
"phone_number": "+7 (999) 444-55-66",
"user_type": "WORKER",
Expand All @@ -72,6 +74,7 @@
"surname": "Давыдова",
"patronymic": "Михайловна",
"email": "[email protected]",
"orders_count": 3,
"password": "$2a$10$J7XkT3xLwvQJxJn68mXbo/jhD5pw7vwIMomik6CH32ewX3jZf1Gti",
"phone_number": "+7 (999) 888-99-00",
"user_type": "WORKER",
Expand Down Expand Up @@ -349,7 +352,7 @@
"status": "IN_PROGRESS",
"services": ["3565ed3fa26c4a64672e9b38"],
"required_workers": 2,
"workers": ["60b8c093f6d292edb4b4a761", "60b8c093f6d292edb4b4a762"],
"workers": ["60b8c093f6d292edb4b4a761"],
"created_at": "2024-04-08T15:30:00.000Z"
},
{
Expand Down Expand Up @@ -415,7 +418,7 @@
"status": "IN_PROGRESS",
"services": ["3fa26c4a64672e9b383565ed", "565ed3fa26c4a64672e9b383"],
"required_workers": 2,
"workers": ["60b8c093f6d292edb4b4a761", "60b8c093f6d292edb4b4a762"],
"workers": ["60b8c093f6d292edb4b4a761"],
"created_at": "2024-04-10T13:45:00.000Z"
},
{
Expand Down Expand Up @@ -448,7 +451,7 @@
"status": "IN_PROGRESS",
"services": ["3fa26c4a64672e9b383565ed", "565ed3fa26c4a64672e9b383"],
"required_workers": 2,
"workers": ["60b8c093f6d292edb4b4a762", "60b8c093f6d292edb4b4a761"],
"workers": ["60b8c093f6d292edb4b4a761"],
"created_at": "2024-04-11T11:45:00.000Z"
},
{
Expand All @@ -470,14 +473,7 @@
"pollution": 50,
"area": 100.0,
"comment": "Нужна полная уборка дома после въезда",
"status_log": [
{
"id": "60b8c093f6d292edb4b4a783",
"new_status": "CREATED",
"prev_status": "CREATED",
"created_at": "2024-04-12T09:00:00.000Z"
}
],
"status_log": [],
"status": "CREATED",
"services": ["3fa26c4a64672e9b383565ed", "565ed3fa26c4a64672e9b383"],
"required_workers": 2,
Expand Down
1 change: 1 addition & 0 deletions backend/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func Run(cfg *config.Config) {
logger,
orderRepo,
userRepo,
userRepo,
)
dumpService := services.NewDumpService(
logger,
Expand Down
3 changes: 3 additions & 0 deletions backend/internal/controllers/http/v1/orders/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func (h *Handler) Routes() chi.Router {
r.Get("/", h.GetOrder)
r.Put("/", h.UpdateOrder)
r.Delete("/", h.DeleteOrder)

r.Post("/complete", h.CompleteOrder)
r.Post("/take", h.TakeOrder)
})

return router
Expand Down
35 changes: 35 additions & 0 deletions backend/internal/controllers/http/v1/orders/post_complete_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package orders

import (
"errors"
"net/http"

"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/moevm/nosql2h24-cleaning/cleaning/internal/services"
"github.com/moevm/nosql2h24-cleaning/cleaning/pkg/httputil"
)

// CompleteOrder
// @Summary Worker complete order
// @Description Worker complete order
// @Tags Orders
// @Accept json
// @Produce json
// @Param id path string true "Order id"
// @Success 200
// @Failure 400 {object} httputil.HTTPError
// @Failure 500 {object} httputil.HTTPError
// @Router /api/v1/orders/{id}/complete [post]
func (h *Handler) CompleteOrder(w http.ResponseWriter, r *http.Request) {
orderID := chi.URLParam(r, "id")

if err := h.service.CompleteOrder(r.Context(), orderID); err != nil {
if errors.Is(err, services.ErrOrderAlreadyDone) {
render.Render(w, r, httputil.NewError(http.StatusBadRequest, err))
return
}
render.Render(w, r, httputil.NewError(http.StatusInternalServerError, err))
return
}
}
Loading

0 comments on commit d563959

Please sign in to comment.