repository attachment api
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"eslogad-be/internal/contract"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type RepositoryAttachmentProcessor interface {
|
||||
CreateAttachment(ctx context.Context, req *contract.CreateRepositoryAttachmentRequest) (*contract.RepositoryAttachmentsResponse, error)
|
||||
DeleteAttachment(ctx context.Context, id uuid.UUID) error
|
||||
GetById(ctx context.Context, id uuid.UUID) (*contract.RepositoryAttachmentsResponse, error)
|
||||
ListAttachment(ctx context.Context, search *string, limit, offset int) ([]contract.RepositoryAttachmentsResponse, int, error)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"eslogad-be/internal/contract"
|
||||
"eslogad-be/internal/transformer"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type RepositoryAttachmentServiceImpl struct {
|
||||
attachmentProcessor RepositoryAttachmentProcessor
|
||||
}
|
||||
|
||||
func NewRepositoryAttachmentService(attachmentProcessor RepositoryAttachmentProcessor) *RepositoryAttachmentServiceImpl {
|
||||
return &RepositoryAttachmentServiceImpl{
|
||||
attachmentProcessor: attachmentProcessor,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RepositoryAttachmentServiceImpl) CreateAttachment(ctx context.Context, req *contract.CreateRepositoryAttachmentRequest) (*contract.RepositoryAttachmentsResponse, error) {
|
||||
return s.attachmentProcessor.CreateAttachment(ctx, req)
|
||||
}
|
||||
|
||||
func (s *RepositoryAttachmentServiceImpl) DeleteAttachment(ctx context.Context, id uuid.UUID) error {
|
||||
return s.attachmentProcessor.DeleteAttachment(ctx, id)
|
||||
}
|
||||
|
||||
func (s *RepositoryAttachmentServiceImpl) GetById(ctx context.Context, id uuid.UUID) (*contract.RepositoryAttachmentsResponse, error) {
|
||||
return s.attachmentProcessor.GetById(ctx, id)
|
||||
}
|
||||
|
||||
func (s *RepositoryAttachmentServiceImpl) ListAttachment(ctx context.Context, req *contract.ListRepositoryAttachmentsRequest) (*contract.ListRepositoryAttachmentsResponse, error) {
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
limit := req.Limit
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
if limit > 100 {
|
||||
limit = 100 // Max limit to prevent performance issues
|
||||
}
|
||||
|
||||
offset := (page - 1) * limit
|
||||
|
||||
// Pass calculated offset and limit to processor
|
||||
attachmentResponses, totalCount, err := s.attachmentProcessor.ListAttachment(ctx, req.Search, limit, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &contract.ListRepositoryAttachmentsResponse{
|
||||
Attachments: attachmentResponses,
|
||||
Pagination: transformer.CreatePaginationResponse(totalCount, page, limit),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user