Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Convert Business Logic JpaRepository to ReactiveMongoRepository #22764

Closed
camenduru opened this issue Jul 3, 2023 · 3 comments
Closed

Comments

@camenduru
Copy link

Hi I am new 👋 leaning jhipster and spring

thanks for the example https://github.com/mraible/jhipster6-demo#add-business-logic

How can I convert JpaRepository Query to ReactiveMongoRepository Query

public interface BlogRepository extends JpaRepository<Blog, Long> {
    @Query("select blog from Blog blog where blog.user.login = ?#{principal.username}")
    List<Blog> findByUserIsCurrentUser();
}

I tried this but not worked

public interface JobRepository extends ReactiveMongoRepository<Job, String> {
    @Query("{'user.login': ?0}")
    Flux<Job> findByUserIsCurrentUser();
}

Job class

public class Job implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    @NotNull(message = "must not be null")
    @Field("prompt")
    private String prompt;

    @NotNull(message = "must not be null")
    @Field("status")
    private JobStatus status;

    @Field("user")
    private User user;
...

I want just list SecurityUtils.getCurrentUserLogin() jobs

    @GetMapping(value = "/jobs", produces = MediaType.APPLICATION_JSON_VALUE)
    public Mono<List<Job>> getAllJobs(@RequestParam(required = false, defaultValue = "false") boolean eagerload) {
        log.debug("REST request to get all Jobs");
        if (eagerload) {
            // return jobRepository.findByUserIsCurrentUser().collectList(); ???
            return jobRepository.findAllWithEagerRelationships().collectList();
        } else {
            return jobRepository.findAll().collectList();
        }
    }
@mraible
Copy link
Contributor

mraible commented Jul 3, 2023

The easiest thing to do is probably to re-create the demo project using MongoDB instead of SQL.

@camenduru
Copy link
Author

Hi @mraible 👋 yep I re-created the project using MongoDB instead of SQL and added Job entity

enum JobStatus {
    WAITING, WORKING, DONE, FAILED
}

entity Job {
    prompt String required
    status JobStatus required
}

relationship ManyToOne {
    Job{user(login)} to User with builtInEntity
}

@mraible
Copy link
Contributor

mraible commented Jul 3, 2023

OK, in that case, hopefully, someone with more MongoDB can answer your question on how to convert the repository.

@DanielFran DanielFran added this to the 8.0.0-beta.2 milestone Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants