diff --git a/src/models/member.go b/src/models/member.go deleted file mode 100644 index f41cb266..00000000 --- a/src/models/member.go +++ /dev/null @@ -1,22 +0,0 @@ -package models - -type Member struct { - UserID int - - Name *string `db:"name"` // TODO: Migrate to not null - Bio *string `db:"bio"` - Blurb *string `db:"blurb"` - Signature *string `db:"signature"` - Avatar *string `db:"avatar"` // TODO: Image field stuff? - - DarkTheme bool `db:"darktheme"` - Timezone string `db:"timezone"` - ProfileColor1 string `db:"color_1"` - ProfileColor2 string `db:"color_2"` - - ShowEmail bool `db:"showemail"` - CanEditLibrary bool `db:"edit_library"` - - DiscordSaveShowcase bool `db:"discord_save_showcase"` - DiscordDeleteSnippetOnMessageDelete bool `db:"discord_delete_snippet_on_message_delete"` -} diff --git a/src/models/user.go b/src/models/user.go index 0152e766..3f1085e1 100644 --- a/src/models/user.go +++ b/src/models/user.go @@ -20,4 +20,21 @@ type User struct { IsSuperuser bool `db:"is_superuser"` IsStaff bool `db:"is_staff"` IsActive bool `db:"is_active"` + + Name string `db:"name"` + Bio string `db:"bio"` + Blurb string `db:"blurb"` + Signature string `db:"signature"` + Avatar *string `db:"avatar"` // TODO: Image field stuff? + + DarkTheme bool `db:"darktheme"` + Timezone string `db:"timezone"` + ProfileColor1 string `db:"color_1"` + ProfileColor2 string `db:"color_2"` + + ShowEmail bool `db:"showemail"` + CanEditLibrary bool `db:"edit_library"` + + DiscordSaveShowcase bool `db:"discord_save_showcase"` + DiscordDeleteSnippetOnMessageDelete bool `db:"discord_delete_snippet_on_message_delete"` } diff --git a/src/templates/mapping.go b/src/templates/mapping.go index 978dd0dc..e13d398a 100644 --- a/src/templates/mapping.go +++ b/src/templates/mapping.go @@ -2,23 +2,6 @@ package templates import "git.handmade.network/hmn/hmn/src/models" -func MemberToTemplate(m *models.Member) Member { - return Member{ - Name: maybeString(m.Name), - Blurb: maybeString(m.Blurb), - Signature: maybeString(m.Signature), - - DarkTheme: m.DarkTheme, - Timezone: m.Timezone, - ProfileColor1: m.ProfileColor1, - ProfileColor2: m.ProfileColor2, - - CanEditLibrary: m.CanEditLibrary, - DiscordSaveShowcase: m.DiscordSaveShowcase, - DiscordDeleteSnippetOnMessageDelete: m.DiscordDeleteSnippetOnMessageDelete, - } -} - func PostToTemplate(p *models.Post) Post { return Post{ Preview: p.Preview, @@ -48,6 +31,19 @@ func UserToTemplate(u *models.User) User { Email: u.Email, IsSuperuser: u.IsSuperuser, IsStaff: u.IsStaff, + + Name: u.Name, + Blurb: u.Blurb, + Signature: u.Signature, + + DarkTheme: u.DarkTheme, + Timezone: u.Timezone, + ProfileColor1: u.ProfileColor1, + ProfileColor2: u.ProfileColor2, + + CanEditLibrary: u.CanEditLibrary, + DiscordSaveShowcase: u.DiscordSaveShowcase, + DiscordDeleteSnippetOnMessageDelete: u.DiscordDeleteSnippetOnMessageDelete, } } diff --git a/src/templates/types.go b/src/templates/types.go index 57472839..735ff1ba 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -12,22 +12,6 @@ type BaseData struct { User *User } -type Member struct { - Name string - Blurb string - Signature string - // Avatar?? - - DarkTheme bool - Timezone string - ProfileColor1 string - ProfileColor2 string - - CanEditLibrary bool - DiscordSaveShowcase bool - DiscordDeleteSnippetOnMessageDelete bool -} - type Post struct { Preview string ReadOnly bool @@ -54,6 +38,20 @@ type User struct { Email string IsSuperuser bool IsStaff bool + + Name string + Blurb string + Signature string + // TODO: Avatar?? + + DarkTheme bool + Timezone string + ProfileColor1 string + ProfileColor2 string + + CanEditLibrary bool + DiscordSaveShowcase bool + DiscordDeleteSnippetOnMessageDelete bool } type OpenGraphItem struct { diff --git a/src/website/landing.go b/src/website/landing.go index fdca316e..6a948adf 100644 --- a/src/website/landing.go +++ b/src/website/landing.go @@ -55,6 +55,11 @@ func Index(c *RequestContext) ResponseData { allProjects := iterProjects.ToSlice() c.Logger.Info().Interface("allProjects", allProjects).Msg("all the projects") + var currentUserId *int + if c.CurrentUser != nil { + currentUserId = &c.CurrentUser.ID + } + for _, projRow := range allProjects { proj := projRow.(*models.Project) @@ -64,7 +69,6 @@ func Index(c *RequestContext) ResponseData { CatLastReadTime *time.Time `db:"clri.lastread"` } - memberId := 3 // TODO: NO projectPostIter, err := db.Query(c.Context(), c.Conn, ProjectPost{}, ` SELECT $columns @@ -74,11 +78,11 @@ func Index(c *RequestContext) ResponseData { JOIN handmade_category AS cat ON cat.id = thread.category_id LEFT OUTER JOIN handmade_threadlastreadinfo AS tlri ON ( tlri.thread_id = thread.id - AND tlri.member_id = $1 + AND tlri.user_id = $1 ) LEFT OUTER JOIN handmade_categorylastreadinfo AS clri ON ( clri.category_id = cat.id - AND clri.member_id = $1 + AND clri.user_id = $1 ) WHERE cat.project_id = $2 @@ -88,7 +92,7 @@ func Index(c *RequestContext) ResponseData { ORDER BY postdate DESC LIMIT $7 `, - memberId, + currentUserId, proj.ID, models.CatTypeBlog, models.CatTypeForum, models.CatTypeWiki, models.CatTypeLibraryResource, maxPosts, diff --git a/src/website/requesthandling.go b/src/website/requesthandling.go index d4d68bc9..1f48b7d9 100644 --- a/src/website/requesthandling.go +++ b/src/website/requesthandling.go @@ -49,7 +49,6 @@ type RequestContext struct { Conn *pgxpool.Pool CurrentProject *models.Project CurrentUser *models.User - // CurrentMember *models.Member } func NewRequestContext(rw http.ResponseWriter, req *http.Request, pathParams httprouter.Params) *RequestContext { diff --git a/src/website/routes.go b/src/website/routes.go index c7ad47f0..1adf725d 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -278,9 +278,9 @@ func CommonWebsiteDataWrapper(c *RequestContext) (bool, ResponseData) { sessionCookie, err := c.Req.Cookie(auth.SessionCookieName) if err == nil { - user, err := getCurrentUserAndMember(c, sessionCookie.Value) + user, err := getCurrentUser(c, sessionCookie.Value) if err != nil { - return false, ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to get current user and member")) + return false, ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to get current user")) } c.CurrentUser = user @@ -290,11 +290,9 @@ func CommonWebsiteDataWrapper(c *RequestContext) (bool, ResponseData) { return true, ResponseData{} } -// Given a session id, fetches user and member data from the database. Will return nil for -// both if neither can be found, and will only return an error if it's serious. -// -// TODO: actually return members :) -func getCurrentUserAndMember(c *RequestContext, sessionId string) (*models.User, error) { +// Given a session id, fetches user data from the database. Will return nil if +// the user cannot be found, and will only return an error if it's serious. +func getCurrentUser(c *RequestContext, sessionId string) (*models.User, error) { session, err := auth.GetSession(c.Context(), c.Conn, sessionId) if err != nil { if errors.Is(err, auth.ErrNoSession) { @@ -315,7 +313,5 @@ func getCurrentUserAndMember(c *RequestContext, sessionId string) (*models.User, } user := userRow.(*models.User) - // TODO: Also get the member model - return user, nil }