diff --git a/cmd/api/server.go b/cmd/api/server.go index 9e5963f..c4e3068 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -109,7 +109,7 @@ func (s *FiberServer) SetupServer( geometryService := services.NewGeometryService(geometryRepo) wikiService := services.NewWikiService(wikiRepo) projectService := services.NewProjectService(projectRepo) - commitService := services.NewCommitService(poolPg, commitRepo, projectRepo) + commitService := services.NewCommitService(poolPg, commitRepo, projectRepo, redis) submissionService := services.NewSubmissionService( submissionRepo, projectRepo, commitRepo, userRepo, wikiRepo, geometryRepo, entityRepo, diff --git a/internal/services/commitService.go b/internal/services/commitService.go index 180ea20..f189eb6 100644 --- a/internal/services/commitService.go +++ b/internal/services/commitService.go @@ -3,11 +3,13 @@ package services import ( "context" "encoding/json" + "fmt" "history-api/internal/dtos/request" "history-api/internal/dtos/response" "history-api/internal/gen/sqlc" "history-api/internal/models" "history-api/internal/repositories" + "history-api/pkg/cache" "history-api/pkg/constants" "history-api/pkg/convert" @@ -26,17 +28,20 @@ type commitService struct { db *pgxpool.Pool commitRepo repositories.CommitRepository projectRepo repositories.ProjectRepository + c cache.Cache } func NewCommitService( db *pgxpool.Pool, commitRepo repositories.CommitRepository, projectRepo repositories.ProjectRepository, + c cache.Cache, ) CommitService { return &commitService{ db: db, commitRepo: commitRepo, 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") } + _ = s.c.Del(ctx, fmt.Sprintf("project:id:%s", projectID)) + return commit.ToResponse(), nil } @@ -163,6 +170,8 @@ func (s *commitService) RestoreCommit(ctx context.Context, userID string, projec if err != nil { return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore commit") } + + _ = s.c.Del(ctx, fmt.Sprintf("project:id:%s", projectID)) return nil }