feat(repository): Add Find method for service repository
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
All(ctx context.Context, limit, offset int, publicOnly bool) ([]model.Service, error)
|
All(ctx context.Context, limit, offset int, publicOnly bool) ([]model.Service, error)
|
||||||
|
Find(ctx context.Context, serviceID int) (*model.Service, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
@@ -48,3 +49,15 @@ func (s *service) All(ctx context.Context, limit, offset int, publicOnly bool) (
|
|||||||
return items, query.
|
return items, query.
|
||||||
Error
|
Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) Find(ctx context.Context, serviceID int) (*model.Service, error) {
|
||||||
|
item := &model.Service{}
|
||||||
|
|
||||||
|
return item, s.db.
|
||||||
|
WithContext(ctx).
|
||||||
|
Preload("Statuses", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Order("created_at desc")
|
||||||
|
}).
|
||||||
|
First(&item, "id", serviceID).
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user