Skip to content

Refactor: Domain and DTO models#159

Draft
GaballaGit wants to merge 56 commits intomainfrom
refactor--domain-models
Draft

Refactor: Domain and DTO models#159
GaballaGit wants to merge 56 commits intomainfrom
refactor--domain-models

Conversation

@GaballaGit
Copy link
Member

DBmodels are models that should not be known to exist by the CLI and any other internals that want to use them.

This PR introduces a solution to that: DTO and Domain models.
Handlers take in a dto_request model and send it over to services as a domain model. Services then call repository where it can access database operations.

Something I am thinking about: Originally I split dto_requests and dto_response into two modules thinking that we can return the client a specialized dto, if we wanted to hide ID or anything else, I dicided against hiding ID for now, and I have yet to find a use for dto_response. So perhaps we should merge the DTO modules to one to reduce code. Some opinions will be good.

TheJolman and others added 2 commits February 11, 2026 09:02
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@GaballaGit GaballaGit marked this pull request as draft February 11, 2026 17:35
@GaballaGit
Copy link
Member Author

Note: positions domain models and dto models are going to need some change, I do not have a full understanding of them yet. So changes have not been implemented to Positions yet.

@GaballaGit
Copy link
Member Author

GaballaGit commented Feb 15, 2026

Todo:

  • Update Position models
  • Change how conversions between models work so sqlnull values don't get unconditionally set to true
  • Document the new architecture

@GaballaGit
Copy link
Member Author

Keeping note of this here: An error has appeared.

Sending an announcement json: &{123 all 2006-01-04 15:00:00 -0800 PST 1234 124} to http://localhost:8080/v1/announcements

The stack dump reads:
2026/02/19 00:01:10 [Recovery] 2026/02/19 - 00:01:10 panic recovered:
POST /v1/announcements HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip
Authorization: *
Content-Length: 125
Content-Type: application/json
User-Agent: Go-http-client/1.1

runtime error: invalid memory address or nil pointer dereference
/nix/store/4h3akzxlwz2c1619i9cnwlh0kyfki5r5-go-1.25.5/share/go/src/runtime/panic.go:262 (0x10407ed87)
panicmem: panic(memoryError)
/nix/store/4h3akzxlwz2c1619i9cnwlh0kyfki5r5-go-1.25.5/share/go/src/runtime/signal_unix.go:925 (0x10407ed58)
sigpanic: panicmem()
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/repository/conv.go:114 (0x104a9e8b0)
convertDomainToCreateDBAnnouncement: DiscordChannelID: sql.NullString{String: *chanID, Valid: validString(chanID)},
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/repository/announcements.go:53 (0x104a9e81c)
(*announcementRepository).Create: err := r.db.CreateAnnouncement(ctx, convertDomainToCreateDBAnnouncement(args))
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/api/services/announcement.go:41 (0x104aa0d93)
(*AnnouncementService).Create: if err := s.announcementRepository.Create(ctx, params); err != nil {
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/api/handlers/announcement.go:94 (0x104b6d363)
(*AnnouncementHandler).CreateAnnouncement: if err := h.announcementService.Create(ctx, mapper.ToAnnouncementDomain(&params)); err != nil {
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/api/middleware/oauth.go:46 (0x104b739bb)
SetupV1.DiscordAuth.func1: c.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/api/middleware/ratelimiter.go:43 (0x104a9d69f)
Ratelimiter.func2: ctx.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/Documents/ACM/apiacmcsuf/api.acmcsuf.com/internal/api/middleware/cors.go:35 (0x104a9d25f)
Cors.func1: ctx.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/recovery.go:92 (0x1048574df)
CustomRecoveryWithWriter.func1: c.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/logger.go:249 (0x1048568d3)
LoggerWithConfig.func1: c.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/context.go:192 (0x10484a297)
(*Context).Next: c.handlersc.index
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/gin.go:689 (0x104855b93)
(*Engine).handleHTTPRequest: c.Next()
/Users/gaballa/go/pkg/mod/github.com/gin-gonic/gin@v1.11.0/gin.go:643 (0x1048556d3)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/nix/store/4h3akzxlwz2c1619i9cnwlh0kyfki5r5-go-1.25.5/share/go/src/net/http/server.go:3340 (0x1042e768f)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/nix/store/4h3akzxlwz2c1619i9cnwlh0kyfki5r5-go-1.25.5/share/go/src/net/http/server.go:2109 (0x1042c98b7)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/nix/store/4h3akzxlwz2c1619i9cnwlh0kyfki5r5-go-1.25.5/share/go/src/runtime/asm_arm64.s:1268 (0x104084ae3)
goexit: MOVD R0, R0 // NOP

This is an issue with dereferencing a nil pointer somewhere upstream, probably with mapper and how it deals with sql null values.

@GaballaGit
Copy link
Member Author

400 level errors related to bad requests seem common too, needs investigating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: decouple sqlc-generated DB models from domain logic

2 participants

Comments