❔ Service layer design

This is my interface
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

}
and here are my the 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;
My question is for FindAll, FindById and FindAllByUserGuid should I return the same a the rest as OneOf<ServiceSuccess, ServiceError> and attached the data in ?
5 Replies
0day
0day2y ago
@TotechsStrypper r u there
TotechsStrypper
TotechsStrypperOP2y ago
Yeah ?
0day
0day2y ago
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...
}
TotechsStrypper
TotechsStrypperOP2y ago
so you will use the same return type ah no, you return a direct object data. I still others giving some thought on this
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server