Merge branch 'backend-api' of ssh://gitea.piair.dev:2222/piair/MyINPulse into backend-api
This commit is contained in:
		@@ -9,6 +9,14 @@ jobs:
 | 
				
			|||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
    - name: Checkout sources
 | 
					    - name: Checkout sources
 | 
				
			||||||
      uses: actions/checkout@v4
 | 
					      uses: actions/checkout@v4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - name: Load .env file
 | 
				
			||||||
 | 
					      uses: xom9ikk/dotenv@v2.3.0
 | 
				
			||||||
 | 
					      with:
 | 
				
			||||||
 | 
					        path: ./config/
 | 
				
			||||||
 | 
					        mode: dev
 | 
				
			||||||
 | 
					        load-mode: strict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - name: Setup Java
 | 
					    - name: Setup Java
 | 
				
			||||||
      uses: actions/setup-java@v4
 | 
					      uses: actions/setup-java@v4
 | 
				
			||||||
      with:
 | 
					      with:
 | 
				
			||||||
@@ -18,8 +26,8 @@ jobs:
 | 
				
			|||||||
    - name: Setup Gradle
 | 
					    - name: Setup Gradle
 | 
				
			||||||
      uses: gradle/actions/setup-gradle@v4
 | 
					      uses: gradle/actions/setup-gradle@v4
 | 
				
			||||||
      with:
 | 
					      with:
 | 
				
			||||||
        cache-disabled: true
 | 
					        cache-disabled: true # Once the code has been pushed once in main, this should be reenabled. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - name: init gradle
 | 
					    - name: init gradle
 | 
				
			||||||
      working-directory: ./MyINPulse-back/
 | 
					      working-directory: ./MyINPulse-back/
 | 
				
			||||||
      run: ./gradlew build -x test # todo: run test, currently fail because no database is present 
 | 
					      run: ./gradlew build # todo: run test, currently fail because no database is present 
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								Makefile
									
									
									
									
									
								
							@@ -19,8 +19,14 @@ front/MyINPulse-front/.installed:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
vite: ./front/MyINPulse-front/.installed
 | 
					vite: ./front/MyINPulse-front/.installed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					keycloak: ./keycloak/.installed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dev-front: clean vite
 | 
					keycloak/.installed:
 | 
				
			||||||
 | 
						@echo "running one time install"
 | 
				
			||||||
 | 
						@cd keycloak/CAS && sudo sh build.sh
 | 
				
			||||||
 | 
						@touch ./keycloak/.installed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dev-front: clean vite keycloak
 | 
				
			||||||
	@cp config/frontdev.env front/MyINPulse-front/.env
 | 
						@cp config/frontdev.env front/MyINPulse-front/.env
 | 
				
			||||||
	@cp config/frontdev.env .env
 | 
						@cp config/frontdev.env .env
 | 
				
			||||||
	@cp config/frontdev.env MyINPulse-back/.env
 | 
						@cp config/frontdev.env MyINPulse-back/.env
 | 
				
			||||||
@@ -28,7 +34,7 @@ dev-front: clean vite
 | 
				
			|||||||
	@docker compose up -d --build
 | 
						@docker compose up -d --build
 | 
				
			||||||
	@cd ./front/MyINPulse-front/ && npm run dev
 | 
						@cd ./front/MyINPulse-front/ && npm run dev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prod: clean
 | 
					prod: clean keycloak
 | 
				
			||||||
	@cp config/prod.env front/MyINPulse-front/.env
 | 
						@cp config/prod.env front/MyINPulse-front/.env
 | 
				
			||||||
	@cp config/prod.env .env
 | 
						@cp config/prod.env .env
 | 
				
			||||||
	@cp config/prod.env .env
 | 
						@cp config/prod.env .env
 | 
				
			||||||
