Added sub commands for doing admin stuff
This commit is contained in:
parent
329de2f953
commit
4a6b79db17
18 changed files with 531 additions and 185 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"emperror.dev/errors"
|
||||
"github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"lmika.dev/lmika/weiro/models"
|
||||
"lmika.dev/lmika/weiro/providers/db"
|
||||
)
|
||||
|
|
@ -90,6 +91,7 @@ func (s *Service) FirstRun(ctx context.Context, req FirstRunRequest) (newUser mo
|
|||
target := models.SitePublishTarget{
|
||||
SiteID: newSite.ID,
|
||||
Enabled: true,
|
||||
GUID: models.NewNanoID(),
|
||||
BaseURL: req.SiteURL,
|
||||
TargetType: "netlify",
|
||||
TargetRef: req.NetlifySiteID,
|
||||
|
|
@ -102,3 +104,25 @@ func (s *Service) FirstRun(ctx context.Context, req FirstRunRequest) (newUser mo
|
|||
|
||||
return newUser, newSite, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetSiteByID(ctx context.Context, siteID int64) (models.Site, error) {
|
||||
user, ok := models.GetUser(ctx)
|
||||
if !ok {
|
||||
return models.Site{}, models.UserRequiredError
|
||||
}
|
||||
|
||||
site, err := s.db.SelectSiteByID(ctx, siteID)
|
||||
if err != nil {
|
||||
return models.Site{}, err
|
||||
}
|
||||
|
||||
if site.OwnerID != user.ID {
|
||||
return models.Site{}, fiber.ErrForbidden
|
||||
}
|
||||
|
||||
return site, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListAllSitesWithOwners(ctx context.Context) ([]db.SiteWithOwner, error) {
|
||||
return s.db.SelectAllSitesWithOwners(ctx)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue