Changeset 1413ee2
- Timestamp:
- 01/03/24 00:00:07 (11 months ago)
- Branches:
- master
- Children:
- 53765dd
- Parents:
- 77205be
- Location:
- src/main
- Files:
-
- 4 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java
r77205be r1413ee2 3 3 import edu.gjoko.schedlr.entity.Stakeholder; 4 4 import edu.gjoko.schedlr.services.StakeholderService; 5 import org.springframework.beans.factory.annotation.Autowired;6 import org.springframework.http.MediaType;7 5 import org.springframework.stereotype.Controller; 8 6 import org.springframework.ui.Model; -
src/main/java/edu/gjoko/schedlr/controllers/rest/BusinessApi.java
r77205be r1413ee2 27 27 28 28 @PatchMapping 29 public void updateBusinesses(@RequestBody List<Business> businessList) { 30 businessService.updateBusinesses(businessList); 29 public void updateBusinesses(@RequestBody List<Business> businessList, HttpServletRequest request) { 30 Long businessOwnerId = (long) request.getSession(true).getAttribute("stakeholderId"); 31 businessService.updateBusinesses(businessList, businessOwnerId); 31 32 } 32 33 -
src/main/java/edu/gjoko/schedlr/controllers/rest/CustomerApi.java
r77205be r1413ee2 24 24 25 25 @PatchMapping 26 public void updateCustomer(@RequestBody Stakeholder stakeholder) { 27 stakeholderService.saveOrUpdateStakeholder(stakeholder); 26 public void updateCustomer(@RequestBody Stakeholder stakeholder, HttpServletRequest request) { 27 Long customerId = (long) request.getSession(true).getAttribute("stakeholderId"); 28 stakeholderService.saveOrUpdateStakeholder(stakeholder, customerId); 28 29 } 29 30 } -
src/main/java/edu/gjoko/schedlr/entity/Service.java
r77205be r1413ee2 54 54 private List<Appointment> appointments; 55 55 56 @Column(name = "service_status") 57 @Enumerated(EnumType.STRING) 58 private ServiceStatus serviceStatus; 59 56 60 @Column(name = "created") 57 61 @CreatedDate -
src/main/java/edu/gjoko/schedlr/repositories/BusinessRepository.java
r77205be r1413ee2 16 16 Business findBusinessByOwner(Stakeholder owner); 17 17 18 List<Business> findBusinessesByBusinessTypeAndBusinessStatus(BusinessType businessType, BusinessStatus businessStatus); 19 18 Business findBusinessesByOwner_Id(Long ownerId); 20 19 List<Business> findBusinessesByBusinessStatusAndBusinessType_Id(BusinessStatus businessStatus, Long id); 21 20 } -
src/main/java/edu/gjoko/schedlr/repositories/ServiceRepository.java
r77205be r1413ee2 1 1 package edu.gjoko.schedlr.repositories; 2 2 3 import edu.gjoko.schedlr.entity.Business;4 3 import edu.gjoko.schedlr.entity.Service; 5 4 import org.springframework.data.jpa.repository.JpaRepository; 5 import org.springframework.data.jpa.repository.Modifying; 6 import org.springframework.data.jpa.repository.Query; 6 7 import org.springframework.stereotype.Repository; 8 9 import java.util.List; 7 10 8 11 @Repository -
src/main/java/edu/gjoko/schedlr/repositories/ServiceTypeRepository.java
r77205be r1413ee2 4 4 import edu.gjoko.schedlr.entity.ServiceType; 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.Modifying; 7 import org.springframework.data.jpa.repository.Query; 6 8 import org.springframework.stereotype.Repository; 7 9 -
src/main/java/edu/gjoko/schedlr/services/BusinessService.java
r77205be r1413ee2 1 1 package edu.gjoko.schedlr.services; 2 2 3 import edu.gjoko.schedlr.entity.*; 4 import edu.gjoko.schedlr.repositories.*; 3 import edu.gjoko.schedlr.entity.Business; 4 import edu.gjoko.schedlr.entity.Stakeholder; 5 import edu.gjoko.schedlr.entity.StakeholderType; 6 import edu.gjoko.schedlr.repositories.BusinessRepository; 5 7 import lombok.AllArgsConstructor; 6 8 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 9 import org.springframework.stereotype.Service; 8 import org.springframework.util.CollectionUtils;9 10 10 11 import java.util.List; … … 18 19 19 20 private final BusinessRepository businessRepository; 20 private final ServiceTypeRepository serviceTypeRepository; 21 private final ServiceRepository serviceRepository; 21 private final ServicesService servicesService; 22 22 private final StakeholderService stakeholderService; 23 24 private final StakeholderRepository stakeholderRepository;25 23 private BCryptPasswordEncoder bCryptPasswordEncoder; 26 24 27 25 public void saveBusiness(Business business) { 28 s aveNewServiceTypes(business);26 servicesService.saveNewServiceTypes(business); 29 27 business.getOwner().setStakeholderType(StakeholderType.BUSINESS_OWNER); 30 28 business.getOwner().setPassword(bCryptPasswordEncoder.encode(business.getOwner().getPassword())); … … 33 31 } 34 32 35 public void saveNewServiceTypes(Business business) {36 business.getServices()37 .stream()38 .forEach(service -> {39 if (service.getServiceType().getId() == null) {40 ServiceType serviceType = service.getServiceType();41 serviceType.setBusinessType(business.getBusinessType());42 service.setServiceType(serviceTypeRepository.save(serviceType));43 }44 });45 }46 47 33 public List<Business> findAll() { 48 34 return businessRepository.findAll(); 49 35 } 50 36 51 public void updateBusinesses(List<Business> businessList ) {37 public void updateBusinesses(List<Business> businessList, Long businessOwnerId) { 52 38 businessList 53 39 .stream() 54 40 .forEach(business -> { 55 stakeholderService.saveOrUpdateStakeholder(business.getOwner()); 56 saveOrUpdateServices(business.getServices()); 57 saveOrUpdateBusiness(business); 41 stakeholderService.saveOrUpdateStakeholder(business.getOwner(), businessOwnerId); 42 }); 43 } 44 45 public void updateBusinessStatuses(List<Business> businessList) { 46 businessList 47 .stream() 48 .forEach(business -> { 49 Business business1 = businessRepository.findById(business.getId()).get(); 50 business1.setBusinessStatus(business.getBusinessStatus()); 51 businessRepository.save(business1); 58 52 }); 59 53 } … … 68 62 return businessRepository.findBusinessesByBusinessStatusAndBusinessType_Id(ACTIVE, businessTypeId); 69 63 } 70 71 72 73 private void saveOrUpdateBusiness(Business business) {74 if (business.getId() != null) {75 var foundBusinessEntity = businessRepository.findById(business.getId());76 business.setCreated(foundBusinessEntity.get().getCreated());77 }78 businessRepository.save(business);79 }80 81 private void saveOrUpdateServices(List<edu.gjoko.schedlr.entity.Service> serviceList) {82 if (!CollectionUtils.isEmpty(serviceList)) {83 serviceList.forEach( service -> {84 if (service.getId() != null) {85 var found = serviceRepository.findById(service.getId());86 service.setCreated(found.get().getCreated());87 }88 });89 serviceRepository.saveAll(serviceList);90 }91 }92 64 } -
src/main/java/edu/gjoko/schedlr/services/StakeholderService.java
r77205be r1413ee2 4 4 import edu.gjoko.schedlr.entity.StakeholderType; 5 5 import edu.gjoko.schedlr.repositories.StakeholderRepository; 6 import lombok.RequiredArgsConstructor; 6 7 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 8 import org.springframework.stereotype.Service; 8 9 9 import java.util.Optional;10 11 10 @Service 11 @RequiredArgsConstructor 12 12 public class StakeholderService { 13 13 14 private StakeholderRepository stakeholderRepository;15 private BCryptPasswordEncoder bCryptPasswordEncoder;14 private final StakeholderRepository stakeholderRepository; 15 private final BCryptPasswordEncoder bCryptPasswordEncoder; 16 16 17 public StakeholderService(StakeholderRepository stakeholderRepository, 18 BCryptPasswordEncoder bCryptPasswordEncoder) { 19 this.stakeholderRepository = stakeholderRepository; 20 this.bCryptPasswordEncoder = bCryptPasswordEncoder; 21 } 22 23 public Stakeholder saveStakeholder(Stakeholder stakeholder) { 17 public void saveStakeholder(Stakeholder stakeholder) { 24 18 stakeholder.setPassword(bCryptPasswordEncoder.encode(stakeholder.getPassword())); 25 19 stakeholder.setStakeholderType(StakeholderType.CUSTOMER); 26 returnstakeholderRepository.save(stakeholder);20 stakeholderRepository.save(stakeholder); 27 21 } 28 22 … … 31 25 } 32 26 33 public void saveOrUpdateStakeholder(Stakeholder stakeholder) { 34 if (stakeholder.getId() != null) { 35 var found = stakeholderRepository.findById(stakeholder.getId()).get(); 36 found.setFirstName(stakeholder.getFirstName()); 37 found.setLastName(stakeholder.getLastName()); 38 found.setPhoneNumber(stakeholder.getPhoneNumber()); 39 found.setEmail(stakeholder.getEmail()); 40 found.setUsername(stakeholder.getUsername()); 41 stakeholderRepository.save(found); 42 } 27 public void saveOrUpdateStakeholder(Stakeholder stakeholder, Long businessOwnerId) { 28 var found = stakeholderRepository.findById(businessOwnerId).get(); 29 found.setFirstName(stakeholder.getFirstName()); 30 found.setLastName(stakeholder.getLastName()); 31 found.setPhoneNumber(stakeholder.getPhoneNumber()); 32 found.setEmail(stakeholder.getEmail()); 33 found.setUsername(stakeholder.getUsername()); 34 stakeholderRepository.save(found); 43 35 } 44 36 } -
src/main/resources/data.sql
r77205be r1413ee2 19 19 values (nextval('hibernate_sequence'), current_timestamp, '075658123', 'admin@schedlr.com', 'admin', 'admin', current_timestamp, '$2a$10$DJyjt.Vj/U8MEuYX1PXL9ukQSMwXHVdhre3POlTqpYzNxHB5gu/MW','ADMIN', 'admin'), 20 20 (nextval('hibernate_sequence'), current_timestamp, '071658125', 'user1@schedlr.com', 'gjoko', 'kostadinov', current_timestamp, '$2a$10$Zc28AcCpAgxB.e67UMF/2.FgchjH9QWB7z8nP0TdkrFneV4IHPXji','CUSTOMER', 'user'), 21 (11111, current_timestamp, '078658523', 'c@c.com', 'Kliment', 'Nedelkovski', current_timestamp, '$2a$10$OratLSMKNsqd7Re.Md3I4.jrRHtTQNaLz/wUKo.I98..GufnD48uG','CUSTOMER', ' kliment123'),22 (10000, current_timestamp, '071218123', 'q@c.com', 'Stefan', 'Petrovski', current_timestamp, '$2a$10$x10O8eLp1r1wHwxDGvyo5.TBL216p8h797JJjQYEfFTbj/1bnCMki','BUSINESS_OWNER', ' stefan123');21 (11111, current_timestamp, '078658523', 'c@c.com', 'Kliment', 'Nedelkovski', current_timestamp, '$2a$10$OratLSMKNsqd7Re.Md3I4.jrRHtTQNaLz/wUKo.I98..GufnD48uG','CUSTOMER', 'c'), 22 (10000, current_timestamp, '071218123', 'q@c.com', 'Stefan', 'Petrovski', current_timestamp, '$2a$10$x10O8eLp1r1wHwxDGvyo5.TBL216p8h797JJjQYEfFTbj/1bnCMki','BUSINESS_OWNER', 'q'); 23 23 24 24 insert into business (id, business_status, company_name, created, modified, business_type_id, owner_id) 25 25 values (10001, 'ACTIVE', 'krojach stefan', current_timestamp, current_timestamp, 1, 10000); 26 26 27 insert into service (id, created, modified, duration, price, cumulated_rating, reviews_count, business_id, service_type_id)28 values (10002, current_timestamp, current_timestamp, 60, 400, 0, 0, 10001, 6),29 (10003, current_timestamp, current_timestamp, 30, 200, 0, 0, 10001, 7);27 insert into service (id, created, modified, service_status, duration, price, cumulated_rating, reviews_count, business_id, service_type_id) 28 values (10002, current_timestamp, current_timestamp, 'ACTIVE', 60, 400, 0, 0, 10001, 6), 29 (10003, current_timestamp, current_timestamp, 'ACTIVE', 30, 200, 0, 0, 10001, 7); 30 30 31 31 insert into appointment (id, created, modified, start_time, end_time, stakeholder_id, service_id) -
src/main/resources/static/css/customer_admin.css
r77205be r1413ee2 1 1 .rate{ 2 3 2 border-bottom-right-radius: 12px; 4 3 border-bottom-left-radius: 12px; 5 6 4 } 7 5 -
src/main/resources/static/js/admin.js
r77205be r1413ee2 20 20 } 21 21 }); 22 console.log(JSON.stringify(companiesToSave));23 22 24 23 25 24 $.ajax({ 26 url: "http://localhost:8080/api/ business",25 url: "http://localhost:8080/api/admin", 27 26 type:"PATCH", 28 27 data: JSON.stringify(companiesToSave), -
src/main/resources/static/js/business_admin.js
r77205be r1413ee2 2 2 var business = {}; 3 3 4 getBusinessInfo(business); 4 getBusinessInfo().then(function (data) { 5 business = data; 6 }); 5 7 6 8 getAppointments(); … … 33 35 $("#update_services_button").click(function () { 34 36 businesses = []; 35 console.log("Gjoko");36 37 servicesObj = []; 37 38 $.each($('#predefined_services_admin_panel input:checked').siblings(), function (index, label) { … … 43 44 var price = $($($(label).parent()).siblings()[1]).children()[0].value; 44 45 45 var serviceType = {} 46 var serviceType = {}; 46 47 if (parseInt(id) != -1) { 47 48 service['id'] = parseInt(id); … … 56 57 servicesObj.push(service); 57 58 }); 58 business['services'] = servicesObj; 59 60 businesses.push(business); 61 console.log(JSON.stringify(businesses)); 62 63 $.ajax({ 64 url: "http://localhost:8080/api/business", 65 type:"PATCH", 66 data: JSON.stringify(businesses), 67 contentType:"application/json; charset=utf-8", 68 dataType: 'text', 69 success: function(succ){ 70 alert( "Updates applied successfully" ); 71 }, 72 error: function(err) { 73 alert(err); 74 } 75 }); 59 60 var servicesForDelete=[]; 61 $.each($('#predefined_services_admin_panel input:not(:checked)').siblings(), function (index, label) { 62 let id = $(label).prop('for'); 63 let foundService = business['services'].find(obj => obj.id === parseInt(id)); 64 if (foundService !== undefined && foundService['serviceStatus'] === 'ACTIVE') { 65 let service1 = {}; 66 service1['id'] = id; 67 servicesForDelete.push(service1); 68 } 69 }); 70 71 72 updateServices(servicesObj).then(function (response) { 73 getBusinessInfo().then(function (data) { 74 business = data; 75 }); 76 }); 77 78 if (servicesForDelete.length > 0) { 79 deleteServices(servicesForDelete).then(function (response) { 80 getBusinessInfo().then(function (data) { 81 business = data; 82 }); 83 }); 84 } 85 76 86 event.preventDefault(); 77 87 }); … … 79 89 $("#update_owner_button").click(function() { 80 90 businesses = []; 81 business['owner']['firstName'] = $('#firstName').val(); 82 business['owner']['lastName'] = $('#lastName').val(); 83 business['owner']['email'] = $('#email').val(); 84 business['owner']['phoneNumber'] = $('#phoneNumber').val(); 85 business['owner']['username'] = $('#username').val(); 91 owner={}; 92 owner['firstName'] = $('#firstName').val(); 93 owner['lastName'] = $('#lastName').val(); 94 owner['email'] = $('#email').val(); 95 owner['phoneNumber'] = $('#phoneNumber').val(); 96 owner['username'] = $('#username').val(); 97 98 business['owner'] = owner; 86 99 87 100 businesses.push(business); 88 console.log(JSON.stringify(businesses)); 89 90 $.ajax({ 91 url: "http://localhost:8080/api/business", 92 type:"PATCH", 93 data: JSON.stringify(businesses), 94 contentType:"application/json; charset=utf-8", 95 dataType: 'text', 96 success: function(succ){ 97 alert( "Updates applied successfully" ); 98 }, 99 error: function(err) { 100 alert(err); 101 } 101 102 updateBusinessInfo(businesses).then(function() { 103 getBusinessInfo().then(function (found) { 104 business = found; 105 }); 102 106 }); 103 107 }); 104 108 event.preventDefault(); 105 109 }); 110 111 function updateBusinessInfo(businessList) { 112 return $.ajax({ 113 url: "http://localhost:8080/api/business", 114 type:"PATCH", 115 data: JSON.stringify(businessList), 116 contentType:"application/json; charset=utf-8", 117 dataType: 'text', 118 success: function(succ){ 119 alert( "Updates applied successfully" ); 120 }, 121 error: function(err) { 122 alert(err); 123 } 124 }); 125 } 126 127 function updateServices(serviceList) { 128 return $.ajax({ 129 url: "http://localhost:8080/api/service", 130 type:"PATCH", 131 data: JSON.stringify(serviceList), 132 contentType:"application/json; charset=utf-8", 133 dataType: 'text', 134 success: function(succ){ 135 alert( "Updates applied successfully" ); 136 }, 137 error: function(err) { 138 alert(err); 139 } 140 }); 141 } 142 143 function deleteServices(services) { 144 return $.ajax({ 145 url: "http://localhost:8080/api/service/delete", 146 type:"POST", 147 data: JSON.stringify(services), 148 contentType:"application/json; charset=utf-8", 149 dataType: 'text', 150 success: function(succ){ 151 console.log("services deleted successfully"); 152 }, 153 error: function(err) { 154 console.error(err); 155 } 156 }); 157 } 106 158 107 159 function cancelAppointment(appointmentId) { … … 123 175 url: "http://localhost:8080/api/appointment/future/me" 124 176 }).then(function (data) { 125 console.log(data);126 177 var $el = $("#bookings-table-body"); 127 178 $el.empty(); … … 154 205 } 155 206 156 function getBusinessInfo( business) {157 $.ajax({207 function getBusinessInfo() { 208 return $.ajax({ 158 209 url: "http://localhost:8080/api/business/me" 159 }).then(function (data) { 160 business = data; 210 }).then(function (business) { 161 211 var $header = $("#header"); 162 212 163 213 // header 164 $header.text( $header.text() + "" + business["owner"]['firstName'] + " " + business['owner']['lastName']);214 $header.text("Welcome back " + business["owner"]['firstName'] + " " + business['owner']['lastName']); 165 215 166 216 // business info … … 181 231 var $el = $("#predefined_services_admin_panel"); 182 232 $el.empty(); 233 183 234 $.each(business['services'], function (index, obj) { 184 $el.append( 185 235 236 var element = '<div class=\"form-outline mb-4\">' + 186 237 ' <div class="row">' + 187 238 ' <div class="col-md-6">\n' + 188 ' <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' + 239 ' <input class="form-check-input" type="checkbox" '; 240 241 if (obj['serviceStatus'] === 'ACTIVE') { 242 element += 'checked'; 243 } 244 245 element += ' value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' + 189 246 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + obj['serviceType'].name + '</label>\n' + 190 247 ' </div>' + … … 196 253 ' </div>' + 197 254 ' </div>' + 198 '</div>'); 199 }); 200 }); 201 } 255 '</div>'; 256 257 $el.append(element); 258 }); 259 return business; 260 }); 261 } -
src/main/resources/static/js/customer_admin.js
r77205be r1413ee2 16 16 customerForSave['phoneNumber'] = $('#phoneNumber').val(); 17 17 customerForSave['username'] = $('#username').val(); 18 19 console.log(JSON.stringify(customerForSave));20 18 21 19 $.ajax({ … … 55 53 const recipientId = button.getAttribute('data-bs-id'); 56 54 57 console.log(recipientName + ' ' + recipientId);58 // If necessary, you could initiate an Ajax request here59 // and then do the updating in a callback.60 61 55 // Update the modal's content. 62 56 const modalTitle = reviewModal.querySelector('.modal-title'); … … 97 91 url: "http://localhost:8080/api/appointment/future/me" 98 92 }).then(function (data) { 99 console.log(data);100 93 var $el = $("#appointments-table-body"); 101 94 $el.empty(); … … 194 187 url: "http://localhost:8080/api/review/me" 195 188 }).then(function (data) { 196 console.log(data);197 189 var $el = $("#my-reviews"); 198 190 $el.empty(); … … 233 225 $('#reviewModal').modal('toggle'); 234 226 getPastAppointments(); 227 getReviewsForCustomer(); 235 228 }, 236 229 error: function(error) { … … 248 241 }).success(function (data) { 249 242 alert("Appointment successfully canceled.") 250 get Appointments();243 getFutureAppointments(); 251 244 }).error(function (error) { 252 245 alert("Something went wrong."); -
src/main/resources/static/js/homepage.js
r77205be r1413ee2 102 102 // get already stored service from in-memory 103 103 selectedServices = businesses.find(item => item.id == selectedVal)['services']; 104 console.log(selectedServices); 104 105 resetAndAppendServices(selectedServices); 105 106 }); … … 164 165 165 166 $.each(services, function (index, obj) { 166 $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>"); 167 if (obj.serviceStatus === 'ACTIVE') { 168 $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>"); 169 } 167 170 }); 168 171 }
Note:
See TracChangeset
for help on using the changeset viewer.