diff --git a/cmd/server/http/handlers_usernotes.go b/cmd/server/http/handlers_usernotes.go new file mode 100644 index 0000000..4e4fc34 --- /dev/null +++ b/cmd/server/http/handlers_usernotes.go @@ -0,0 +1,27 @@ +package http + +import ( + "encoding/json" + "net/http" + + "github.com/bnkamalesh/errors" + "github.com/bnkamalesh/goapp/internal/usernotes" + "github.com/bnkamalesh/webgo/v7" +) + +func (h *Handlers) CreateUserNote(w http.ResponseWriter, r *http.Request) error { + unote := new(usernotes.Note) + err := json.NewDecoder(r.Body).Decode(unote) + if err != nil { + return errors.InputBodyErr(err, "invalid JSON provided") + } + + un, err := h.apis.CreateUserNote(r.Context(), unote) + if err != nil { + return err + } + + webgo.R200(w, un) + + return nil +} diff --git a/cmd/subscribers/kafka/kafka.go b/cmd/subscribers/kafka/kafka.go index e0c7116..6c6d13a 100644 --- a/cmd/subscribers/kafka/kafka.go +++ b/cmd/subscribers/kafka/kafka.go @@ -1,3 +1,4 @@ +// Package kafka implements the Kafka subscription functionality package kafka import "github.com/bnkamalesh/goapp/internal/api" diff --git a/internal/api/api.go b/internal/api/api.go index dc63020..3309d61 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/bnkamalesh/goapp/internal/usernotes" "github.com/bnkamalesh/goapp/internal/users" ) @@ -15,6 +16,8 @@ var ( type Server interface { CreateUser(ctx context.Context, user *users.User) (*users.User, error) ReadUserByEmail(ctx context.Context, email string) (*users.User, error) + CreateUserNote(ctx context.Context, un *usernotes.Note) (*usernotes.Note, error) + ReadUserNote(ctx context.Context, userID string, noteID string) (*usernotes.Note, error) ServerHealth() (map[string]any, error) } @@ -24,7 +27,8 @@ type Subscriber interface { } type API struct { - users *users.Users + users *users.Users + unotes *usernotes.UserNotes } // ServerHealth returns the health of the serever app along with other info like version @@ -40,18 +44,17 @@ func (a *API) ServerHealth() (map[string]any, error) { } -func New(us *users.Users) *API { +func New(us *users.Users, un *usernotes.UserNotes) *API { return &API{ - users: us, + users: us, + unotes: un, } } -func NewServer(us *users.Users) Server { - return &API{ - users: us, - } +func NewServer(us *users.Users, un *usernotes.UserNotes) Server { + return New(us, un) } -func NewSubscriber() Subscriber { - return &API{} +func NewSubscriber(us *users.Users) Subscriber { + return New(us, nil) } diff --git a/internal/api/usernotes.go b/internal/api/usernotes.go new file mode 100644 index 0000000..9f3369c --- /dev/null +++ b/internal/api/usernotes.go @@ -0,0 +1,16 @@ +package api + +import ( + "context" + "errors" + + "github.com/bnkamalesh/goapp/internal/usernotes" +) + +func (a *API) CreateUserNote(ctx context.Context, un *usernotes.Note) (*usernotes.Note, error) { + return nil, errors.New("create user not is not implemented") +} + +func (a *API) ReadUserNote(ctx context.Context, userID string, noteID string) (*usernotes.Note, error) { + return nil, errors.New("read user not is not implemented") +}