@@ -37,7 +43,7 @@ prod: clean
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dev-back:
 | 
					dev-back: keycloak
 | 
				
			||||||
	@cp config/backdev.env front/MyINPulse-front/.env
 | 
						@cp config/backdev.env front/MyINPulse-front/.env
 | 
				
			||||||
	@cp config/backdev.env .env
 | 
						@cp config/backdev.env .env
 | 
				
			||||||
	@cp config/backdev.env MyINPulse-back/.env
 | 
						@cp config/backdev.env MyINPulse-back/.env
 | 
				
			||||||
@@ -46,7 +52,7 @@ dev-back:
 | 
				
			|||||||
	@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
 | 
						@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
 | 
				
			||||||
	@echo "./gradlew bootRun --args='--server.port=8081'"
 | 
						@echo "./gradlew bootRun --args='--server.port=8081'"
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
dev: clean vite
 | 
					dev: clean vite keycloak
 | 
				
			||||||
	@cp config/dev.env front/MyINPulse-front/.env
 | 
						@cp config/dev.env front/MyINPulse-front/.env
 | 
				
			||||||
	@cp config/dev.env .env
 | 
						@cp config/dev.env .env
 | 
				
			||||||
	@cp config/dev.env MyINPulse-back/.env
 | 
						@cp config/dev.env MyINPulse-back/.env
 | 
				
			||||||
