Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
abbenhoumi
IntegrationProjet
Commits
ef72fb08
Commit
ef72fb08
authored
Apr 10, 2020
by
benhoumine
Browse files
ajout méthode poubelle controller
parent
6a15b3b1
Pipeline
#6001
failed with stages
in 10 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/isima/f2/contrats/IAvertissement.java
View file @
ef72fb08
...
...
@@ -11,4 +11,5 @@ public interface IAvertissement {
public
Avertissement
modifierAvertissement
(
Avertissement
avertissement
);
public
Optional
<
Avertissement
>
getAvertissement
(
Long
id
);
public
List
<
Avertissement
>
getAvertissements
();
public
int
getNumberAvertissementPourEmploye
(
long
idEmploye
);
}
src/main/java/isima/f2/contrats/IPoubelle.java
View file @
ef72fb08
package
isima.f2.contrats
;
import
java.util.List
;
import
java.util.Optional
;
import
isima.f2.model.Poubelle
;
public
interface
IPoubelle
{
public
Poubelle
ajouterPoubelle
(
Poubelle
poubelle
);
public
void
deletePoubelle
(
Long
id
);
public
Poubelle
modifierPoubelle
(
Poubelle
poubelle
);
public
Optional
<
Poubelle
>
getPoubelle
(
Long
id
);
public
Poubelle
getPoubelle
(
Long
id
);
public
List
<
Poubelle
>
getPoubelles
();
public
void
viderPoubelle
(
long
id
);
}
src/main/java/isima/f2/controllers/AvertissementController.java
View file @
ef72fb08
package
isima.f2.controllers
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
isima.f2.model.Avertissement
;
import
isima.f2.services.ImpAvertissement
;
@RestController
@RequestMapping
(
"avertissement"
)
public
class
AvertissementController
{
@Autowired
private
ImpAvertissement
impAvertissement
;
@GetMapping
(
"/"
)
public
List
<
Avertissement
>
getAvertissement
()
{
return
impAvertissement
.
getAvertissements
();
}
@GetMapping
(
"/delete"
)
public
void
deleteAvertissement
(
Long
id
)
{
impAvertissement
.
deleteAvertissement
(
id
);
}
}
src/main/java/isima/f2/controllers/PoubelleController.java
View file @
ef72fb08
...
...
@@ -6,6 +6,7 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -26,12 +27,17 @@ public class PoubelleController {
public
List
<
Poubelle
>
getPoubelles
()
{
return
poubelles
.
getPoubelles
();
}
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
Poubelle
getPoubelle
(
@PathVariable
long
id
)
{
return
poubelles
.
getPoubelle
(
id
);
}
@PostMapping
(
value
=
"/savepoubelle"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
Poubelle
savePoubelle
(
@RequestBody
Poubelle
poubelle
)
{
return
poubelles
.
ajouterPoubelle
(
poubelle
);
}
@PostMapping
(
"/vider"
)
@ResponseBody
public
String
viderPoubelle
(
@RequestParam
Map
<
String
,
String
>
allParams
)
{
...
...
src/main/java/isima/f2/dao/IAvertissementDAO.java
View file @
ef72fb08
package
isima.f2.dao
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
isima.f2.model.Avertissement
;
@Repository
public
interface
IAvertissementDAO
extends
JpaRepository
<
Avertissement
,
Long
>{
}
@Query
(
value
=
"SELECT * FROM invertissement WHERE employe.id = ?1"
,
countQuery
=
"SELECT count(*) FROM invertissement WHERE employe.id = ?1"
,
nativeQuery
=
true
)
public
int
getNombreAvertissementByIdEmploye
(
long
id
);
}
\ No newline at end of file
src/main/java/isima/f2/model/Avertissement.java
View file @
ef72fb08
...
...
@@ -5,6 +5,7 @@ import java.io.Serializable;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.OneToOne
;
@Entity
public
class
Avertissement
implements
Serializable
{
...
...
@@ -14,6 +15,9 @@ public class Avertissement implements Serializable {
@Id
@GeneratedValue
private
Long
id
;
@OneToOne
private
Employe
employe
;
public
Avertissement
()
{
super
();
...
...
@@ -25,7 +29,16 @@ public class Avertissement implements Serializable {
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
Employe
getEmploye
()
{
return
employe
;
}
public
void
setEmploye
(
Employe
employe
)
{
this
.
employe
=
employe
;
}
}
src/main/java/isima/f2/services/ImpAvertissement.java
View file @
ef72fb08
...
...
@@ -3,14 +3,17 @@ package isima.f2.services;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
isima.f2.contrats.IAvertissement
;
import
isima.f2.dao.IAvertissementDAO
;
import
isima.f2.model.Avertissement
;
@Service
public
class
ImpAvertissement
implements
IAvertissement
{
@Autowired
private
IAvertissementDAO
avertissementDAO
;
private
IAvertissementDAO
avertissementDAO
;
@Override
public
Avertissement
ajouterAvertissement
(
Avertissement
avertissement
)
{
...
...
@@ -19,7 +22,7 @@ public class ImpAvertissement implements IAvertissement {
@Override
public
void
deleteAvertissement
(
Long
id
)
{
avertissementDAO
.
deleteById
(
id
);
avertissementDAO
.
deleteById
(
id
);
}
@Override
...
...
@@ -38,4 +41,10 @@ public class ImpAvertissement implements IAvertissement {
return
avertissementDAO
.
findAll
();
}
@Override
public
int
getNumberAvertissementPourEmploye
(
long
idEmploye
)
{
return
avertissementDAO
.
getNombreAvertissementByIdEmploye
(
idEmploye
);
}
}
src/main/java/isima/f2/services/ImpPoubelle.java
View file @
ef72fb08
...
...
@@ -5,7 +5,6 @@ import java.util.Optional;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
isima.f2.contrats.IPoubelle
;
import
isima.f2.dao.IPoubelleDAO
;
import
isima.f2.model.Poubelle
;
...
...
@@ -23,7 +22,7 @@ public class ImpPoubelle implements IPoubelle{
@Override
public
void
deletePoubelle
(
Long
id
)
{
poubelleDAO
.
delete
(
getPoubelle
(
id
));
}
@Override
...
...
@@ -32,8 +31,12 @@ public class ImpPoubelle implements IPoubelle{
}
@Override
public
Optional
<
Poubelle
>
getPoubelle
(
Long
id
)
{
return
null
;
public
Poubelle
getPoubelle
(
Long
id
)
{
Optional
<
Poubelle
>
poubelle
=
poubelleDAO
.
findById
(
id
);
if
(
poubelle
.
isPresent
())
{
return
poubelle
.
get
();
}
return
null
;
}
@Override
...
...
src/test/java/isima/F2/RamassagePoubleDepotApplicationTests.java
View file @
ef72fb08
...
...
@@ -3,14 +3,20 @@ package isima.F2;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.test.context.junit4.SpringRunner
;
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
class
RamassagePoubleDepotApplicationTests
{
@LocalServerPort
...
...
@@ -21,7 +27,6 @@ class RamassagePoubleDepotApplicationTests {
@Test
public
void
testRunServerRamassageAppTest
()
throws
Exception
{
assertThat
(
this
.
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/"
,
String
.
class
)).
isNotEmpty
();
}
...
...
src/test/java/isima/F2/controller/PoubelleControllerTest.java
View file @
ef72fb08
...
...
@@ -40,5 +40,14 @@ public class PoubelleControllerTest {
.
andExpect
(
content
().
string
(
containsString
(
"\"id\":null"
)));
}
@Test
public
void
verificationGetPoubelleMethode
()
throws
Exception
{
long
idPoubelle
=
1
;
//Return null car Il n'y pas une initialisation de constructeur
when
(
service
.
getPoubelle
(
idPoubelle
)).
thenReturn
(
null
);
this
.
mockMvc
.
perform
(
get
(
"/poubelles/1"
)).
andDo
(
print
()).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
containsString
(
"null"
)));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment