-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/MERINGIT/AppointmentSche…
…duler into develop
- Loading branch information
Showing
14 changed files
with
528 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/slabiak/appointmentscheduler/model/AdjusterAfterEnd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.slabiak.appointmentscheduler.model; | ||
|
||
class AdjusterAfterEnd implements TimePeriodAdjuster { | ||
|
||
|
||
@Override | ||
public TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod) { | ||
if (breakPeriod.getEnd().isAfter(original.getEnd())) { | ||
original.setEnd(breakPeriod.getEnd()); | ||
} | ||
return original; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/slabiak/appointmentscheduler/model/AdjusterBeforeStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example.slabiak.appointmentscheduler.model; | ||
|
||
|
||
import java.time.LocalDateTime; | ||
|
||
class AdjusterBeforeStart implements TimePeriodAdjuster { | ||
|
||
|
||
@Override | ||
public TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod) { | ||
if (breakPeriod.getStart().isBefore(original.getStart())) { | ||
original.setStart((breakPeriod.getStart())); | ||
} | ||
return original; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/slabiak/appointmentscheduler/model/TimePeriodAdjuster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.slabiak.appointmentscheduler.model; | ||
|
||
public interface TimePeriodAdjuster { | ||
TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/slabiak/appointmentscheduler/service/RetailCustomerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.slabiak.appointmentscheduler.service; | ||
|
||
import com.example.slabiak.appointmentscheduler.entity.user.Role; | ||
import com.example.slabiak.appointmentscheduler.entity.user.customer.RetailCustomer; | ||
import com.example.slabiak.appointmentscheduler.model.UserForm; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface RetailCustomerService { | ||
public void saveNewRetailCustomer(UserForm userForm); | ||
|
||
public void updateRetailCustomerProfile(UserForm updateData); | ||
|
||
public List<RetailCustomer> getAllRetailCustomers(); | ||
|
||
public RetailCustomer getRetailCustomerById(int retailCustomerId); | ||
|
||
public Collection<Role> getRolesForRetailCustomer(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,8 @@ public EmailServiceImpl(JavaMailSender javaMailSender, SpringTemplateEngine temp | |
this.baseUrl = baseUrl; | ||
} | ||
|
||
@Async | ||
//Before Extract Method | ||
/*@Async | ||
@Override | ||
public void sendEmail(String to, String subject, String templateName, Context templateContext, File attachment) { | ||
try { | ||
|
@@ -65,8 +66,42 @@ public void sendEmail(String to, String subject, String templateName, Context te | |
log.error("Error while adding attachment to email, error is {}", e.getLocalizedMessage()); | ||
} | ||
}*/ | ||
|
||
//After Extract Method | ||
@Async | ||
@Override | ||
public void sendEmail(String to, String subject, String templateName, Context templateContext, File attachment) { | ||
try { | ||
MimeMessage message = createMimeMessageWithAttachment(to, subject, templateName, templateContext, attachment); | ||
javaMailSender.send(message); | ||
} catch (MessagingException e) { | ||
log.error("Error while adding attachment to email, error is {}", e.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
private MimeMessage createMimeMessageWithAttachment(String to, String subject, String templateName, Context templateContext, File attachment) throws MessagingException { | ||
MimeMessage message = javaMailSender.createMimeMessage(); | ||
MimeMessageHelper helper = new MimeMessageHelper(message, | ||
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, | ||
StandardCharsets.UTF_8.name()); | ||
|
||
String html = templateEngine.process("email/" + templateName, templateContext); | ||
|
||
helper.setTo(to); | ||
helper.setFrom("[email protected]"); | ||
helper.setSubject(subject); | ||
helper.setText(html, true); | ||
|
||
if (attachment != null) { | ||
helper.addAttachment("invoice", attachment); | ||
} | ||
|
||
return message; | ||
} | ||
|
||
|
||
|
||
@Async | ||
@Override | ||
public void sendAppointmentFinishedNotification(Appointment appointment) { | ||
|
69 changes: 69 additions & 0 deletions
69
...ain/java/com/example/slabiak/appointmentscheduler/service/impl/RetailCustomerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// RetailCustomerService.java | ||
|
||
package com.example.slabiak.appointmentscheduler.service.impl; | ||
|
||
import com.example.slabiak.appointmentscheduler.dao.RoleRepository; | ||
import com.example.slabiak.appointmentscheduler.dao.user.customer.RetailCustomerRepository; | ||
import com.example.slabiak.appointmentscheduler.entity.user.Role; // Add this import | ||
import com.example.slabiak.appointmentscheduler.entity.user.customer.RetailCustomer; | ||
import com.example.slabiak.appointmentscheduler.model.UserForm; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
@Service | ||
public class RetailCustomerService implements com.example.slabiak.appointmentscheduler.service.RetailCustomerService { | ||
|
||
private final RetailCustomerRepository retailCustomerRepository; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
private RoleRepository roleRepository ; | ||
|
||
public RetailCustomerService(RetailCustomerRepository retailCustomerRepository,PasswordEncoder passwordEncoder,RoleRepository roleRepository) { | ||
this.retailCustomerRepository = retailCustomerRepository; | ||
this.passwordEncoder = passwordEncoder; | ||
this.roleRepository = roleRepository; | ||
|
||
} | ||
|
||
@Override | ||
@PreAuthorize("#updateData.id == principal.id or hasRole('ADMIN')") | ||
public void updateRetailCustomerProfile(UserForm updateData) { | ||
RetailCustomer retailCustomer = retailCustomerRepository.getOne(updateData.getId()); | ||
retailCustomer.update(updateData); | ||
retailCustomerRepository.save(retailCustomer); | ||
} | ||
|
||
@Override | ||
public void saveNewRetailCustomer(UserForm userForm) { | ||
RetailCustomer retailCustomer = new RetailCustomer(userForm, passwordEncoder.encode(userForm.getPassword()), getRolesForRetailCustomer()); | ||
retailCustomerRepository.save(retailCustomer); | ||
} | ||
|
||
@Override | ||
public List<RetailCustomer> getAllRetailCustomers() { | ||
return retailCustomerRepository.findAll(); | ||
} | ||
|
||
|
||
@Override | ||
@PreAuthorize("#retailCustomerId == principal.id or hasRole('ADMIN')") | ||
public RetailCustomer getRetailCustomerById(int retailCustomerId) { | ||
return retailCustomerRepository.findById(retailCustomerId) | ||
.orElseThrow(() -> new UsernameNotFoundException("User not found!")); | ||
} | ||
|
||
|
||
public Collection<Role> getRolesForRetailCustomer() { | ||
HashSet<Role> roles = new HashSet(); | ||
roles.add(roleRepository.findByName("ROLE_CUSTOMER_RETAIL")); | ||
roles.add(roleRepository.findByName("ROLE_CUSTOMER")); | ||
return roles; | ||
} | ||
|
||
} |
Oops, something went wrong.