Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

create user if userId not found in db #132

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import haw.teamagochi.backend.device.logic.registrationmanager.RegistrationManager;
import haw.teamagochi.backend.user.dataaccess.model.UserEntity;
import haw.teamagochi.backend.user.logic.UcFindUser;
import haw.teamagochi.backend.user.logic.UcManageUser;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
Expand All @@ -22,6 +23,9 @@ public class UcManageDeviceImpl implements UcManageDevice {
@Inject
UcFindUser ucFindUser;

@Inject
UcManageUser ucManageUser;

@Inject
UcManageDevice ucManageDevice;

Expand Down Expand Up @@ -81,7 +85,8 @@ public DeviceEntity registerDevice(String registrationCode, String deviceName, S

UserEntity owner = ucFindUser.find(uuid);
if (owner == null) {
throw new IllegalArgumentException("User does not exist");
ucManageUser.create(uuid); // create userId in database
owner = ucFindUser.find(uuid);
}

DeviceEntity device = new DeviceEntity(deviceName, DeviceType.FROG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import haw.teamagochi.backend.pet.logic.UcManagePet;
import haw.teamagochi.backend.pet.service.rest.v1.mapper.PetMapper;
import haw.teamagochi.backend.pet.service.rest.v1.model.PetDTO;
import haw.teamagochi.backend.user.dataaccess.model.UserEntity;
import haw.teamagochi.backend.user.logic.UcFindUser;
import haw.teamagochi.backend.user.logic.UcManageUser;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand Down Expand Up @@ -38,6 +41,12 @@ public class PetRestSelfService {
@Inject
protected UcManagePet ucManagePet;

@Inject
protected UcFindUser ucFindUser;

@Inject
protected UcManageUser ucManageUser;

/**
* Get all pets.
*
Expand All @@ -63,6 +72,10 @@ public List<PetDTO> getAllPets() {
@APIResponse(responseCode = "200")
public PetDTO createPet(PetDTO dto) {
String uuid = SecurityUtil.getExternalUserId(identity);
UserEntity owner = ucFindUser.find(uuid);
if (owner == null) {
ucManageUser.create(uuid); // create userId in database
}
dto.setOwnerId(uuid);
PetEntity entity = petMapper.mapTransferObjectToEntity(dto);
ucManagePet.create(entity);
Expand Down