Skip to content

Commit

Permalink
basics
Browse files Browse the repository at this point in the history
  • Loading branch information
bnkamalesh committed Feb 17, 2024
1 parent c2aeecb commit e1f56df
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
27 changes: 27 additions & 0 deletions cmd/server/http/handlers_usernotes.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/subscribers/kafka/kafka.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package kafka implements the Kafka subscription functionality
package kafka

import "github.com/bnkamalesh/goapp/internal/api"
Expand Down
21 changes: 12 additions & 9 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"time"

"github.com/bnkamalesh/goapp/internal/usernotes"
"github.com/bnkamalesh/goapp/internal/users"
)

Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -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)
}
16 changes: 16 additions & 0 deletions internal/api/usernotes.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit e1f56df

Please sign in to comment.