Add pet action management and update requests

This commit is contained in:
2025-02-01 00:29:33 -03:00
parent 4c4036a266
commit e1c5eed02d
12 changed files with 337 additions and 36 deletions

View File

@@ -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);
}
}
}