Skip to content

Commit b1e8723

Browse files
Allow for updating review progres
1 parent 2907ae8 commit b1e8723

File tree

7 files changed

+285
-1
lines changed

7 files changed

+285
-1
lines changed

cmd/internal/controllers/reviews_controllers.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,39 @@ func (rc *ReviewsController) GetReviewProgress(c *fiber.Ctx) error {
478478
},
479479
})
480480
}
481+
482+
// generate swagger docs
483+
// @Summary Update review progress
484+
// @Description Update review progress
485+
// @Tags reviews
486+
// @Security BearerAuth
487+
// @Accept json
488+
// @Produce json
489+
// @Param reviewStatusID path string true "Review Status ID"
490+
// @Param updateReviewRequest body requests.UpdateReviewRequest true "Update review progress request"
491+
// @Success 200 {object} map[string]interface{}
492+
// @Failure 400 {object} map[string]interface{}
493+
// @Failure 500 {object} map[string]interface{}
494+
// @Router /api/v1/review-status/{reviewStatusID} [put]
495+
func (rc *ReviewsController) UpdateReviewProgress(c *fiber.Ctx) error {
496+
reviewStatusID, err := utils.ReadUintPathParam(c, "reviewStatusID")
497+
if err != nil {
498+
return err
499+
}
500+
var request requests.UpdateReviewRequest
501+
if err := c.BodyParser(&request); err != nil {
502+
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Could not parse request body"})
503+
}
504+
505+
tx := db.GetDBTransaction(c)
506+
if err := rc.reviewsService.UpdateReviewStatus(tx, reviewStatusID, request.Status, request.Progress); err != nil {
507+
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
508+
"message": "Could not update review progress",
509+
"error": err.Error(),
510+
})
511+
}
512+
513+
return c.Status(fiber.StatusOK).JSON(fiber.Map{
514+
"message": "Updated progress successfully.",
515+
})
516+
}

cmd/internal/dto/requests/reviews.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package requests
22

