Skip to content

Commit

Permalink
checkAtLeastTwoSpecificUserProfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev committed Jul 19, 2024
1 parent 61b96aa commit e939d5a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public class UserProfiles extends PanacheEntityBase implements Serializable {
private Timestamp lastUpdatedAt;
public UserProfiles(UserProfilesPK userProfilesPK) {
this.userProfilesPK = userProfilesPK;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

@ApplicationScoped
public class UserProfilesRepository implements PanacheRepositoryBase<UserProfiles, UserProfilesPK> {
/*public Uni<Long> deleteByUserId(String userId) {
return delete(
"delete from UserProfiles b where b.userProfilesPK.userId = :userId",
Parameters.with("userId", userId));
}*/

public Uni<Long> deleteUserProfiles(List<UserProfilesPK> pKList) {
return delete("delete from UserProfiles b where b.userProfilesPK in :pKList",
Expand All @@ -27,8 +22,8 @@ public Uni<List<UserProfiles>> findByUserId (String userId) {
Parameters.with("userId", userId)).list();
}

/*public Uni<List<UserProfiles>> findByIds (List<String> userProfilePkList) {
return find("select c from UserProfiles c where c.userProfilesPK in :userProfilePkList",
Parameters.with("userProfilePkList",userProfilePkList)).list();
}*/
public Uni<List<UserProfiles>> findUserProfilesWithSpecificProfile() {
return find("select a from UserProfiles a where a.userProfilesPK.profileId = 5").list();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.validation.Valid;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
Expand Down Expand Up @@ -49,6 +50,19 @@ public Uni<List<UserProfilesDTO>> update(@RequestBody(required = true) @Valid Us
.transform(updatedUserProfiles -> userProfilesMapper.toDtoList(updatedUserProfiles));
}

@GET
@Path("/insert-with-profiles")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> checkSpecificProfiles() {
return userProfilesService.checkAtLeastTwoSpecificUserProfiles()
.onItem()
.transform(isAtLeastTwo -> Response.ok(isAtLeastTwo).build())
.onFailure()
.recoverWithItem(th -> Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(th.getMessage())
.build());
}

@GET
@Path("/userId/{userId}/profileId/{profileId}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface UserProfilesService {
Uni<Void> deleteUserProfiles(UserProfilesPK userProfilesIDs);

Uni<List<UserProfiles>> updateUserProfiles(UserProfilesInsertionDTO userProfilesInsertionDTO);

Uni<Void> checkAtLeastTwoSpecificUserProfiles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ public Uni<List<UserProfiles>> updateUserProfiles(UserProfilesInsertionDTO userP
})
)
);
}

@WithSession
public Uni<Void> checkAtLeastTwoSpecificUserProfiles() {
return hasAtLeastTwoSpecificUserProfiles()
.onItem()
.transform(isAtLeastTwo -> {
if (!isAtLeastTwo) {
throw new AtmLayerException("Meno di due occorrenze trovate per il profilo specificato.", Response.Status.BAD_REQUEST, AppErrorCodeEnum.NO_ASSOCIATION_FOUND);
}
return null;
});
}

@WithSession
public Uni<Boolean> hasAtLeastTwoSpecificUserProfiles() {
return userProfilesRepository.findUserProfilesWithSpecificProfile()
.onItem()
.transform(userProfiles -> userProfiles.size() >= 2);
}

}

0 comments on commit e939d5a

Please sign in to comment.