-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from bldg14/kf/functional-core-imperative-shell
functional core imperative shell
- Loading branch information
Showing
10 changed files
with
229 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bldg14/eventual/internal/shell/storage" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
) | ||
|
||
type Event struct { | ||
Title string `json:"title"` | ||
Start string `json:"start"` | ||
End string `json:"end"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` | ||
Email string `json:"email"` | ||
} | ||
|
||
func GetAllEvents(pool *pgxpool.Pool) ([]Event, error) { | ||
storageEvents, err := storage.GetAll(pool) | ||
if err != nil { | ||
return nil, fmt.Errorf("HandleGetAllEvents failed to GetAll: %w", err) | ||
} | ||
|
||
events := make([]Event, len(storageEvents)) | ||
for i, storageEvent := range storageEvents { | ||
events[i] = Event{ | ||
Title: storageEvent.Title, | ||
Start: storageEvent.Start.Format(time.RFC3339), | ||
End: storageEvent.End.Format(time.RFC3339), | ||
Description: storageEvent.Description, | ||
URL: storageEvent.URL, | ||
Email: storageEvent.Email, | ||
} | ||
} | ||
|
||
return events, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/bldg14/eventual/internal/shell/app" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
"github.com/kevinfalting/mux" | ||
) | ||
|
||
func HandleGetAllEvents(pool *pgxpool.Pool) mux.ErrHandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) error { | ||
events, err := app.GetAllEvents(pool) | ||
if err != nil { | ||
return mux.Error(fmt.Errorf("HandleGetAllEvents failed to GetAllEvents: %w", err), http.StatusInternalServerError) | ||
} | ||
|
||
result, err := json.Marshal(events) | ||
if err != nil { | ||
return mux.Error(fmt.Errorf("HandleGetAllEvents failed to Marshal: %w", err), http.StatusInternalServerError) | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write(result) | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.