❔ Service layer design
This is my interface
and here are my the
My question is for
using OneOf;
namespace petaverseapi;
public interface IAnimalService
{
#region [ READS ]
Task<IEnumerable<AnimalDTO>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
Task<AnimalDTO?> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
#endregion
#region [ MUTATES ]
Task<OneOf<ServiceSuccess, ServiceError>> Create(CreatePetDTO dto, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalMultiplePhotosAsync(int animalId, MediaTypeDTO mediaType, IFormFileCollection medias, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalAvatarPhotoAsync(int animalId, IFormFile avatar, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalPhotoAsync(int animalId, IFormFile file, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> Delete(int id, string consumerName, CancellationToken cancellationToken = default!);
#endregion
}
using OneOf;
namespace petaverseapi;
public interface IAnimalService
{
#region [ READS ]
Task<IEnumerable<AnimalDTO>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
Task<AnimalDTO?> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
#endregion
#region [ MUTATES ]
Task<OneOf<ServiceSuccess, ServiceError>> Create(CreatePetDTO dto, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalMultiplePhotosAsync(int animalId, MediaTypeDTO mediaType, IFormFileCollection medias, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalAvatarPhotoAsync(int animalId, IFormFile avatar, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalPhotoAsync(int animalId, IFormFile file, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<ServiceSuccess, ServiceError>> Delete(int id, string consumerName, CancellationToken cancellationToken = default!);
#endregion
}
ServiceSuccess
and ServiceError
basically they are just return information.
namespace petaverseapi;
public record ServiceSuccess(string ServiceName = "",
string MethodName = "",
string ConsumerName = "",
object? AttachedData = default!) : PetaverseSuccess;
namespace petaverseapi;
public record ServiceSuccess(string ServiceName = "",
string MethodName = "",
string ConsumerName = "",
object? AttachedData = default!) : PetaverseSuccess;
namespace petaverseapi;
public record ServiceError(string ServiceName = "", string MethodName = "", string ConsumerName = "") : PetaverseError;
namespace petaverseapi;
public record ServiceError(string ServiceName = "", string MethodName = "", string ConsumerName = "") : PetaverseError;
FindAll
, FindById
and FindAllByUserGuid
should I return the same a the rest as OneOf<ServiceSuccess, ServiceError>
and attached the data in ?5 Replies
@TotechsStrypper r u there
Yeah ?
i fixed it
public interface IAnimalService
{
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<AnimalDTO?, ServiceError>> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
// Rest of the methods...
}
public interface IAnimalService
{
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<AnimalDTO?, ServiceError>> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
// Rest of the methods...
}
so you will use the same return type
ah no, you return a direct object data. I still others giving some thought on this
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.