37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package useCases
|
|
|
|
import (
|
|
"RenewCMS/internal/domain/contenttype"
|
|
"RenewCMS/internal/domain/entry"
|
|
"RenewCMS/internal/domain/image"
|
|
"RenewCMS/internal/domain/role"
|
|
)
|
|
|
|
type GetEntryUseCase struct {
|
|
contentTypes contenttype.Repository
|
|
entries entry.Repository
|
|
images image.Repository
|
|
}
|
|
|
|
func NewGetEntryUseCase(contentTypes contenttype.Repository, entries entry.Repository, images image.Repository) *GetEntryUseCase {
|
|
return &GetEntryUseCase{contentTypes, entries, images}
|
|
}
|
|
|
|
func (u *GetEntryUseCase) Get(contentTypeKey string, id uint32, caller ContentCaller) (TypedEntry, error) {
|
|
if err := caller.requireHolding(role.KeyContentRead, contentTypeKey); err != nil {
|
|
return TypedEntry{}, err
|
|
}
|
|
owner, err := u.contentTypes.GetByKey(contentTypeKey)
|
|
if err != nil {
|
|
return TypedEntry{}, err
|
|
}
|
|
found, err := u.entries.Get(owner.ID, id)
|
|
if err != nil {
|
|
return TypedEntry{}, err
|
|
}
|
|
if !caller.reads(contentTypeKey, found.CreatedBy) {
|
|
return TypedEntry{}, entry.ErrEntryNotFound
|
|
}
|
|
return typedEntry(owner, found, newEntryResolvers(u.images, u.contentTypes, u.entries))
|
|
}
|