package org.xcolab.view.pages.proposals.view.action;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.xcolab.client.members.pojo.Member;
import org.xcolab.client.proposals.ProposalClient;
import org.xcolab.client.proposals.pojo.Proposal;
import org.xcolab.view.pages.proposals.exceptions.ProposalsAuthorizationException;
import org.xcolab.view.pages.proposals.utils.context.ProposalContext;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/contests/{contestYear}/{contestUrlName}")
public class SubscribeProposalActionController {

    @PostMapping("/c/{proposalUrlString}/{proposalId}/subscribeProposal")
    public void handleAction(HttpServletRequest request, HttpServletResponse response, Model model,
            ProposalContext proposalContext, Member currentMember)
            throws ProposalsAuthorizationException, IOException {

        if (proposalContext.getPermissions().getCanSubscribeProposal()) {
            final Proposal proposal = proposalContext.getProposal();
            long proposalId = proposal.getProposalId();
            long memberId = currentMember.getId_();
            final ProposalClient proposalClient = proposalContext.getClients().getProposalClient();
            if (proposalClient.isMemberSubscribedToProposal(proposalId, memberId)) {
                proposalClient.unsubscribeMemberFromProposal(proposalId, memberId);
            } else {
                proposalClient.subscribeMemberToProposal(proposalId, memberId);
            }
            response.sendRedirect(proposal.getProposalLinkUrl(proposalContext.getContest()));
        } else {
            throw new ProposalsAuthorizationException("User isn't allowed to subscribe proposal");
        }
    }

}

@@ -134,16 +134,75 @@
 .Model;%0A
+import org.springframework.web.bind.annotation.GetMapping;%0A
 import o
@@ -317,16 +317,63 @@
 pping;%0A%0A
+import org.xcolab.client.contest.pojo.Contest;%0A
 import o
@@ -511,16 +511,70 @@
 oposal;%0A
+import org.xcolab.commons.servlet.flash.AlertMessage;%0A
 import o
@@ -911,16 +911,51 @@
 UrlName%7D
+/c/%7BproposalUrlString%7D/%7BproposalId%7D
 %22)%0Apubli
@@ -1022,43 +1022,8 @@
 g(%22/
-c/%7BproposalUrlString%7D/%7BproposalId%7D/
 subs
@@ -2134,10 +2134,599 @@
 %0A    %7D%0A%0A
+    @GetMapping(%22/subscribeProposal%22)%0A    public String handleInvalidGetRequest(HttpServletRequest request,%0A            HttpServletResponse response, Model model, ProposalContext proposalContext,%0A            Member member) %7B%0A%0A        AlertMessage.warning(%0A                %22Could not subscribe to proposal, please make sure to click the button only once.%22)%0A                .flash(request);%0A        final Contest contest = proposalContext.getContest();%0A        final Proposal proposal = proposalContext.getProposal();%0A        return %22redirect:%22 + proposal.getProposalLinkUrl(contest);%0A    %7D%0A
 %7D%0A

Add get equivalent for subscribe