@@ -55,3 +61,13 @@ dev: clean vite
 | 
				
			|||||||
	@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
 | 
						@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
 | 
				
			||||||
	@echo "./gradlew bootRun --args='--server.port=8081'"
 | 
						@echo "./gradlew bootRun --args='--server.port=8081'"
 | 
				
			||||||
	@cd ./front/MyINPulse-front/ && npm run dev &
 | 
						@cd ./front/MyINPulse-front/ && npm run dev &
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test-back: clean keycloak
 | 
				
			||||||
 | 
						@cp config/dev.env front/MyINPulse-front/.env
 | 
				
			||||||
 | 
						@cp config/dev.env .env
 | 
				
			||||||
 | 
						@cp config/dev.env MyINPulse-back/.env
 | 
				
			||||||
 | 
						@cp config/dev.docker-compose.yaml docker-compose.yaml
 | 
				
			||||||
 | 
						@docker compose up -d --build
 | 
				
			||||||
 | 
						@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
 | 
				
			||||||
 | 
						@cd ./MyINPulse-back/ && ./gradlew test && ./gradlew jacocoTestReport
 | 
				
			||||||
 | 
						@firefox ./MyINPulse-back/build/jacocoHtml/index.html
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,6 @@ public class Entrepreneur extends User {
 | 
				
			|||||||
    public Entrepreneur() {}
 | 
					    public Entrepreneur() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Entrepreneur(
 | 
					    public Entrepreneur(
 | 
				
			||||||
            Long idUser,
 | 
					 | 
				
			||||||
            String userSurname,
 | 
					            String userSurname,
 | 
				
			||||||
            String username,
 | 
					            String username,
 | 
				
			||||||
            String primaryMail,
 | 
					            String primaryMail,
 | 
				
			||||||
@@ -46,7 +45,7 @@ public class Entrepreneur extends User {
 | 
				
			|||||||
            String school,
 | 
					            String school,
 | 
				
			||||||
            String course,
 | 
					            String course,
 | 
				
			||||||
            boolean sneeStatus) {
 | 
					            boolean sneeStatus) {
 | 
				
			||||||
        super(idUser, userSurname, username, primaryMail, secondaryMail, phoneNumber);
 | 
					        super(userSurname, username, primaryMail, secondaryMail, phoneNumber);
 | 
				
			||||||
        this.school = school;
 | 
					        this.school = school;
 | 
				
			||||||
        this.course = course;
 | 
					        this.course = course;
 | 
				
			||||||
        this.sneeStatus = sneeStatus;
 | 
					        this.sneeStatus = sneeStatus;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,8 @@ public class User {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public User() {}
 | 
					    public User() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: this should be removed as we shouldn't be able to chose the ID. Leaving it for
 | 
				
			||||||
 | 
					    // compatibility purposes, as soon as it's not used anymore, delete it
 | 
				
			||||||
    public User(
 | 
					    public User(
 | 
				
			||||||
            Long idUser,
 | 
					            Long idUser,
 | 
				
			||||||
            String userSurname,
 | 
					            String userSurname,
 | 
				
			||||||
@@ -43,6 +45,19 @@ public class User {
 | 
				
			|||||||
        this.phoneNumber = phoneNumber;
 | 
					        this.phoneNumber = phoneNumber;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public User(
 | 
				
			||||||
 | 
					            String userSurname,
 | 
				
			||||||
 | 
					            String userName,
 | 
				
			||||||
 | 
					            String primaryMail,
 | 
				
			||||||
 | 
					            String secondaryMail,
 | 
				
			||||||
 | 
					            String phoneNumber) {
 | 
				
			||||||
 | 
					        this.userSurname = userSurname;
 | 
				
			||||||
 | 
					        this.userName = userName;
 | 
				
			||||||
 | 
					        this.primaryMail = primaryMail;
 | 
				
			||||||
 | 
					        this.secondaryMail = secondaryMail;
 | 
				
			||||||
 | 
					        this.phoneNumber = phoneNumber;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Long getIdUser() {
 | 
					    public Long getIdUser() {
 | 
				
			||||||
        return idUser;
 | 
					        return idUser;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,7 +105,7 @@ public class AdminApiService {
 | 
				
			|||||||
    // TODO: check if tests are sufficient - peer verification required
 | 
					    // TODO: check if tests are sufficient - peer verification required
 | 
				
			||||||
    public void addNewProject(Project project) {
 | 
					    public void addNewProject(Project project) {
 | 
				
			||||||
        project.setIdProject(null);
 | 
					        project.setIdProject(null);
 | 
				
			||||||
        // We remove it from the request to be sure that it will be auto generated
 | 
					        // We remove the ID from the request to be sure that it will be auto generated
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            this.projectService.getProjectByName(project.getProjectName(), true);
 | 
					            this.projectService.getProjectByName(project.getProjectName(), true);
 | 
				
			||||||
            throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
 | 
					            throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
 | 
				
			||||||
@@ -115,8 +115,14 @@ public class AdminApiService {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Project newProject = projectService.addNewProject(project);
 | 
					        Project newProject = projectService.addNewProject(project);
 | 
				
			||||||
 | 
					        if (project.getProjectAdministrator() != null) {
 | 
				
			||||||
            newProject.getProjectAdministrator().updateListProject(newProject);
 | 
					            newProject.getProjectAdministrator().updateListProject(newProject);
 | 
				
			||||||
        newProject.getEntrepreneurProposed().setProjectProposed(newProject);
 | 
					        }
 | 
				
			||||||
 | 
					        if (newProject.getEntrepreneurProposed() != null) {
 | 
				
			||||||
 | 
					            Entrepreneur proposed = newProject.getEntrepreneurProposed();
 | 
				
			||||||
 | 
					            proposed.setProjectProposed(newProject);
 | 
				
			||||||
 | 
					            proposed.setProjectParticipation(newProject);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        newProject
 | 
					        newProject
 | 
				
			||||||
                .getListEntrepreneurParticipation()
 | 
					                .getListEntrepreneurParticipation()
 | 
				
			||||||
                .forEach(
 | 
					                .forEach(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,10 +5,12 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.*;
 | 
				
			|||||||
import static org.junit.jupiter.api.Assertions.*;
 | 
					import static org.junit.jupiter.api.Assertions.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import enseirb.myinpulse.model.Administrator;
 | 
					import enseirb.myinpulse.model.Administrator;
 | 
				
			||||||
 | 
					import enseirb.myinpulse.model.Entrepreneur;
 | 
				
			||||||
import enseirb.myinpulse.model.Project;
 | 
					import enseirb.myinpulse.model.Project;
 | 
				
			||||||
import enseirb.myinpulse.model.ProjectDecision;
 | 
					import enseirb.myinpulse.model.ProjectDecision;
 | 
				
			||||||
import enseirb.myinpulse.service.AdminApiService;
 | 
					import enseirb.myinpulse.service.AdminApiService;
 | 
				
			||||||
import enseirb.myinpulse.service.database.AdministratorService;
 | 
					import enseirb.myinpulse.service.database.AdministratorService;
 | 
				
			||||||
 | 
					import enseirb.myinpulse.service.database.EntrepreneurService;
 | 
				
			||||||
import enseirb.myinpulse.service.database.ProjectService;
 | 
					import enseirb.myinpulse.service.database.ProjectService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.BeforeAll;
 | 
					import org.junit.jupiter.api.BeforeAll;
 | 
				
			||||||
@@ -26,13 +28,16 @@ import java.util.List;
 | 
				
			|||||||
@Transactional
 | 
					@Transactional
 | 
				
			||||||
public class AdminApiServiceTest {
 | 
					public class AdminApiServiceTest {
 | 
				
			||||||
    private static long administratorid;
 | 
					    private static long administratorid;
 | 
				
			||||||
 | 
					    private static Administrator administrator;
 | 
				
			||||||
 | 
					    private static Entrepreneur entrepreneur;
 | 
				
			||||||
    @Autowired private AdminApiService adminApiService;
 | 
					    @Autowired private AdminApiService adminApiService;
 | 
				
			||||||
    @Autowired private ProjectService projectService;
 | 
					    @Autowired private ProjectService projectService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @BeforeAll
 | 
					    @BeforeAll
 | 
				
			||||||
    static void setup(
 | 
					    static void setup(
 | 
				
			||||||
            @Autowired AdministratorService administratorService,
 | 
					            @Autowired AdministratorService administratorService,
 | 
				
			||||||
            @Autowired ProjectService projectService) {
 | 
					            @Autowired ProjectService projectService,
 | 
				
			||||||
 | 
					            @Autowired EntrepreneurService entrepreneurService) {
 | 
				
			||||||
        administratorService.addAdministrator(
 | 
					        administratorService.addAdministrator(
 | 
				
			||||||
                new Administrator(
 | 
					                new Administrator(
 | 
				
			||||||
                        "admin",
 | 
					                        "admin",
 | 
				
			||||||
@@ -40,7 +45,7 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
                        "testAdminEmpty@example.com",
 | 
					                        "testAdminEmpty@example.com",
 | 
				
			||||||
                        "testAdmin@example.com",
 | 
					                        "testAdmin@example.com",
 | 
				
			||||||
                        ""));
 | 
					                        ""));
 | 
				
			||||||
        Administrator a =
 | 
					        administrator =
 | 
				
			||||||
                administratorService.addAdministrator(
 | 
					                administratorService.addAdministrator(
 | 
				
			||||||
                        new Administrator(
 | 
					                        new Administrator(
 | 
				
			||||||
                                "admin2",
 | 
					                                "admin2",
 | 
				
			||||||
@@ -48,7 +53,18 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
                                "testAdminFull@example.com",
 | 
					                                "testAdminFull@example.com",
 | 
				
			||||||
                                "testAdmin@example.com",
 | 
					                                "testAdmin@example.com",
 | 
				
			||||||
                                ""));
 | 
					                                ""));
 | 
				
			||||||
        administratorid = a.getIdUser();
 | 
					        administratorid = administrator.getIdUser();
 | 
				
			||||||
 | 
					        entrepreneur =
 | 
				
			||||||
 | 
					                new Entrepreneur(
 | 
				
			||||||
 | 
					                        "JeSuisUnEntrepreneurDeCompet",
 | 
				
			||||||
 | 
					                        "EtUé",
 | 
				
			||||||
 | 
					                        "Entrepreneur@inpulse.com",
 | 
				
			||||||
 | 
					                        "mail2",
 | 
				
			||||||
 | 
					                        "phone",
 | 
				
			||||||
 | 
					                        "Ensimag    nan jdeconne ENSEIRB (-matmeca mais on s'en fout)",
 | 
				
			||||||
 | 
					                        "info ofc",
 | 
				
			||||||
 | 
					                        false);
 | 
				
			||||||
 | 
					        entrepreneurService.addEntrepreneur(entrepreneur);
 | 
				
			||||||
        projectService.addNewProject(
 | 
					        projectService.addNewProject(
 | 
				
			||||||
                new Project(
 | 
					                new Project(
 | 
				
			||||||
                        "sampleProjectAdminApiService",
 | 
					                        "sampleProjectAdminApiService",
 | 
				
			||||||
@@ -161,6 +177,41 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
        assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size());
 | 
					        assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectToAdmin() {
 | 
				
			||||||
 | 
					        assertEquals(0, administrator.getListProject().size());
 | 
				
			||||||
 | 
					        Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, administrator);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(1, administrator.getListProject().size());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectToUser() {
 | 
				
			||||||
 | 
					        assertNull(entrepreneur.getProjectParticipation());
 | 
				
			||||||
 | 
					        Project p1 =
 | 
				
			||||||
 | 
					                new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, entrepreneur);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(p1, entrepreneur.getProjectParticipation());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectWithManyUsers() {
 | 
				
			||||||
 | 
					        Entrepreneur e1 = new Entrepreneur();
 | 
				
			||||||
 | 
					        Entrepreneur e2 = new Entrepreneur();
 | 
				
			||||||
 | 
					        Entrepreneur e3 = new Entrepreneur();
 | 
				
			||||||
 | 
					        assertNull(e1.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertNull(e2.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertNull(e3.getProjectParticipation());
 | 
				
			||||||
 | 
					        Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, null);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e1);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e2);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e3);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(p1, e1.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertEquals(p1, e2.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertEquals(p1, e3.getProjectParticipation());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    void addDuplicateProject() {
 | 
					    void addDuplicateProject() {
 | 
				
			||||||
        Project p1 =
 | 
					        Project p1 =
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								config/.env.dev
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								config/.env.dev
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					POSTGRES_DB=postgres_db
 | 
				
			||||||
 | 
					POSTGRES_USER=postgres
 | 
				
			||||||
 | 
					POSTGRES_PASSWORD=postgres_db_user_password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KEYCLOAK_ADMIN=admin
 | 
				
			||||||
 | 
					KEYCLOAK_ADMIN_PASSWORD=admin
 | 
				
			||||||
 | 
					KEYCLOAK_HOSTNAME=localhost
 | 
				
			||||||
 | 
					KEYCLOAK_DB=keycloak_db
 | 
				
			||||||
 | 
					KEYCLOAK_USER=keycloak_db_user
 | 
				
			||||||
 | 
					KEYCLOAK_PASSWORD=keycloak_db_user_password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BACKEND_DB=backend_db
 | 
				
			||||||
 | 
					BACKEND_USER=backend_db_user
 | 
				
			||||||
 | 
					BACKEND_PASSWORD=backend_db_user_password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DATABASE_URL=localhost:5433
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VITE_KEYCLOAK_URL=http://localhost:7080
 | 
				
			||||||
 | 
					VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev
 | 
				
			||||||
 | 
					VITE_KEYCLOAK_REALM=test
 | 
				
			||||||
 | 
					VITE_APP_URL=http://localhost:5173
 | 
				
			||||||
 | 
					VITE_BACKEND_URL=http://localhost:8081/
 | 
				
			||||||
		Reference in New Issue
	
	Block a user