3+
import "github.com/simondanielsson/apPRoved/cmd/constants"
4+
35
type CreateRepositoryRequest struct {
46
Name string `json:"name"`
57
URL string `json:"url"`
@@ -21,3 +23,8 @@ type CompleteReviewRequest struct {
2123
ReviewStatusID uint `json:"review_status_id"`
2224
FileReviews []FileReviewRequest `json:"file_reviews"`
2325
}
26+
27+
type UpdateReviewRequest struct {
28+
Progress int `json:"progress"`
29+
Status constants.ReviewStatus `json:"status"`
30+
}

cmd/internal/routes/reviews_routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ func RegisterReviewsRoutes(apiV1 fiber.Router, reviewsController *controllers.Re
2525
router.Get("/:repositoryID/pull-requests/:prID/reviews/:reviewID/files", reviewsController.GetFileReviews)
2626
router.Get("/:repositoryID/pull-requests/:prID/reviews/:reviewID/progress", reviewsController.GetReviewProgress)
2727

28+
// used by LLM service
2829
apiV1.Post("/reviews/complete", opt_middlewares.Transaction, reviewsController.CompleteReview)
30+
apiV1.Put("/review-status/:reviewStatusID", opt_middlewares.Transaction, reviewsController.UpdateReviewProgress)
2931
}

cmd/internal/services/reviews_services.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,15 @@ func (rs *ReviewsService) GetReviewStatus(tx *gorm.DB, repoID, prID, reviewID ui
353353

354354
return reviewStatus, nil
355355
}
356+
357+
func (rs *ReviewsService) UpdateReviewStatus(tx *gorm.DB, reviewStatusID uint, status constants.ReviewStatus, progress int) error {
358+
if err := rs.reviewsRepository.UpdateReviewStatus(tx, reviewStatusID, status); err != nil {
359+
return err
360+
}
361+
362+
if err := rs.reviewsRepository.UpdateReviewProgress(tx, reviewStatusID, progress); err != nil {
363+
return err
364+
}
365+
366+
return nil
367+
}

docs/docs.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,67 @@ const docTemplate = `{
788788
}
789789
}
790790
},
791+
"/api/v1/review-status/{reviewStatusID}": {
792+
"put": {
793+
"security": [
794+
{
795+
"BearerAuth": []
796+
}
797+
],
798+
"description": "Update review progress",
799+
"consumes": [
800+
"application/json"
801+
],
802+
"produces": [
803+
"application/json"
804+
],
805+
"tags": [
806+
"reviews"
807+
],
808+
"summary": "Update review progress",
809+
"parameters": [
810+
{
811+
"type": "string",
812+
"description": "Review Status ID",
813+
"name": "reviewStatusID",
814+
"in": "path",
815+
"required": true
816+
},
817+
{
818+
"description": "Update review progress request",
819+
"name": "updateReviewRequest",
820+
"in": "body",
821+
"required": true,
822+
"schema": {
823+
"$ref": "#/definitions/requests.UpdateReviewRequest"
824+
}
825+
}
826+
],
827+
"responses": {
828+
"200": {
829+
"description": "OK",
830+
"schema": {
831+
"type": "object",
832+
"additionalProperties": true
833+
}
834+
},
835+
"400": {
836+
"description": "Bad Request",
837+
"schema": {
838+
"type": "object",
839+
"additionalProperties": true
840+
}
841+
},
842+
"500": {
843+
"description": "Internal Server Error",
844+
"schema": {
845+
"type": "object",
846+
"additionalProperties": true
847+
}
848+
}
849+
}
850+
}
851+
},
791852
"/api/v1/reviews/complete": {
792853
"post": {
793854
"description": "Complete a review",
@@ -905,6 +966,19 @@ const docTemplate = `{
905966
}
906967
},
907968
"definitions": {
969+
"constants.ReviewStatus": {
970+
"type": "string",
971+
"enum": [
972+
"queued",
973+
"processing",
974+
"available"
975+
],
976+
"x-enum-varnames": [
977+
"StatusQueued",
978+
"StatusProcessing",
979+
"StatusAvailable"
980+
]
981+
},
908982
"requests.CompleteReviewRequest": {
909983
"type": "object",
910984
"properties": {
@@ -957,6 +1031,17 @@ const docTemplate = `{
9571031
"type": "string"
9581032
}
9591033
}
1034+
},
1035+
"requests.UpdateReviewRequest": {
1036+
"type": "object",
1037+
"properties": {
1038+
"progress": {
1039+
"type": "integer"
1040+
},
1041+
"status": {
1042+
"$ref": "#/definitions/constants.ReviewStatus"
1043+
}
1044+
}
9601045
}
9611046
},
9621047
"securityDefinitions": {

docs/swagger.json

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,67 @@
780780
}
781781
}
782782
},
783+
"/api/v1/review-status/{reviewStatusID}": {
784+
"put": {
785+
"security": [
786+
{
787+
"BearerAuth": []
788+
}
789+
],
790+
"description": "Update review progress",
791+
"consumes": [
792+
"application/json"
793+
],
794+
"produces": [
795+
"application/json"
796+
],
797+
"tags": [
798+
"reviews"
799+
],
800+
"summary": "Update review progress",
801+
"parameters": [
802+
{
803+
"type": "string",
804+
"description": "Review Status ID",
805+
"name": "reviewStatusID",
806+
"in": "path",
807+
"required": true
808+
},
809+
{
810+
"description": "Update review progress request",
811+
"name": "updateReviewRequest",
812+
"in": "body",
813+
"required": true,
814+
"schema": {
815+
"$ref": "#/definitions/requests.UpdateReviewRequest"
816+
}
817+
}
818+
],
819+
"responses": {
820+
"200": {
821+
"description": "OK",
822+
"schema": {
823+
"type": "object",
824+
"additionalProperties": true
825+
}
826+
},
827+
"400": {
828+
"description": "Bad Request",
829+
"schema": {
830+
"type": "object",
831+
"additionalProperties": true
832+
}
833+
},
834+
"500": {
835+
"description": "Internal Server Error",
836+
"schema": {
837+
"type": "object",
838+
"additionalProperties": true
839+
}
840+
}
841+
}
842+
}
843+
},
783844
"/api/v1/reviews/complete": {
784845
"post": {
785846
"description": "Complete a review",
@@ -897,6 +958,19 @@
897958
}
898959
},
899960
"definitions": {
961+
"constants.ReviewStatus": {
962+
"type": "string",
963+
"enum": [
964+
"queued",
965+
"processing",
966+
"available"
967+
],
968+
"x-enum-varnames": [
969+
"StatusQueued",
970+
"StatusProcessing",
971+
"StatusAvailable"
972+
]
973+
},
900974
"requests.CompleteReviewRequest": {
901975
"type": "object",
902976
"properties": {
@@ -949,6 +1023,17 @@
9491023
"type": "string"
9501024
}
9511025
}
1026+
},
1027+
"requests.UpdateReviewRequest": {
1028+
"type": "object",
1029+
"properties": {
1030+
"progress": {
1031+
"type": "integer"
1032+
},
1033+
"status": {
1034+
"$ref": "#/definitions/constants.ReviewStatus"
1035+
}
1036+
}
9521037
}
9531038
},
9541039
"securityDefinitions": {
@@ -958,4 +1043,4 @@
9581043
"in": "header"
9591044
}
9601045
}
961-
}
1046+
}

docs/swagger.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
definitions:
2+
constants.ReviewStatus:
3+
enum:
4+
- queued
5+
- processing
6+
- available
7+
type: string
8+
x-enum-varnames:
9+
- StatusQueued
10+
- StatusProcessing
11+
- StatusAvailable
212
requests.CompleteReviewRequest:
313
properties:
414
file_reviews:
@@ -33,6 +43,13 @@ definitions:
3343
patch:
3444
type: string
3545
type: object
46+
requests.UpdateReviewRequest:
47+
properties:
48+
progress:
49+
type: integer
50+
status:
51+
$ref: '#/definitions/constants.ReviewStatus'
52+
type: object
3653
info:
3754
contact: {}
3855
description: API for apPRoved
@@ -552,6 +569,46 @@ paths:
552569
summary: Get review progress
553570
tags:
554571
- reviews
572+
/api/v1/review-status/{reviewStatusID}:
573+
put:
574+
consumes:
575+
- application/json
576+
description: Update review progress
577+
parameters:
578+
- description: Review Status ID
579+
in: path
580+
name: reviewStatusID
581+
required: true
582+
type: string
583+
- description: Update review progress request
584+
in: body
585+
name: updateReviewRequest
586+
required: true
587+
schema:
588+
$ref: '#/definitions/requests.UpdateReviewRequest'
589+
produces:
590+
- application/json
591+
responses:
592+
"200":
593+
description: OK
594+
schema:
595+
additionalProperties: true
596+
type: object
597+
"400":
598+
description: Bad Request
599+
schema:
600+
additionalProperties: true
601+
type: object
602+
"500":
603+
description: Internal Server Error
604+
schema:
605+
additionalProperties: true
606+
type: object
607+
security:
608+
- BearerAuth: []
609+
summary: Update review progress
610+
tags:
611+
- reviews
555612
/api/v1/reviews/complete:
556613
post:
557614
consumes:

0 commit comments

Comments
 (0)