From 3b61fc6fb9c532a157787c6a2e5a478a3e789511 Mon Sep 17 00:00:00 2001 From: almostinf Date: Fri, 6 Sep 2024 14:11:33 +0300 Subject: [PATCH] add godoc --- api/controller/emergency_contact.go | 2 +- api/dto/emergency_contact.go | 8 ++++++++ api/handler/emergency_contact.go | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/api/controller/emergency_contact.go b/api/controller/emergency_contact.go index 2fd0bf99e..11ca281fc 100644 --- a/api/controller/emergency_contact.go +++ b/api/controller/emergency_contact.go @@ -105,7 +105,7 @@ func UpdateEmergencyContact(database moira.Database, contactID string, emergency }, nil } -// UpdateEmergencyContact a method to delete the emergency contact. +// RemoveEmergencyContact a method to delete the emergency contact. func RemoveEmergencyContact(database moira.Database, contactID string) *api.ErrorResponse { if err := database.RemoveEmergencyContact(contactID); err != nil { return api.ErrorInternalServer(err) diff --git a/api/dto/emergency_contact.go b/api/dto/emergency_contact.go index 3e2d6b5bd..3202075e6 100644 --- a/api/dto/emergency_contact.go +++ b/api/dto/emergency_contact.go @@ -11,15 +11,18 @@ import ( // ErrEmptyEmergencyTypes means that the user has not specified any emergency types. var ErrEmptyEmergencyTypes = errors.New("emergency types can not be empty") +// EmergencyContact is the DTO structure for contacts to which notifications will go in the event of special internal Moira problems. type EmergencyContact struct { ContactID string `json:"contact_id" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"` EmergencyTypes []moira.EmergencyContactType `json:"emergency_types" example:"notifier_off"` } +// Render is a function that implements chi Renderer interface for EmergencyContact. func (*EmergencyContact) Render(w http.ResponseWriter, r *http.Request) error { return nil } +// Bind is a method that implements Binder interface from chi and checks that validity of data in request. func (emergencyContact *EmergencyContact) Bind(r *http.Request) error { if len(emergencyContact.EmergencyTypes) == 0 { return ErrEmptyEmergencyTypes @@ -34,14 +37,17 @@ func (emergencyContact *EmergencyContact) Bind(r *http.Request) error { return nil } +// EmergencyContactList is the DTO structure for list of contacts to which notifications will go in the event of special internal Moira problems. type EmergencyContactList struct { List []EmergencyContact `json:"list"` } +// Render is a function that implements chi Renderer interface for EmergencyContactList. func (*EmergencyContactList) Render(w http.ResponseWriter, r *http.Request) error { return nil } +// FromEmergencyContacts a method that converts emergency contacts to dto emergency ccontact list. func FromEmergencyContacts(emergencyContacts []*moira.EmergencyContact) *EmergencyContactList { emergencyContactsDTO := &EmergencyContactList{ List: make([]EmergencyContact, 0, len(emergencyContacts)), @@ -56,10 +62,12 @@ func FromEmergencyContacts(emergencyContacts []*moira.EmergencyContact) *Emergen return emergencyContactsDTO } +// SaveEmergencyContactResponse is the DTO structure which is returned in the methods of saving contact. type SaveEmergencyContactResponse struct { ContactID string `json:"contact_id" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"` } +// Render is a function that implements chi Renderer interface for SaveEmergencyContactResponse. func (SaveEmergencyContactResponse) Render(w http.ResponseWriter, r *http.Request) error { return nil } diff --git a/api/handler/emergency_contact.go b/api/handler/emergency_contact.go index 2b6270920..72681f4e4 100644 --- a/api/handler/emergency_contact.go +++ b/api/handler/emergency_contact.go @@ -170,6 +170,7 @@ func removeEmergencyContact(writer http.ResponseWriter, request *http.Request) { } } +// emergencyContactFilter is middleware for check emergency contact existence. func emergencyContactFilter(next http.Handler) http.Handler { return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { contactID := middleware.GetContactID(request)