-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rename port; add initial character support
- Loading branch information
1 parent
e7bcb7e
commit d0f902c
Showing
22 changed files
with
179 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
internal/chronicle/adapter/http/character/character_request.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package character | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/SomethingSexy/chronicle/internal/chronicle/core/domain" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type CharacterRequest struct { | ||
ID string `jsonapi:"primary,characters"` | ||
CharacterId string `jsonapi:"attr,characterId"` | ||
Name string `jsonapi:"attr,name"` | ||
Description string `jsonapi:"attr,description"` | ||
} | ||
|
||
func (c *CharacterRequest) Bind(r *http.Request) error { | ||
if c.Name == "" { | ||
return errors.New("missing required name fields") | ||
} | ||
|
||
if _, err := uuid.Parse(c.CharacterId); err != nil { | ||
return errors.New("characterId must be valid UUID") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *CharacterRequest) ToDomain() domain.Character { | ||
return domain.Character{ | ||
CharacterId: uuid.MustParse(c.CharacterId), | ||
Name: c.Name, | ||
Description: c.Description, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package character | ||
|
||
import ( | ||
"net/http" | ||
|
||
corePort "github.com/SomethingSexy/chronicle/internal/chronicle/core/port" | ||
"github.com/SomethingSexy/chronicle/internal/chronicle/port" | ||
"github.com/SomethingSexy/chronicle/internal/common" | ||
"github.com/go-chi/chi/v5" | ||
"github.com/go-chi/render" | ||
) | ||
|
||
func NewCharacterHttpServer(commands port.CharacterCommands, queries port.CharacterQueries) CharacterHttpServer { | ||
return CharacterHttpServer{ | ||
commands: commands, | ||
queries: queries, | ||
} | ||
} | ||
|
||
type CharacterHttpServer struct { | ||
commands port.CharacterCommands | ||
queries port.CharacterQueries | ||
} | ||
|
||
func (h CharacterHttpServer) Routes() chi.Router { | ||
r := chi.NewRouter() | ||
r.Post("/", h.CreateCharacter) | ||
|
||
return r | ||
} | ||
|
||
func (h CharacterHttpServer) CreateCharacter(w http.ResponseWriter, r *http.Request) { | ||
data := &CharacterRequest{} | ||
if err := render.Bind(r, data); err != nil { | ||
render.Render(w, r, common.ErrInvalidRequest(err)) | ||
return | ||
} | ||
|
||
if err := h.commands.CreateCharacter.Handle(r.Context(), corePort.CreateCharacter{ | ||
Character: data.ToDomain(), | ||
}); err != nil { | ||
render.Render(w, r, common.ErrInvalidRequest(err)) | ||
return | ||
} | ||
|
||
render.Status(r, http.StatusCreated) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
internal/chronicle/adapter/persistence/postgres/sqlc/migrations/atlas.sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
h1:DljSNBalsjIkrSZ+WOGYFkwLIstGT0W6kK3Zalo3/9Q= | ||
20240924154059_initial.sql h1:YA7/O03b3X56utueibLwOYeFGKNHYWsGZ+3nyM+YWq8= | ||
h1:TdZuQJmsSrzILr2eodHh12uuIpXTkEIV6zGSwf9SSnk= | ||
20240926193418_initial.sql h1:JA1YcfhJ3X2c51i2AuEQdTXOHrWn+Mfmc1OidtC7oSo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.