RyZ commited on
Commit
75ce63a
·
1 Parent(s): c22329b

feat: adding essential feature for admin

Browse files
controllers/connection_controller.go DELETED
@@ -1,32 +0,0 @@
1
- package controllers
2
-
3
- import (
4
- "dinacom-11.0-backend/dto"
5
- "dinacom-11.0-backend/services"
6
- "dinacom-11.0-backend/utils"
7
-
8
- "github.com/gin-gonic/gin"
9
- )
10
-
11
- type ConnectionController interface {
12
- Connect(ctx *gin.Context)
13
- }
14
-
15
- type connectionController struct {
16
- connectionService services.ConnectionService
17
- }
18
-
19
- func NewConnectionController(connectionService services.ConnectionService) ConnectionController {
20
- return &connectionController{connectionService}
21
- }
22
-
23
- func (cc *connectionController) Connect(ctx *gin.Context) {
24
- var req dto.ConnectRequest
25
- if err := ctx.ShouldBindJSON(&req); err != nil {
26
- utils.SendResponse[any, any](ctx, nil, nil, err)
27
- return
28
- }
29
-
30
- err := cc.connectionService.Connect(ctx, req)
31
- utils.SendResponse[any, any](ctx, nil, nil, err)
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
controllers/report_controller.go CHANGED
@@ -23,6 +23,8 @@ type ReportController interface {
23
  GetWorkerAssignedReports(ctx *gin.Context)
24
  GetWorkerHistory(ctx *gin.Context)
25
  VerifyReport(ctx *gin.Context)
 
 
26
  }
27
 
28
  type reportController struct {
@@ -321,3 +323,69 @@ func (c *reportController) VerifyReport(ctx *gin.Context) {
321
 
322
  utils.SendSuccessResponse(ctx, "Report verified successfully", nil)
323
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  GetWorkerAssignedReports(ctx *gin.Context)
24
  GetWorkerHistory(ctx *gin.Context)
25
  VerifyReport(ctx *gin.Context)
26
+ GetReportDetail(ctx *gin.Context)
27
+ GetReportImage(ctx *gin.Context)
28
  }
29
 
30
  type reportController struct {
 
323
 
324
  utils.SendSuccessResponse(ctx, "Report verified successfully", nil)
325
  }
326
+
327
+ // @Summary Get Report Detail
328
+ // @Description Get assigned report detail for worker
329
+ // @Tags Worker
330
+ // @Produce json
331
+ // @Param report_id query string true "Report ID"
332
+ // @Security BearerAuth
333
+ // @Success 200 {object} dto.ReportDetailResponse
334
+ // @Failure 400 {object} map[string]string
335
+ // @Failure 401 {object} map[string]string
336
+ // @Router /api/worker/report/assign/detail [get]
337
+ func (c *reportController) GetReportDetail(ctx *gin.Context) {
338
+ workerIDVal, exists := ctx.Get("user_id")
339
+ if !exists {
340
+ utils.SendErrorResponse(ctx, http.StatusUnauthorized, "Unauthorized")
341
+ return
342
+ }
343
+ workerID := workerIDVal.(uuid.UUID)
344
+
345
+ reportID := ctx.Query("report_id")
346
+ if reportID == "" {
347
+ utils.SendErrorResponse(ctx, http.StatusBadRequest, "report_id is required")
348
+ return
349
+ }
350
+
351
+ response, err := c.reportService.GetReportDetail(workerID, reportID)
352
+ if err != nil {
353
+ utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
354
+ return
355
+ }
356
+
357
+ utils.SendSuccessResponse(ctx, "Report detail retrieved", response)
358
+ }
359
+
360
+ // @Summary Get Report Image
361
+ // @Description Get before image URL for assigned report
362
+ // @Tags Worker
363
+ // @Produce json
364
+ // @Param report_id query string true "Report ID"
365
+ // @Security BearerAuth
366
+ // @Success 200 {object} dto.ReportImageResponse
367
+ // @Failure 400 {object} map[string]string
368
+ // @Failure 401 {object} map[string]string
369
+ // @Router /api/worker/report/assign/image [get]
370
+ func (c *reportController) GetReportImage(ctx *gin.Context) {
371
+ workerIDVal, exists := ctx.Get("user_id")
372
+ if !exists {
373
+ utils.SendErrorResponse(ctx, http.StatusUnauthorized, "Unauthorized")
374
+ return
375
+ }
376
+ workerID := workerIDVal.(uuid.UUID)
377
+
378
+ reportID := ctx.Query("report_id")
379
+ if reportID == "" {
380
+ utils.SendErrorResponse(ctx, http.StatusBadRequest, "report_id is required")
381
+ return
382
+ }
383
+
384
+ response, err := c.reportService.GetReportImage(workerID, reportID)
385
+ if err != nil {
386
+ utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
387
+ return
388
+ }
389
+
390
+ utils.SendSuccessResponse(ctx, "Report image retrieved", response)
391
+ }
models/dto/user_report_dto.go CHANGED
@@ -30,3 +30,16 @@ type PaginatedReportsResponse struct {
30
  type VerifyReportRequest struct {
31
  ReportID string `json:"report_id" binding:"required"`
32
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  type VerifyReportRequest struct {
31
  ReportID string `json:"report_id" binding:"required"`
32
  }
33
+
34
+ type ReportDetailResponse struct {
35
+ BeforeImageURL string `json:"before_image_url"`
36
+ RoadName string `json:"road_name"`
37
+ Deadline *time.Time `json:"deadline"`
38
+ TotalScore float64 `json:"total_score"`
39
+ DestructClass string `json:"destruct_class"`
40
+ AdminNotes string `json:"admin_notes"`
41
+ }
42
+
43
+ type ReportImageResponse struct {
44
+ BeforeImageURL string `json:"before_image_url"`
45
+ }
repositories/connection_repositories.go DELETED
@@ -1,23 +0,0 @@
1
- package repositories
2
-
3
- import (
4
- "context"
5
- "gorm.io/gorm"
6
- )
7
-
8
- type ConnectionRepository interface {
9
- Connect(ctx context.Context) error
10
- }
11
-
12
- type connectionRepository struct {
13
- db *gorm.DB
14
- }
15
-
16
- func NewConnectionRepository(db *gorm.DB) ConnectionRepository {
17
- return &connectionRepository{db: db}
18
- }
19
-
20
- func (cr *connectionRepository) Connect(ctx context.Context) error {
21
- return nil
22
- }
23
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
router/report_router.go CHANGED
@@ -40,5 +40,7 @@ func (r *reportRouter) Setup(router *gin.RouterGroup) {
40
  workerGroup.Use(middleware.RoleMiddleware(entity.ROLE_WORKER, entity.ROLE_ADMIN))
41
  workerGroup.PATCH("/report", r.reportController.FinishReport)
42
  workerGroup.GET("/report/assign/me", r.reportController.GetWorkerAssignedReports)
 
 
43
  workerGroup.GET("/report/history/me", r.reportController.GetWorkerHistory)
44
  }
 
40
  workerGroup.Use(middleware.RoleMiddleware(entity.ROLE_WORKER, entity.ROLE_ADMIN))
41
  workerGroup.PATCH("/report", r.reportController.FinishReport)
42
  workerGroup.GET("/report/assign/me", r.reportController.GetWorkerAssignedReports)
43
+ workerGroup.GET("/report/assign/detail", r.reportController.GetReportDetail)
44
+ workerGroup.GET("/report/assign/image", r.reportController.GetReportImage)
45
  workerGroup.GET("/report/history/me", r.reportController.GetWorkerHistory)
46
  }
services/connection_service.go DELETED
@@ -1,23 +0,0 @@
1
- package services
2
-
3
- import (
4
- "context"
5
-
6
- "dinacom-11.0-backend/dto"
7
- "dinacom-11.0-backend/repositories"
8
- )
9
-
10
- type ConnectionService interface {
11
- Connect(ctx context.Context, req dto.ConnectRequest) error
12
- }
13
- type connectionService struct {
14
- connectionRepo repositories.ConnectionRepository
15
- }
16
-
17
- func NewConnectionService(connectionRepo repositories.ConnectionRepository) ConnectionService {
18
- return &connectionService{connectionRepo: connectionRepo}
19
- }
20
-
21
- func (s *connectionService) Connect(ctx context.Context, req dto.ConnectRequest) error {
22
- return s.connectionRepo.Connect(ctx)
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
services/report_service.go CHANGED
@@ -34,6 +34,8 @@ type ReportService interface {
34
  GetWorkerAssignedReports(workerID uuid.UUID, page, limit int) (*dto.PaginatedReportsResponse, error)
35
  GetWorkerHistory(workerID uuid.UUID, verifyAdmin bool, page, limit int) (*dto.PaginatedReportsResponse, error)
36
  VerifyReport(reportID string) error
 
 
37
  }
38
 
39
  type reportService struct {
@@ -283,3 +285,38 @@ func (s *reportService) buildPaginatedResponse(reports []entity.Report, total in
283
  TotalPages: totalPages,
284
  }
285
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  GetWorkerAssignedReports(workerID uuid.UUID, page, limit int) (*dto.PaginatedReportsResponse, error)
35
  GetWorkerHistory(workerID uuid.UUID, verifyAdmin bool, page, limit int) (*dto.PaginatedReportsResponse, error)
36
  VerifyReport(reportID string) error
37
+ GetReportDetail(workerID uuid.UUID, reportID string) (*dto.ReportDetailResponse, error)
38
+ GetReportImage(workerID uuid.UUID, reportID string) (*dto.ReportImageResponse, error)
39
  }
40
 
41
  type reportService struct {
 
285
  TotalPages: totalPages,
286
  }
287
  }
288
+
289
+ func (s *reportService) GetReportDetail(workerID uuid.UUID, reportID string) (*dto.ReportDetailResponse, error) {
290
+ report, err := s.reportRepo.GetReportByID(reportID)
291
+ if err != nil {
292
+ return nil, http_error.REPORT_NOT_FOUND
293
+ }
294
+
295
+ if report.WorkerID == nil || *report.WorkerID != workerID {
296
+ return nil, http_error.NOT_ASSIGNED_TO_REPORT
297
+ }
298
+
299
+ return &dto.ReportDetailResponse{
300
+ BeforeImageURL: report.BeforeImageURL,
301
+ RoadName: report.RoadName,
302
+ Deadline: report.Deadline,
303
+ TotalScore: report.TotalScore,
304
+ DestructClass: report.DestructClass,
305
+ AdminNotes: report.AdminNotes,
306
+ }, nil
307
+ }
308
+
309
+ func (s *reportService) GetReportImage(workerID uuid.UUID, reportID string) (*dto.ReportImageResponse, error) {
310
+ report, err := s.reportRepo.GetReportByID(reportID)
311
+ if err != nil {
312
+ return nil, http_error.REPORT_NOT_FOUND
313
+ }
314
+
315
+ if report.WorkerID == nil || *report.WorkerID != workerID {
316
+ return nil, http_error.NOT_ASSIGNED_TO_REPORT
317
+ }
318
+
319
+ return &dto.ReportImageResponse{
320
+ BeforeImageURL: report.BeforeImageURL,
321
+ }, nil
322
+ }