From 7b5c9ddca965208bc847c0097342ef3601a5e1a3 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Wed, 16 Feb 2022 12:30:14 +0100 Subject: [PATCH] Added request exchange functionality. --- .../nl/andrewl/coyotecredit/ctl/HomePage.java | 2 +- .../ctl/RequestExchangeController.java | 35 +++++++++++++++++ .../ctl/dto/RequestExchangePayload.java | 7 ++++ .../dao/ExchangeRequestRepository.java | 9 +++++ .../coyotecredit/model/ExchangeRequest.java | 38 +++++++++++++++++++ .../templates/exchange/exchanges.html | 2 +- .../templates/exchange/removeAccount.html | 2 +- .../templates/exchange/request_exchange.html | 36 ++++++++++++++++++ src/main/resources/templates/home.html | 10 +++++ 9 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 src/main/java/nl/andrewl/coyotecredit/ctl/RequestExchangeController.java create mode 100644 src/main/java/nl/andrewl/coyotecredit/ctl/dto/RequestExchangePayload.java create mode 100644 src/main/java/nl/andrewl/coyotecredit/dao/ExchangeRequestRepository.java create mode 100644 src/main/java/nl/andrewl/coyotecredit/model/ExchangeRequest.java create mode 100644 src/main/resources/templates/exchange/request_exchange.html diff --git a/src/main/java/nl/andrewl/coyotecredit/ctl/HomePage.java b/src/main/java/nl/andrewl/coyotecredit/ctl/HomePage.java index b7d7b75..fb899cb 100644 --- a/src/main/java/nl/andrewl/coyotecredit/ctl/HomePage.java +++ b/src/main/java/nl/andrewl/coyotecredit/ctl/HomePage.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller -@RequestMapping(path = "/") +@RequestMapping(path = {"/", "/home"}) @RequiredArgsConstructor public class HomePage { private final AccountService accountService; diff --git a/src/main/java/nl/andrewl/coyotecredit/ctl/RequestExchangeController.java b/src/main/java/nl/andrewl/coyotecredit/ctl/RequestExchangeController.java new file mode 100644 index 0000000..70f08da --- /dev/null +++ b/src/main/java/nl/andrewl/coyotecredit/ctl/RequestExchangeController.java @@ -0,0 +1,35 @@ +package nl.andrewl.coyotecredit.ctl; + +import lombok.RequiredArgsConstructor; +import nl.andrewl.coyotecredit.ctl.dto.RequestExchangePayload; +import nl.andrewl.coyotecredit.dao.ExchangeRequestRepository; +import nl.andrewl.coyotecredit.model.ExchangeRequest; +import nl.andrewl.coyotecredit.model.User; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping(path = "/requestExchange") +@RequiredArgsConstructor +public class RequestExchangeController { + private final ExchangeRequestRepository exchangeRequestRepository; + + @GetMapping + public String get() { + return "exchange/request_exchange"; + } + + @PostMapping + @Transactional + public String post(@AuthenticationPrincipal User user, @ModelAttribute RequestExchangePayload payload) { + exchangeRequestRepository.save(new ExchangeRequest( + user, payload.estimatedAccountCount(), payload.organization(), payload.reason() + )); + return "redirect:/"; + } +} diff --git a/src/main/java/nl/andrewl/coyotecredit/ctl/dto/RequestExchangePayload.java b/src/main/java/nl/andrewl/coyotecredit/ctl/dto/RequestExchangePayload.java new file mode 100644 index 0000000..fb3a725 --- /dev/null +++ b/src/main/java/nl/andrewl/coyotecredit/ctl/dto/RequestExchangePayload.java @@ -0,0 +1,7 @@ +package nl.andrewl.coyotecredit.ctl.dto; + +public record RequestExchangePayload ( + int estimatedAccountCount, + String organization, + String reason +) {} diff --git a/src/main/java/nl/andrewl/coyotecredit/dao/ExchangeRequestRepository.java b/src/main/java/nl/andrewl/coyotecredit/dao/ExchangeRequestRepository.java new file mode 100644 index 0000000..0652423 --- /dev/null +++ b/src/main/java/nl/andrewl/coyotecredit/dao/ExchangeRequestRepository.java @@ -0,0 +1,9 @@ +package nl.andrewl.coyotecredit.dao; + +import nl.andrewl.coyotecredit.model.ExchangeRequest; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ExchangeRequestRepository extends JpaRepository { +} diff --git a/src/main/java/nl/andrewl/coyotecredit/model/ExchangeRequest.java b/src/main/java/nl/andrewl/coyotecredit/model/ExchangeRequest.java new file mode 100644 index 0000000..367e827 --- /dev/null +++ b/src/main/java/nl/andrewl/coyotecredit/model/ExchangeRequest.java @@ -0,0 +1,38 @@ +package nl.andrewl.coyotecredit.model; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +/** + * Represents a user's request to create a new exchange. + */ +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class ExchangeRequest { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(optional = false, fetch = FetchType.LAZY) + private User user; + + @Column(nullable = false) + private int estimatedAccountCount; + + @Column + private String organization; + + @Column(nullable = false) + private String reason; + + public ExchangeRequest(User user, int estimatedAccountCount, String organization, String reason) { + this.user = user; + this.estimatedAccountCount = estimatedAccountCount; + this.organization = organization; + this.reason = reason; + } +} diff --git a/src/main/resources/templates/exchange/exchanges.html b/src/main/resources/templates/exchange/exchanges.html index f628b73..fa7031e 100644 --- a/src/main/resources/templates/exchange/exchanges.html +++ b/src/main/resources/templates/exchange/exchanges.html @@ -15,7 +15,7 @@
- Est. Account Balance: + My Account Balance:   diff --git a/src/main/resources/templates/exchange/removeAccount.html b/src/main/resources/templates/exchange/removeAccount.html index bc2bbd8..f23b8d4 100644 --- a/src/main/resources/templates/exchange/removeAccount.html +++ b/src/main/resources/templates/exchange/removeAccount.html @@ -5,7 +5,7 @@ th:replace="~{layout/basic_page :: layout (title='Remove Account', content=~{::#content})}" >
-

Remove Account

+

Remove Account

Are you sure you want to remove this account?

diff --git a/src/main/resources/templates/exchange/request_exchange.html b/src/main/resources/templates/exchange/request_exchange.html new file mode 100644 index 0000000..afcab0b --- /dev/null +++ b/src/main/resources/templates/exchange/request_exchange.html @@ -0,0 +1,36 @@ + + +
+
+
+

Request a New Exchange

+

+ Fill in the requested information below to submit your request + for a new exchange. +

+ +
+
+ + +
+
+ + The name of the organization that will use this exchange, if any. + +
+
+ + Give some motivation for why you'd like to request an exchange. + +
+ + +
+
+
+
diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 165a6e1..01fe93f 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -17,11 +17,21 @@
+

Getting Started

You can visit the Exchanges page to view a list of exchanges that you're participating in. Within an exchange, you may buy and sell tradeable assets, and transfer funds to other accounts.

+

+ If you're looking to open your own exchange for your friends, colleagues, or + students to participate in, you can submit a + request for a new exchange. + + Note that exchange requests are processed manually, on a case-by-case basis, and + are subject to the discretion of site administrators. + +

\ No newline at end of file