Skip to content

Commit

Permalink
add godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Sep 6, 2024
1 parent dd37d7c commit 3b61fc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/controller/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions api/dto/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)),
Expand All @@ -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
}
1 change: 1 addition & 0 deletions api/handler/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b61fc6

Please sign in to comment.