From fcf4e1c01d48b0a5963d1c2c5da24219107b4dfb Mon Sep 17 00:00:00 2001 From: MAILLAL Anas Date: Tue, 29 Apr 2025 21:22:13 +0200 Subject: [PATCH] feat: added an endpoint for fething the project an entrepreneur is associated with --- .../myinpulse/controller/EntrepreneurApi.java | 15 +++++++++++ .../service/EntrepreneurApiService.java | 12 +++++++++ .../openapi/src/entrepreneurApi.yaml | 26 ++++++++++++++++++- documentation/openapi/src/main.yaml | 3 +++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java index c0f3638..f5c23d1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java @@ -1,10 +1,12 @@ package enseirb.myinpulse.controller; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -42,6 +44,19 @@ public class EntrepreneurApi { sectionCellId, content, principal.getClaimAsString("email")); } + /** + * Endpoint used to update a LC section. + * + * @return status code + */ + @GetMapping("/entrepreneur/projects") + public Iterable getEntrepreneurProjectId( + @PathVariable Long sectionCellId, + @RequestBody String content, + @AuthenticationPrincipal Jwt principal) { + return entrepreneurApiService.getProjectIdViaClaim(principal.getClaimAsString("email")); + } + /** * TODO: checkReturn Type * diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index c89a35f..571b5ff 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -14,7 +14,10 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; + import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; @Service public class EntrepreneurApiService { @@ -219,4 +222,13 @@ public class EntrepreneurApiService { } throw new ResponseStatusException(HttpStatus.CONFLICT, "User already exists in the system"); } + + public Iterable getProjectIdViaClaim(String email) { + Long UserId = this.userService.getUserByEmail(email).getIdUser(); + Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(UserId); + List Project_List = new ArrayList<>(); + ; + Project_List.add(entrepreneur.getProjectParticipation()); + return Project_List; + } } diff --git a/documentation/openapi/src/entrepreneurApi.yaml b/documentation/openapi/src/entrepreneurApi.yaml index 3041742..6dd4a46 100644 --- a/documentation/openapi/src/entrepreneurApi.yaml +++ b/documentation/openapi/src/entrepreneurApi.yaml @@ -109,4 +109,28 @@ paths: "404": description: Bad Request - sectionCell not found. "401": - description: Unauthorized. \ No newline at end of file + description: Unauthorized. + + + /entrepreneur/projects: + get: + summary: gets the projectId of the project associated with the entrepreneur + description: returns a list of projectIds of the projects associated with the entrepreneur + tags: + - Entrepreneurs API + security: + - MyINPulse: [MyINPulse-entrepreneur] + parameters: + responses: + "200": + description: OK - Section cell updated successfully. Returns the updated cell. + content: + application/json: + schema: + type: array + items: + $ref: "./main.yaml#/components/schemas/project" + "404": + description: Bad Request - Invalid input or ID mismatch. + "401": + description: Unauthorized or identity not found \ No newline at end of file diff --git a/documentation/openapi/src/main.yaml b/documentation/openapi/src/main.yaml index 4c87d94..6cf5cb6 100644 --- a/documentation/openapi/src/main.yaml +++ b/documentation/openapi/src/main.yaml @@ -138,6 +138,9 @@ paths: # / ___ \| __/| | # /_/ \_\_| |___| # + + /entrepreneur/projects: + $ref: "./entrepreneurApi.yaml#/paths/~1entrepreneur~1projects" /entrepreneur/projects/request: $ref: "./entrepreneurApi.yaml#/paths/~1entrepreneur~1projects~1request" /entrepreneur/sectionCells: