Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gestion des stages Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fatima Ezzahra Majidi
Gestion des stages Backend
Merge requests
!2
Lier les services l'un à l'autre
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Lier les services l'un à l'autre
master
into
main
Overview
0
Commits
1
Pipelines
0
Changes
17
Merged
Fatima Ezzahra Majidi
requested to merge
master
into
main
2 months ago
Overview
0
Commits
1
Pipelines
0
Changes
17
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
40700f36
1 commit,
2 months ago
17 files
+
382
−
189
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
17
Search (e.g. *.vue) (Ctrl+P)
src/main/java/com/example/gestionstagesbackend/controllers/CandidacyController.java
+
59
−
16
Options
package
com.example.gestionstagesbackend.controllers
;
import
com.example.gestionstagesbackend.model.Candidacy
;
import
com.example.gestionstagesbackend.model.Student
;
import
com.example.gestionstagesbackend.model.Stage
;
import
com.example.gestionstagesbackend.model.UnivSupervisor
;
import
com.example.gestionstagesbackend.services.CandidacyService
;
import
com.example.gestionstagesbackend.services.StudentService
;
import
com.example.gestionstagesbackend.services.StageService
;
import
com.example.gestionstagesbackend.services.UnivSupervisorService
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@@ -11,30 +16,68 @@ import java.util.Optional;
@RestController
@RequestMapping
(
"/api/candidacies"
)
@CrossOrigin
(
origins
=
"*"
)
public
class
CandidacyController
{
private
final
CandidacyService
candidacyService
;
private
final
StudentService
studentService
;
private
final
StageService
stageService
;
private
final
UnivSupervisorService
univSupervisorService
;
public
CandidacyController
(
CandidacyService
candidacyService
)
{
public
CandidacyController
(
CandidacyService
candidacyService
,
StudentService
studentService
,
StageService
stageService
,
UnivSupervisorService
univSupervisorService
)
{
this
.
candidacyService
=
candidacyService
;
this
.
studentService
=
studentService
;
this
.
stageService
=
stageService
;
this
.
univSupervisorService
=
univSupervisorService
;
}
@GetMapping
public
List
<
Candidacy
>
getAllCandidacies
()
{
return
candidacyService
.
getAllCandidacies
();
}
@PostMapping
public
ResponseEntity
<?>
createCandidacy
(
@RequestBody
Candidacy
candidacy
)
{
if
(
candidacy
.
getStudent
()
==
null
||
candidacy
.
getStudent
().
getId
()
==
null
)
{
return
ResponseEntity
.
badRequest
().
body
(
"Student ID is required"
);
}
if
(
candidacy
.
getStage
()
==
null
||
candidacy
.
getStage
().
getId
()
==
null
)
{
return
ResponseEntity
.
badRequest
().
body
(
"Stage ID is required"
);
}
if
(
candidacy
.
getUnivSupervisor
()
!=
null
&&
candidacy
.
getUnivSupervisor
().
getId
()
==
null
)
{
return
ResponseEntity
.
badRequest
().
body
(
"UnivSupervisor ID is invalid"
);
}
@GetMapping
(
"/{id}"
)
public
Optional
<
Candidacy
>
getCandidacyById
(
@PathVariable
Long
id
)
{
return
candidacyService
.
getCandidacyById
(
id
);
Optional
<
Student
>
student
=
studentService
.
getStudentById
(
candidacy
.
getStudent
().
getId
());
Optional
<
Stage
>
stage
=
stageService
.
getStageById
(
candidacy
.
getStage
().
getId
());
Optional
<
UnivSupervisor
>
univSupervisor
=
Optional
.
empty
();
if
(
candidacy
.
getUnivSupervisor
()
!=
null
)
{
univSupervisor
=
univSupervisorService
.
getUnivSupervisorById
(
candidacy
.
getUnivSupervisor
().
getId
());
if
(
univSupervisor
.
isEmpty
())
{
return
ResponseEntity
.
badRequest
().
body
(
"UnivSupervisor not found"
);
}
}
if
(
student
.
isEmpty
())
{
return
ResponseEntity
.
badRequest
().
body
(
"Student not found"
);
}
if
(
stage
.
isEmpty
())
{
return
ResponseEntity
.
badRequest
().
body
(
"Stage not found"
);
}
candidacy
.
setStudent
(
student
.
get
());
candidacy
.
setStage
(
stage
.
get
());
univSupervisor
.
ifPresent
(
candidacy:
:
setUnivSupervisor
);
Candidacy
savedCandidacy
=
candidacyService
.
saveCandidacy
(
candidacy
);
return
ResponseEntity
.
ok
(
savedCandidacy
);
}
@
Pos
tMapping
public
Candidacy
saveCandidacy
(
@RequestBody
Candidacy
c
andidac
y
)
{
return
candidacyService
.
save
Candidac
y
(
candidacy
);
@
Ge
tMapping
public
ResponseEntity
<
List
<
Candidacy
>>
getAllC
andidac
ies
(
)
{
return
ResponseEntity
.
ok
(
candidacyService
.
getAll
Candidac
ies
()
);
}
@DeleteMapping
(
"/{id}"
)
public
void
deleteCandidacy
(
@PathVariable
Long
id
)
{
candidacyService
.
deleteCandidacy
(
id
);
@GetMapping
(
"/{id}"
)
public
ResponseEntity
<
Candidacy
>
getCandidacyById
(
@PathVariable
Long
id
)
{
return
candidacyService
.
getCandidacyById
(
id
)
.
map
(
ResponseEntity:
:
ok
)
.
orElse
(
ResponseEntity
.
notFound
().
build
());
}
}
Loading