feat: implement CommitService and register commit management routes in the API server
All checks were successful
Build and Release / release (push) Successful in 1m27s

This commit is contained in:
2026-05-06 10:58:44 +07:00
parent e7b0141684
commit ca05785a24
2 changed files with 10 additions and 1 deletions

View File

@@ -109,7 +109,7 @@ func (s *FiberServer) SetupServer(
geometryService := services.NewGeometryService(geometryRepo) geometryService := services.NewGeometryService(geometryRepo)
wikiService := services.NewWikiService(wikiRepo) wikiService := services.NewWikiService(wikiRepo)
projectService := services.NewProjectService(projectRepo) projectService := services.NewProjectService(projectRepo)
commitService := services.NewCommitService(poolPg, commitRepo, projectRepo) commitService := services.NewCommitService(poolPg, commitRepo, projectRepo, redis)
submissionService := services.NewSubmissionService( submissionService := services.NewSubmissionService(
submissionRepo, projectRepo, commitRepo, submissionRepo, projectRepo, commitRepo,
userRepo, wikiRepo, geometryRepo, entityRepo, userRepo, wikiRepo, geometryRepo, entityRepo,

View File

@@ -3,11 +3,13 @@ package services
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"history-api/internal/dtos/request" "history-api/internal/dtos/request"
"history-api/internal/dtos/response" "history-api/internal/dtos/response"
"history-api/internal/gen/sqlc" "history-api/internal/gen/sqlc"
"history-api/internal/models" "history-api/internal/models"
"history-api/internal/repositories" "history-api/internal/repositories"
"history-api/pkg/cache"
"history-api/pkg/constants" "history-api/pkg/constants"
"history-api/pkg/convert" "history-api/pkg/convert"
@@ -26,17 +28,20 @@ type commitService struct {
db *pgxpool.Pool db *pgxpool.Pool
commitRepo repositories.CommitRepository commitRepo repositories.CommitRepository
projectRepo repositories.ProjectRepository projectRepo repositories.ProjectRepository
c cache.Cache
} }
func NewCommitService( func NewCommitService(
db *pgxpool.Pool, db *pgxpool.Pool,
commitRepo repositories.CommitRepository, commitRepo repositories.CommitRepository,
projectRepo repositories.ProjectRepository, projectRepo repositories.ProjectRepository,
c cache.Cache,
) CommitService { ) CommitService {
return &commitService{ return &commitService{
db: db, db: db,
commitRepo: commitRepo, commitRepo: commitRepo,
projectRepo: projectRepo, projectRepo: projectRepo,
c: c,
} }
} }
@@ -129,6 +134,8 @@ func (s *commitService) CreateCommit(ctx context.Context, userID string, project
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to commit transaction") return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to commit transaction")
} }
_ = s.c.Del(ctx, fmt.Sprintf("project:id:%s", projectID))
return commit.ToResponse(), nil return commit.ToResponse(), nil
} }
@@ -163,6 +170,8 @@ func (s *commitService) RestoreCommit(ctx context.Context, userID string, projec
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore commit") return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore commit")
} }
_ = s.c.Del(ctx, fmt.Sprintf("project:id:%s", projectID))
return nil return nil
} }