Commit dd0b4e78 authored by elisabeth kee's avatar elisabeth kee

Function de la modification prenom des profiles

parent 926ad82e
...@@ -89,13 +89,13 @@ public class ProfileResource { ...@@ -89,13 +89,13 @@ public class ProfileResource {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{id}/updateFirstname") @Path("{id}/updateFirstname")
public Response updateFirstname(@PathParam("id") Long id, Profile p) { public Response updateFirstname(@PathParam("id") Long id, String newFirstname) {
String firstname = p.getFirstname(); String newFirstname2 = newFirstname.replace('"',' ');
Optional<Profile> optional = profileRepository.findById(id); Optional<Profile> optional = profileRepository.findById(id);
if (optional.isPresent()) { if (optional.isPresent()) {
Profile pBDD = optional.get(); Profile pBDD = optional.get();
pBDD.setFirstname(firstname); pBDD.setFirstname(newFirstname2.strip());
profileRepository.save(pBDD); profileRepository.save(pBDD);
return Response.ok(pBDD).build(); return Response.ok(pBDD).build();
} else { } else {
......
...@@ -3,10 +3,14 @@ $(document).ready(function() { ...@@ -3,10 +3,14 @@ $(document).ready(function() {
let $listeProfilesDelete = $("#listProfilesDelete"); let $listeProfilesDelete = $("#listProfilesDelete");
let $listeProfilesSelect = $("#listProfilesSelect"); let $listeProfilesSelect = $("#listProfilesSelect");
let $listeProfilesSelect2 = $("#listProfilesSelect2"); let $listeProfilesSelect2 = $("#listProfilesSelect2");
let $listeMatches= $("#listMatches"); let $listeMatches = $("#listMatches");
let $listeMyProfile= $("#myProfile"); //let $listeMyProfile= $("#myProfile");
let $selectLovers = $("#selectLovers"); let $selectLovers = $("#selectLovers");
let $selectLovers2 = $("#selectLovers2"); let $selectLovers2 = $("#selectLovers2");
let $modifyFirstnameText = $("#firstname-modify");
let $modifyFirstnameButton = $("#modifyFirstname");
let $listModifiedProfile = $("#showModifiedProfile");
let $buttonSeeModifications = $("#seeModifications");
$.get("http://localhost:8080/api/profiles",function(resp){ $.get("http://localhost:8080/api/profiles",function(resp){
resp.forEach( p => { resp.forEach( p => {
...@@ -43,21 +47,18 @@ $(document).ready(function() { ...@@ -43,21 +47,18 @@ $(document).ready(function() {
}); });
}); });
$listeProfilesSelect2.on("click", "li button", function() { $('#modifyLover').click(function(){
let idProfile = $(this).parent().attr('id'); let idProfile = $listeProfilesSelect2.val();
$.ajax({ $.ajax({
type: "GET", type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-',''), url: "http://localhost:8080/api/profiles/"+idProfile+"/updateLovers",
contentType: "application/json; charset=utf-8",
dataType: "json", dataType: "json",
success: function(data){ success: function(data){
appendToListMyProfile(data);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert("Impossible de trouver le profile");
} }
}); });
}); });
$listeLovers.on("click", "li button", function() { $listeLovers.on("click", "li button", function() {
...@@ -79,6 +80,32 @@ $(document).ready(function() { ...@@ -79,6 +80,32 @@ $(document).ready(function() {
}); });
}); });
$('#modifyFirstname').click(function(){
let idProfile = $listeProfilesSelect2.val();
let newFirstname = $('#firstname-modify').val();
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile+"/updateFirstname",
data: JSON.stringify(newFirstname),
contentType: "application/json; charset=utf-8",
dataType: "json",
/*
//You blocked this code because you want to show the new profile at the very end after they
//have made all the modifications they desire by clicking on the button $('#seeModifications')
success: function(data){
showModifiedProfile(data);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert("Impossible à faire la MAJ du firstname");
}*/
});
$('#firstname-modify').val('');
return false;
});
$('#addbtnProfile').click(function(){ $('#addbtnProfile').click(function(){
let firstname = $('#firstname-input').val(); let firstname = $('#firstname-input').val();
let age = $('#age-input').val(); let age = $('#age-input').val();
...@@ -90,7 +117,7 @@ $(document).ready(function() { ...@@ -90,7 +117,7 @@ $(document).ready(function() {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "http://localhost:8080/api/profiles", url: "http://localhost:8080/api/profiles",
data: JSON.stringify({ "firstname": firstname, "age" : age, "gender": gender, "pet": pet, "contact": contact}), data: JSON.stringify({"firstname": firstname, "age" : age, "gender": gender, "pet": pet, "contact": contact}),
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
dataType: "json", dataType: "json",
success: function(data){ success: function(data){
...@@ -133,6 +160,14 @@ $(document).ready(function() { ...@@ -133,6 +160,14 @@ $(document).ready(function() {
$listeLovers.append(`<li id="lover-${lover.id}" class="list-group-item">${lover.partnerGender} - who likes ${lover.partnerPet} <button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" >X</button></li>`); $listeLovers.append(`<li id="lover-${lover.id}" class="list-group-item">${lover.partnerGender} - who likes ${lover.partnerPet} <button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" >X</button></li>`);
} }
/* Ajoute un élément li dans la liste de lovers*/
function showModifiedProfile(profile) {
liToAppend4 = `<li id="${profile.id}" class="list-group-item">You are: ${profile.firstname} - age: ${profile.age}`;
profile.lovers.forEach( lover => liToAppend4+= ` - interested in: ${lover.partnerGender} - who likes ${lover.partnerPet}`);
liToAppend4+= `</li>`;
$listModifiedProfile.append(liToAppend4);
}
/* Ajoute un élément li dans le select des lovers*/ /* Ajoute un élément li dans le select des lovers*/
function appendToSelects(lover) { function appendToSelects(lover) {
$selectLovers.append(`<option value="${lover.id}">${lover.partnerGender} - who likes ${lover.partnerPet}</option>`); $selectLovers.append(`<option value="${lover.id}">${lover.partnerGender} - who likes ${lover.partnerPet}</option>`);
...@@ -199,4 +234,18 @@ $(document).ready(function() { ...@@ -199,4 +234,18 @@ $(document).ready(function() {
} }
}); });
}; };
/* Ajout un lover à une profile existante*/
function modifyLoverToProfile(idProfile) {
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile+"/updateLovers",
data: JSON.stringify({"idLover" : idLover}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
}
});
};
}); });
\ No newline at end of file
...@@ -68,6 +68,8 @@ ...@@ -68,6 +68,8 @@
<p>See your new profile now that you have made all your modifications: </p> <p>See your new profile now that you have made all your modifications: </p>
<p><input type="button" id="seeModifications" name="addbtn" value="Modified" class="btn btn-primary btn-sm"></p> <p><input type="button" id="seeModifications" name="addbtn" value="Modified" class="btn btn-primary btn-sm"></p>
<ul class="list-group" id="showModifiedProfile">
</ul>
</div> </div>
</p> </p>
<p> <p>
......
/*
let firstname = $('#firstname-modify').val();
let age = $('#age-modify').val();
let gender = $('#gender-modify').val();
let pet = $('#pet-modify').val();
let contact= $('#contact-modify').val();
let idLover = $selectLovers2.val();
if(age !== null){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updateAge",
data: JSON.stringify({ "updateAge" : age}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
if(firstname !== ''){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updateFirstname",
data: JSON.stringify({ "updateFirstname" : firstname}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
if(gender !== null){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updateGender",
data: JSON.stringify({ "updateGender" : gender}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
if(pet !== null){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updatePet",
data: JSON.stringify({ "updatePet" : pet}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
if(contact !== null){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updateContact",
data: JSON.stringify({ "updateContact" : contact}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
if(idLover !== null){
$.ajax({
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-','')+"/updateLovers",
data: JSON.stringify({ "updateLovers" : idLover}),
contentType: "application/json; charset=utf-8",
dataType: "json",
}); }
$('#firstname-modify').val('');
$('#age-modify').val('');
$('#gender-modify').val('');
$('#pet-modify').val('');
$('#contact-modify').val('');
$.ajax({
type: "GET",
url: "http://localhost:8080/api/profiles"+idProfile.replace('profile-',''),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
myNewProfile(data);
},
});
return false;
*/
<p>Here is the profile you want to change : </p>
<p id="ProfileToModify"></p>
<p>Modify your profile info : </p>
<p>Firstname : <input type="text" name="firstname" id="firstname-modify"><input type="button" id="modifyFirstname" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>Age : <input type="number" name="age" id="age-modify"><input type="button" id="modifyAge" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>Gender (Male/Female/Other): <input type="text" name="gender" id="gender-modify"><input type="button" id="modifyGender" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>For a pet, what do you prefer (cats/dogs/other) ? : <input type="text" name="pet" id="pet-modify"><input type="button" id="modifyPet" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>Contact information for potential lovers : <input type="text" name="contact" id="contact-modify"><input type="button" id="modifyContact" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>Want to choose a new love interest ?: </p>
<p><select id="selectLovers2"></select><input type="button" id="modifyLover" name="addbtn" value="Modify" class="btn btn-primary btn-sm"></p>
<p>See your new profile now that you have made all your modifications: </p>
<p><input type="button" id="seeModifications" name="addbtn" value="Modified" class="btn btn-primary btn-sm"></p>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment