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

Add filters for projects #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add filters for projects #14

wants to merge 5 commits into from

Conversation

L1mple
Copy link

@L1mple L1mple commented Apr 18, 2023

Pull request

@L1mple L1mple self-assigned this Apr 18, 2023
@L1mple L1mple linked an issue Apr 18, 2023 that may be closed by this pull request
POSTGRES_PASSWORD: 1234
POSTGRES_DB: postgres
ports:
- 5440:5432
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add docker configuration? And how should app be launched now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the configuration for the database. If you don't want to use it, launching the application will be the same.

I added it because I don't want to touch the local database, so I created a docker file for this project. This is useful if you don't have postgres on your computer or don't want to touch it, it will be an isolated, clean database every time you run the container(but when app is launched seeding with liquibase still works for docker DB).


public interface ProjectService {
Iterable<ProjectTO> findAll();
ProjectTO findById(long id);
ProjectTO addProject(ProjectRequestTO project);
List<ProjectTO> findProjectsBetweenDates(Date startDate, Date endDate);
Copy link
Collaborator

@SerjVankovich SerjVankovich Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make return parameter Iterable<ProjectTO>

Copy link
Collaborator

@SerjVankovich SerjVankovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix comments

Copy link
Collaborator

@End-rey End-rey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fix all the problems. It would also be very cool if you could tell me what filters you need in the end, point by point, and need to implement all of them to merge into the master later. At the moment I can't start the server

@GetMapping
public Iterable<ProjectTO> getAllProjects() {
return projectService.findAll();
@GetMapping("/projects")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is path /data/projects already in @RequestMapping and it will be added to all paths, so do not add /projects to your @GetMapping. Now your path looks like this: loacalhost:8080/data/projects/projects

return projectService.findAll();
@GetMapping("/projects")
public List<ProjectTO> getProjectsBetweenDates(
@RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you delete get request with all project, most likely it should be that your query should output all projects if there are no parameters, but your parameters are required, and nowhere is it checked for their null. To do this, you can use Optional and in service check for null

public Iterable<ProjectTO> getAllProjects() {
return projectService.findAll();
@GetMapping("/projects")
public List<ProjectTO> getProjectsBetweenDates(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must do only filter by date?



@Query("SELECT p FROM public.Project as p, Tag as pt WHERE pt.tag_id = :tagID AND p.id = pt.project_id AND p.start > :startDate AND (p.end IS NULL OR p.end <= :endDate)")
List<Project> findProjectsBetweenDates(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("tagID") Integer tagID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you use here tagId and its Integer? And in the service, when you call this function, do not write any tagId, I get an error because of this



@Query("SELECT p FROM public.Project as p, Tag as pt WHERE pt.tag_id = :tagID AND p.id = pt.project_id AND p.start > :startDate AND (p.end IS NULL OR p.end <= :endDate)")
List<Project> findProjectsBetweenDates(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("tagID") Integer tagID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I could not start the server because the request was not written correctly

@@ -72,6 +73,12 @@ public ProjectTO addProject(ProjectRequestTO projectRequest) {
return ConvertToTO.projectToTO(project);
}

@Override
public List<ProjectTO> findProjectsBetweenDates(java.util.Date startDate, java.util.Date endDate) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make java.util.Date import

@@ -1,4 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres?useSSL=false
spring.datasource.url=jdbc:postgresql://localhost:5440/postgres?useSSL=false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you change port? If you use a docker, it is better to keep it on your computer, so that there will be no problems when they merge the branch into the master

@@ -1,6 +1,6 @@
classpath=
changeLogfile=db/changelog/db.changelog-master.xml
url=jdbc:postgresql://localhost:5432/postgres?useSSL=false
url=jdbc:postgresql://localhost:5440/postgres?useSSL=false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same problem as in src/main/resources/application.properties

@MicAPic
Copy link
Collaborator

MicAPic commented May 2, 2023

@End-rey, @SerjVankovich, can you please help me resolve the 3rd merge conflict?

@RequestParam(required = false, defaultValue = "[]") List<String> tags_from_request,
@RequestParam(required = false, defaultValue = "[]") List<String> clinics_from_request) {
return projectService.getProjects(string_to_search, startDate, endDate, sorting_by_Date, tags_from_request,
clinics_from_request);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to use camelCase instead of snake_case.


public interface ProjectRepo extends JpaRepository<Project, Long> {


// WHERE cast(p.id as text) LIKE %:string_to_search%"'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@End-rey
Copy link
Collaborator

End-rey commented May 4, 2023

I don't know why, but when i search by first word in description it doesn't work

"CASE WHEN :sorting_by_Date = 'ASC' THEN p.start END ASC, " +
"CASE WHEN :sorting_by_Date = 'DESC' THEN p.start END DESC, " +
"CASE WHEN :sorting_by_Date = 'NULL' THEN NULL END")
// "AND (t.name IN (:tags_from_request)) ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@Override
public Iterable<ProjectTO> getProjects(String string_to_search, Date startDate, Date endDate, Sort sorting_by_Date,
List<String> tags_from_request, List<String> clinics_from_request) {
// System.out.println(projectRepo.getProjectsByFilters());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@End-rey
Copy link
Collaborator

End-rey commented May 4, 2023

Search by supervisor does not work

@End-rey
Copy link
Collaborator

End-rey commented May 4, 2023

I think I figured out what the problem is. The search does not work if the word you want to find has a capital letter.

@End-rey
Copy link
Collaborator

End-rey commented May 4, 2023

The filter does not work when I enter a tag list:

PSQLException: ERROR: input of anonymous composite types is not implemented

Copy link
Collaborator

@SerjVankovich SerjVankovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix comments

@End-rey
Copy link
Collaborator

End-rey commented May 4, 2023

It is not very clear how the filter by date works. In theory, when I search by startDate should display projects exactly for the specified year and no more, the same with endDate - only projects that end in the specified year

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add filters
5 participants