This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ChangePet Functionality (#162)
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
web_backend/src/main/java/haw/teamagochi/backend/device/logic/UcChangePet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package haw.teamagochi.backend.device.logic; | ||
|
||
import haw.teamagochi.backend.device.dataaccess.model.DeviceEntity; | ||
|
||
public interface UcChangePet { | ||
|
||
/** | ||
* | ||
* @param deviceId id of the device | ||
* @param petId id of pet to be put on the device | ||
* @return the Device Entity | ||
*/ | ||
DeviceEntity changePet(long deviceId, long petId); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
web_backend/src/main/java/haw/teamagochi/backend/device/logic/UcChangePetImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package haw.teamagochi.backend.device.logic; | ||
|
||
import haw.teamagochi.backend.device.dataaccess.model.DeviceEntity; | ||
import haw.teamagochi.backend.device.dataaccess.repository.DeviceRepository; | ||
import haw.teamagochi.backend.pet.dataaccess.model.PetEntity; | ||
import haw.teamagochi.backend.pet.logic.UcFindPet; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.NotFoundException; | ||
|
||
@ApplicationScoped | ||
public class UcChangePetImpl implements UcChangePet{ | ||
|
||
@Inject | ||
DeviceRepository deviceRepository; | ||
|
||
@Inject | ||
UcFindDevice ucFindDevice; | ||
@Inject | ||
UcFindPet findPet; | ||
|
||
@Override | ||
@Transactional | ||
public DeviceEntity changePet(long deviceId, long petId) { | ||
DeviceEntity device = ucFindDevice.find(deviceId); | ||
PetEntity pet = findPet.find(petId); | ||
if(device == null || pet == null){ | ||
return null; | ||
} | ||
device.setPet(pet); | ||
//deviceRepository.persist(device); --> nicht da als @Transactional gekennzeichnet | ||
return device; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters