Refactor Store into SessionStore; move domain SQL onto User/Question/Answer.

This commit is contained in:
2026-08-22 02:40:51 -07:00
parent f31f352838
commit c77298411e
15 changed files with 696 additions and 876 deletions
+8 -4
View File
@@ -91,7 +91,11 @@ func (s *Server) handleProfile(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.store.UpdateProfile(r.Context(), u.ID, state, avatarURL); err != nil {
u.State = state
if avatarURL != "" {
u.AvatarURL = avatarURL
}
if err := u.SaveProfile(r.Context()); err != nil {
http.Error(w, "could not save profile", http.StatusInternalServerError)
return
}
@@ -122,16 +126,16 @@ func (s *Server) renderProfile(w http.ResponseWriter, r *http.Request, u *store.
)
if u.Admin() {
label = "Questions you answered"
questions, err = s.store.ListQuestionsAnsweredBy(r.Context(), u.ID)
questions, err = store.ListQuestionsAnsweredBy(r.Context(), s.db, u.ID)
} else {
label = "Your questions"
questions, err = s.store.ListQuestionsByAuthor(r.Context(), u.ID)
questions, err = store.ListQuestionsByAuthor(r.Context(), s.db, u.ID)
}
if err != nil {
http.Error(w, "could not load questions", http.StatusInternalServerError)
return
}
if fresh, e := s.store.UserByID(r.Context(), u.ID); e == nil {
if fresh, e := store.UserByID(r.Context(), s.db, u.ID); e == nil {
u = fresh
}
p := s.basePage(r, "Profile")