Skip to content

Commit

Permalink
feat: Propose via form and view proposal, closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhumberstone committed Sep 9, 2024
1 parent c499fd6 commit d713e05
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ Mon Sep 02 20:55:29 BST 2024
There was an unexpected error (type=Method Not Allowed, status=405).
Method 'POST' is not supported.
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' is not supported

Mon 9 Sep
Need to fix the list display so each list item isn't the entire list of topics, and is instead one topic of all of them
Need to add proper CI/CD automated testing
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/main/java/com/nickhumberstone/xpvoting/ProposalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class ProposalController {

private ProposalService proposalservice;

public ProposalController(ProposalService proposalservice) {
this.proposalservice = proposalservice;
}

@GetMapping("/")
public String home(Model model) {
model.addAttribute("proposals", new Proposals());
model.addAttribute("proposalslist", proposalservice.proposals());
return "index";
}

@PostMapping("/")
public String submitProposal(@ModelAttribute Proposals proposal, Model model) {
String proposal2 = proposal.getProposal();
proposalservice.addProposal(proposal2);
return "redirect:/";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
package com.nickhumberstone.xpvoting;

import java.util.List;

import org.springframework.stereotype.Service;

import java.util.ArrayList;

import java.util.Collections;

@Service
public class ProposalService {
List<String> proposals = new ArrayList<>();

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/nickhumberstone/xpvoting/Proposals.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public String getProposal() {
return proposal;
}

}
public void setProposal(String proposal) {
this.proposal = proposal;
}

}
16 changes: 13 additions & 3 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@

<body>
<h1>XP Voting</h1>
<h2>Proposed topic titles</h2>


<form action="#" th:action="@{/}" th:object="${proposals}" method="post">
<label>Proposal: <input type="text" th:field="*{proposal}" /></label>
<label>Proposal: <input type="text" th:field="*{proposal}" /></label>
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</form>

<h2>Proposed topic titles</h2>
<ul>
<li th:if="${proposalslist.empty}">No topics yet</li>
<li th:each="proposal : ${proposalslist}" th:text="${proposalslist}">
</li>



<!-- Space for list of topics -->
</ul>

</body>

Expand Down

0 comments on commit d713e05

Please sign in to comment.