Use generated interface
This commit is contained in:
@ -12,7 +12,6 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -60,7 +59,7 @@ func (r *createElectionRequestWithValidator) isValid() bool {
|
||||
return r.Valid()
|
||||
}
|
||||
|
||||
func (app *application) createElection(w http.ResponseWriter, r *http.Request) {
|
||||
func (app *application) CreateElection(w http.ResponseWriter, r *http.Request) {
|
||||
var request createElectionRequestWithValidator
|
||||
|
||||
if err := app.unmarshalRequest(r, &request); err != nil {
|
||||
@ -131,7 +130,7 @@ func (r *createVotesRequestWithValidator) isValid() bool {
|
||||
return r.Valid()
|
||||
}
|
||||
|
||||
func (app *application) createVotes(w http.ResponseWriter, r *http.Request) {
|
||||
func (app *application) CreateVotes(w http.ResponseWriter, r *http.Request, id int) {
|
||||
var request createVotesRequestWithValidator
|
||||
|
||||
if err := app.unmarshalRequest(r, &request); err != nil {
|
||||
@ -144,13 +143,7 @@ func (app *application) createVotes(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
electionID, err := strconv.Atoi(r.PathValue("id"))
|
||||
if err != nil {
|
||||
app.clientError(w, http.StatusBadRequest, "Couldn't convert the id you provided to a number")
|
||||
return
|
||||
}
|
||||
|
||||
election, err := app.elections.GetById(electionID)
|
||||
election, err := app.elections.GetById(id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
app.clientError(w, http.StatusNotFound, "Couldn't find an election with the ID you provided")
|
||||
@ -274,3 +267,7 @@ func (app *application) createVotesHandleUnknownVotersElection(w http.ResponseWr
|
||||
|
||||
return voterIdentity, nil
|
||||
}
|
||||
|
||||
func (app *application) GetElectionResults(w http.ResponseWriter, r *http.Request, id int) {
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user