// Copyright (c) Mainflux // SPDX-License-Identifier: Apache-2.0 package api import ( "fmt" "net/http" "github.com/mainflux/mainflux" "github.com/mainflux/mainflux/users" ) var ( _ mainflux.Response = (*tokenRes)(nil) _ mainflux.Response = (*viewUserRes)(nil) _ mainflux.Response = (*passwChangeRes)(nil) _ mainflux.Response = (*updateGroupRes)(nil) _ mainflux.Response = (*viewGroupRes)(nil) _ mainflux.Response = (*createGroupRes)(nil) _ mainflux.Response = (*createUserRes)(nil) _ mainflux.Response = (*groupDeleteRes)(nil) _ mainflux.Response = (*assignUserToGroupRes)(nil) _ mainflux.Response = (*removeUserFromGroupRes)(nil) ) // MailSent message response when link is sent const MailSent = "Email with reset link is sent" type pageRes struct { Total uint64 `json:"total"` Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` } type createUserRes struct { ID string created bool } func (res createUserRes) Code() int { if res.created { return http.StatusCreated } return http.StatusOK } func (res createUserRes) Headers() map[string]string { if res.created { return map[string]string{ "Location": fmt.Sprintf("/users/%s", res.ID), } } return map[string]string{} } func (res createUserRes) Empty() bool { return true } type tokenRes struct { Token string `json:"token,omitempty"` } func (res tokenRes) Code() int { return http.StatusCreated } func (res tokenRes) Headers() map[string]string { return map[string]string{} } func (res tokenRes) Empty() bool { return res.Token == "" } type updateUserRes struct{} func (res updateUserRes) Code() int { return http.StatusOK } func (res updateUserRes) Headers() map[string]string { return map[string]string{} } func (res updateUserRes) Empty() bool { return true } type viewUserRes struct { ID string `json:"id"` Email string `json:"email"` Groups []users.Group `json:"groups"` Metadata map[string]interface{} `json:"metadata,omitempty"` } func (res viewUserRes) Code() int { return http.StatusOK } func (res viewUserRes) Headers() map[string]string { return map[string]string{} } func (res viewUserRes) Empty() bool { return false } type userPageRes struct { pageRes Users []viewUserRes } func (res userPageRes) Code() int { return http.StatusOK } func (res userPageRes) Headers() map[string]string { return map[string]string{} } func (res userPageRes) Empty() bool { return false } type createGroupRes struct { ID string `json:"id"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ParentID string `json:"parent_id"` Metadata map[string]interface{} `json:"metadata,omitempty"` created bool } func (res createGroupRes) Code() int { if res.created { return http.StatusCreated } return http.StatusOK } func (res createGroupRes) Headers() map[string]string { if res.created { return map[string]string{ "Location": fmt.Sprintf("/groups/%s", res.ID), } } return map[string]string{} } func (res createGroupRes) Empty() bool { return true } type updateGroupRes struct{} func (res updateGroupRes) Code() int { return http.StatusOK } func (res updateGroupRes) Headers() map[string]string { return map[string]string{} } func (res updateGroupRes) Empty() bool { return true } type viewGroupRes struct { ID string `json:"id"` Name string `json:"name"` ParentID string `json:"parent_id"` OwnerID string `json:"owner_id"` Description string `json:"description"` Metadata map[string]interface{} `json:"metadata,omitempty"` } func (res viewGroupRes) Code() int { return http.StatusOK } func (res viewGroupRes) Headers() map[string]string { return map[string]string{} } func (res viewGroupRes) Empty() bool { return false } type errorRes struct { Err string `json:"error"` } type passwChangeRes struct { Msg string `json:"msg"` } func (res passwChangeRes) Code() int { return http.StatusCreated } func (res passwChangeRes) Headers() map[string]string { return map[string]string{} } func (res passwChangeRes) Empty() bool { return false } type groupPageRes struct { pageRes Groups []viewGroupRes } func (res groupPageRes) Code() int { return http.StatusOK } func (res groupPageRes) Headers() map[string]string { return map[string]string{} } func (res groupPageRes) Empty() bool { return false } type groupDeleteRes struct{} func (res groupDeleteRes) Code() int { return http.StatusNoContent } func (res groupDeleteRes) Headers() map[string]string { return map[string]string{} } func (res groupDeleteRes) Empty() bool { return true } type assignUserToGroupRes struct{} func (res assignUserToGroupRes) Code() int { return http.StatusNoContent } func (res assignUserToGroupRes) Headers() map[string]string { return map[string]string{} } func (res assignUserToGroupRes) Empty() bool { return true } type removeUserFromGroupRes struct{} func (res removeUserFromGroupRes) Code() int { return http.StatusNoContent } func (res removeUserFromGroupRes) Headers() map[string]string { return map[string]string{} } func (res removeUserFromGroupRes) Empty() bool { return true }