60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
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
|
|
}
|