feat: implement mongo APIs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -40,6 +41,7 @@ func (h *LetterHandler) GetByYear(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
docs, err := h.repo.GetByYear(r.Context(), year)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetByYear(%d): %v", year, err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch letters")
|
||||
return
|
||||
}
|
||||
@@ -50,6 +52,7 @@ func (h *LetterHandler) GetByRecipient(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
docs, err := h.repo.GetByRecipient(r.Context(), name)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetByRecipient(%s): %v", name, err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch letters")
|
||||
return
|
||||
}
|
||||
@@ -60,6 +63,7 @@ func (h *LetterHandler) GetByLocation(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
docs, err := h.repo.GetByLocation(r.Context(), name)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetByLocation(%s): %v", name, err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch letters")
|
||||
return
|
||||
}
|
||||
@@ -69,6 +73,7 @@ func (h *LetterHandler) GetByLocation(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *LetterHandler) GetYears(w http.ResponseWriter, r *http.Request) {
|
||||
docs, err := h.repo.GetYears(r.Context())
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetYears: %v", err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch years")
|
||||
return
|
||||
}
|
||||
@@ -78,6 +83,7 @@ func (h *LetterHandler) GetYears(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *LetterHandler) GetRecipients(w http.ResponseWriter, r *http.Request) {
|
||||
docs, err := h.repo.GetRecipients(r.Context())
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetRecipients: %v", err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch recipients")
|
||||
return
|
||||
}
|
||||
@@ -87,6 +93,7 @@ func (h *LetterHandler) GetRecipients(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *LetterHandler) GetLocations(w http.ResponseWriter, r *http.Request) {
|
||||
docs, err := h.repo.GetLocations(r.Context())
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] GetLocations: %v", err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch locations")
|
||||
return
|
||||
}
|
||||
@@ -96,6 +103,7 @@ func (h *LetterHandler) GetLocations(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *LetterHandler) Count(w http.ResponseWriter, r *http.Request) {
|
||||
count, err := h.repo.Count(r.Context())
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Count: %v", err)
|
||||
response.Error(w, http.StatusInternalServerError, "failed to count letters")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user