userfriends

package
v0.0.0-...-ebd03d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorForbidden     = Response{Code: http.StatusForbidden, Message: "Forbidden"}
	ErrorUnauthorized  = Response{Code: http.StatusUnauthorized, Message: "Unauthorized"}
	ErrorRequiredField = Response{Code: http.StatusBadRequest, Message: "Required field"}
	ErrorInternal      = Response{Code: http.StatusInternalServerError, Message: "Internal Server Error"}
	ErrorBadRequest    = Response{Code: http.StatusBadRequest, Message: "Bad Request"}
	ErrorNoRecords     = Response{Code: http.StatusOK, Message: "No records found"}
	ErrorNotFound      = Response{Code: http.StatusNotFound, Message: "No records found"}

	ErrFriendAlreadyExists = Response{Code: http.StatusBadRequest, Message: "Friend had already been added"}
	ErrFriendNotExists     = Response{Code: http.StatusNotFound, Message: "Friend is not found"}
	ErrCannotAddSelf       = Response{Code: http.StatusBadRequest, Message: "Cannot add self as friend"}
	ErrCannotDeleteSelf    = Response{Code: http.StatusBadRequest, Message: "Cannot delete self as friend"}
	ErrNotFriend           = Response{Code: http.StatusBadRequest, Message: "Cannot delete non friend"}
)
View Source
var (
	SuccessCreateResponse = Response{Code: 200, Message: "Friend added successfully"}
	SuccessDeleteResponse = Response{Code: 200, Message: "Friend deleted successfully"}
)

Functions

This section is empty.

Types

type CreateUserFriendPayload

type CreateUserFriendPayload struct {
	LoggedUserID string
	UserID       string `json:"userId"`
}

func (CreateUserFriendPayload) Validate

func (p CreateUserFriendPayload) Validate() error

type DeleteUserFriendPayload

type DeleteUserFriendPayload struct {
	LoggedUserID string
	UserID       string `json:"userId"`
}

func (DeleteUserFriendPayload) Validate

func (p DeleteUserFriendPayload) Validate() error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateUserFriends

func (h *Handler) CreateUserFriends(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteUserFriends

func (h *Handler) DeleteUserFriends(w http.ResponseWriter, r *http.Request)

type Repository

type Repository interface {
	AddFriend(ctx context.Context, userFriend *UserFriends) error
	RemoveFriend(ctx context.Context, userID string, friendID string) error
	GetByFriendID(ctx context.Context, userID string, friendID string) (*UserFriends, error)
	ListByUserID(ctx context.Context, userID string) ([]*UserFriends, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Response

type Response struct {
	Code    int
	Message string
	Data    any
	Meta    *response.Pagination
	Error   string
}

type Service

type Service interface {
	Create(ctx context.Context, req CreateUserFriendPayload) Response
	Delete(ctx context.Context, req DeleteUserFriendPayload) Response
}

func NewService

func NewService(repository Repository, userRepository user.Repository) Service

type UserFriends

type UserFriends struct {
	ID        uint64
	UserID    string
	FriendID  string
	CreatedAt time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL