package api import ( "database/sql" "net/http" "atlas9.dev/c/core/dbi" "atlas9.dev/c/core/iam" "atlas9.dev/c/demo/lib" ) type UsersImpl struct { DB *sql.DB Guard lib.Guard Users dbi.Factory[iam.UserStore] } func (s *UsersImpl) GetByEmail(w http.ResponseWriter, r *http.Request) { var req Users_GetByEmailReq if read(w, r, &req) { return } if checkSystem(w, r, s.Guard, iam.CapUsersGetByEmail) { return } ctx := r.Context() var res Users_GetByEmailRes err := dbi.ReadOnly(ctx, s.DB, func(tx dbi.DBI) error { return s.Users(tx).GetByEmail(ctx, req.Email, &res.User) }) write(ctx, w, err, res) } func (s *UsersImpl) List(w http.ResponseWriter, r *http.Request) { var req Users_ListReq if read(w, r, &req) { return } if checkSystem(w, r, s.Guard, iam.CapUsersList) { return } ctx := r.Context() var res Users_ListRes err := dbi.ReadOnly(ctx, s.DB, func(tx dbi.DBI) error { return s.Users(tx).List(ctx, req.Page, &res.Page) }) write(ctx, w, err, res) }