Skip to content
Snippets Groups Projects
Commit 7fb25a32 authored by Flnal's avatar Flnal
Browse files

added GetCampagin2 (for special IDs)

parent 2fc38f41
No related branches found
No related tags found
1 merge request!3Master
......@@ -31,6 +31,7 @@ func main() {
router.HandleFunc("/health", handler.Health).Methods("GET")
router.HandleFunc("/campaign", handler.CreateCampaign).Methods("POST")
router.HandleFunc("/campaigns", handler.GetCampaigns).Methods("GET")
router.HandleFunc("/campaign/{id}", handler.GetCampaign2).Methods("GET")
if err := http.ListenAndServe(":8000", router); err != nil {
log.Fatal(err)
}
......
......@@ -44,3 +44,21 @@ func GetCampaign(r *http.Request) (*model.Campaign, error) {
}
return &campaign, nil
}
func GetCampaign2(w http.ResponseWriter, r *http.Request) {
id, idErr := getId(r)
if idErr != nil {
log.Errorf("Error calling service getId: %v", idErr)
http.Error(w, idErr.Error(), http.StatusInternalServerError)
return
}
resCampaign, err := service.GetCampaign2(id)
if err != nil {
log.Errorf("Error calling service GetCampaign: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
log.Infof("Campaign with the ID %v was printed", resCampaign.ID)
sendJson(w, resCampaign)
}
package service
import (
"errors"
log "github.com/sirupsen/logrus"
"gitlab.reutlingen-university.de/albrecht/myaktion-go/src/myaktion/model"
......@@ -32,3 +34,16 @@ func GetCampaigns() ([]model.Campaign, error) {
log.Tracef("Retrieved: %v", campaigns)
return campaigns, nil
}
func GetCampaign2(requestedID uint) (model.Campaign, error) {
var resCampaign model.Campaign
for _, campaign := range campaignStore {
if campaign.ID == requestedID {
resCampaign = *campaign
log.Tracef("Retrieved: %v", resCampaign)
return resCampaign, nil
}
}
return resCampaign, errors.New("keine Campaign mit der ID wurde gefunden")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment