Add pet action management and update requests
This commit is contained in:
@@ -17,15 +17,37 @@ namespace pet_companion_api.Services
|
||||
return petRepository.GetPetsByUserId(userId.ToString());
|
||||
}
|
||||
|
||||
public Pet CreatePet(Guid userId, Pet pet)
|
||||
public Pet CreatePet(Guid userId, PetCreationRequest petRequest)
|
||||
{
|
||||
pet.Id = Guid.NewGuid().ToString();
|
||||
pet.UserId = userId.ToString();
|
||||
pet.Level = 1;
|
||||
pet.Stats = new PetStats(pet.Class);
|
||||
pet.Resources = new Resources();
|
||||
var pet = new Pet
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
UserId = userId.ToString(),
|
||||
Name = petRequest.Name,
|
||||
Class = petRequest.Class,
|
||||
Level = 1,
|
||||
Stats = PetStats.BuildFromClass(petRequest.Class),
|
||||
Resources = new Resources(),
|
||||
ActionSince = DateTime.UtcNow,
|
||||
PetAction = PetAction.IDLE,
|
||||
IsDead = false
|
||||
};
|
||||
|
||||
return petRepository.CreatePet(pet);
|
||||
}
|
||||
|
||||
public Pet UpdatePetAction(string petId, string userId, PetUpdateActionRequest actionRequest)
|
||||
{
|
||||
var pet = petRepository.GetPetById(petId, userId);
|
||||
if (pet == null)
|
||||
{
|
||||
throw new Exception("Pet not found");
|
||||
}
|
||||
|
||||
pet.PetAction = actionRequest.PetAction;
|
||||
pet.ActionSince = DateTime.UtcNow;
|
||||
|
||||
return petRepository.UpdatePetAction(pet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user