-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin POCHAT
authored and
Benjamin POCHAT
committed
Jan 5, 2021
1 parent
22c5fe3
commit 232fdde
Showing
21 changed files
with
294 additions
and
28 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
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
10 changes: 4 additions & 6 deletions
10
core/src/main/java/com/localeat/core/commons/EmailService.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
2 changes: 1 addition & 1 deletion
2
core/src/main/java/com/localeat/core/commons/GenericBuilder.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
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
10 changes: 9 additions & 1 deletion
10
core/src/main/java/com/localeat/core/domains/actor/BreederRepository.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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
package com.localeat.core.domains.actor; | ||
|
||
public interface BreederRepository { | ||
import com.localeat.core.domains.farm.Farm; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface BreederRepository extends CrudRepository<Breeder, Long> { | ||
@Query("SELECT b FROM Breeder b " + | ||
"WHERE b.farm = :farm") | ||
Iterable<Breeder> findBreedersByFarm(@Param("farm") Farm farm); | ||
} |
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
58 changes: 58 additions & 0 deletions
58
core/src/main/java/com/localeat/core/domains/order/OrderNotificationService.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 |
---|---|---|
@@ -1,4 +1,62 @@ | ||
package com.localeat.core.domains.order; | ||
|
||
import com.localeat.core.commons.EmailService; | ||
import com.localeat.core.domains.actor.Breeder; | ||
import com.localeat.core.domains.actor.BreederRepository; | ||
import com.localeat.core.domains.product.Batch; | ||
import com.localeat.core.domains.product.BatchRepository; | ||
import com.localeat.core.domains.slaughter.Slaughter; | ||
import com.localeat.core.domains.slaughter.SlaughterRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
@Service | ||
public class OrderNotificationService { | ||
|
||
@Autowired | ||
private BatchRepository batchRepository; | ||
|
||
@Autowired | ||
private SlaughterRepository slaughterRepository; | ||
|
||
@Autowired | ||
private BreederRepository breederRepository; | ||
|
||
@Autowired | ||
private OrderItemRepository orderItemRepository; | ||
|
||
@Autowired | ||
private EmailService emailService; | ||
|
||
public void notifyByMail(Order order) { | ||
Slaughter slaughter = slaughterRepository.findByDelivery(order.getDelivery()); | ||
Iterable<Breeder> breeders = breederRepository.findBreedersByFarm(slaughter.getAnimal().getFinalFarm()); | ||
String recipient = StreamSupport.stream(breeders.spliterator(), false).map(Breeder::getEmail).collect(Collectors.joining(",")); | ||
String subject = "nouvelle commande !"; | ||
String body = String.format( | ||
"<div>La commande n° %s a été enregistrée</div>" | ||
+ "<div><ul>" | ||
+ "<li>Montant de la commande : %s €TTC</li>" | ||
+ "<li>Quantité commandée : %s kg</li>" | ||
+ "</ul></div>", | ||
order.getId(), | ||
order.getOrderedItems().stream() | ||
.mapToDouble(item -> { | ||
Batch batch = batchRepository.findById(item.getBatch().getId()).orElseThrow(); | ||
return item.getQuantity() * batch.getProduct().getUnitPrice() * batch.getProduct().getNetWeight(); | ||
}) | ||
.sum(), | ||
order.getOrderedItems().stream().mapToDouble(item -> { | ||
Batch batch = batchRepository.findById(item.getBatch().getId()).orElseThrow(); | ||
return item.getQuantity() * batch.getProduct().getNetWeight(); | ||
}).sum()); | ||
sendMail(recipient, subject, body); | ||
} | ||
|
||
void sendMail(String recipient, String subject, String body) { | ||
emailService.sendMail(recipient, subject, body); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
core/src/main/java/com/localeat/core/domains/security/AccountRepository.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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package com.localeat.core.domains.security; | ||
|
||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface AccountRepository extends CrudRepository<Account, Long> { | ||
Account getAccountByUsername(String username); | ||
|
||
@Query("SELECT a FROM Account a " + | ||
"INNER JOIN a.actor act " + | ||
"WHERE act.email = :email") | ||
Iterable<Account> findByEmail(@Param("email") String email); | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/com/localeat/core/domains/security/PasswordRenewalController.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 |
---|---|---|
@@ -1,4 +1,24 @@ | ||
package com.localeat.core.domains.security; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.stream.StreamSupport; | ||
|
||
@RestController | ||
public class PasswordRenewalController { | ||
|
||
@Autowired | ||
AccountRepository accountRepository; | ||
|
||
@PostMapping(path = "/passwordRenewal/{email}") | ||
public String renewPassword(@PathVariable String email){ | ||
Account account = StreamSupport.stream(accountRepository.findByEmail(email).spliterator(), false).findFirst().orElseThrow(() -> new ResponseStatusException(HttpStatus.FORBIDDEN, String.format("No account for email address %s.", email))); | ||
// TODO : générer un token et envoyer un mail | ||
return String.format("An email has been sent to %s.", email); | ||
} | ||
} |
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
4 changes: 0 additions & 4 deletions
4
core/src/test/java/com/localeat/core/commons/TestEmailController.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.