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 {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/updateFirstname")
public Response updateFirstname(@PathParam("id") Long id, Profile p) {
String firstname = p.getFirstname();
public Response updateFirstname(@PathParam("id") Long id, String newFirstname) {
String newFirstname2 = newFirstname.replace('"',' ');
Optional<Profile> optional = profileRepository.findById(id);
if (optional.isPresent()) {
Profile pBDD = optional.get();
pBDD.setFirstname(firstname);
pBDD.setFirstname(newFirstname2.strip());
profileRepository.save(pBDD);
return Response.ok(pBDD).build();
} else {
......
......@@ -3,10 +3,14 @@ $(document).ready(function() {
let $listeProfilesDelete = $("#listProfilesDelete");
let $listeProfilesSelect = $("#listProfilesSelect");
let $listeProfilesSelect2 = $("#listProfilesSelect2");
let $listeMatches= $("#listMatches");
let $listeMyProfile= $("#myProfile");
let $listeMatches = $("#listMatches");
//let $listeMyProfile= $("#myProfile");
let $selectLovers = $("#selectLovers");
let $selectLovers2 = $("#selectLovers2");
let $modifyFirstnameText = $("#firstname-modify");
let $modifyFirstnameButton = $("#modifyFirstname");
let $listModifiedProfile = $("#showModifiedProfile");
let $buttonSeeModifications = $("#seeModifications");
$.get("http://localhost:8080/api/profiles",function(resp){
resp.forEach( p => {
......@@ -43,21 +47,18 @@ $(document).ready(function() {
});
});
$listeProfilesSelect2.on("click", "li button", function() {
let idProfile = $(this).parent().attr('id');
$('#modifyLover').click(function(){
let idProfile = $listeProfilesSelect2.val();
$.ajax({
type: "GET",
url: "http://localhost:8080/api/profiles/"+idProfile.replace('profile-',''),
type: "PATCH",
url: "http://localhost:8080/api/profiles/"+idProfile+"/updateLovers",
contentType: "application/json; charset=utf-8",
dataType: "json",
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() {
......@@ -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(){
let firstname = $('#firstname-input').val();
let age = $('#age-input').val();
......@@ -90,7 +117,7 @@ $(document).ready(function() {
$.ajax({
type: "POST",
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",
dataType: "json",
success: function(data){
......@@ -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>`);
}
/* 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*/
function appendToSelects(lover) {
$selectLovers.append(`<option value="${lover.id}">${lover.partnerGender} - who likes ${lover.partnerPet}</option>`);
......@@ -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 @@
<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>
<ul class="list-group" id="showModifiedProfile">
</ul>
</div>
</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