Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 11:16:11 +01:00

Implement starring

This commit is contained in:
erik 2023-12-07 13:24:01 +01:00 committed by Michael Jerger
parent 976256bf3d
commit 745598bba4

View file

@ -297,14 +297,32 @@ func RepositoryInbox(ctx *context.APIContext) {
} }
} }
} else { remoteUser, err := user_model.GetUserByEmail(ctx, user.Email)
// use first user if err != nil {
user := users[0] ctx.Error(http.StatusInternalServerError, "StarRepo", err)
log.Info("%v", user) return
} }
// TODO: handle case of count > 1 // check if already starred by this user
// execute star action alreadyStared := repo_model.IsStaring(ctx, remoteUser.ID, ctx.Repo.Repository.ID)
switch alreadyStared {
case true: // execute unstar action
{
err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, false)
if err != nil {
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
return
}
}
case false: // execute star action
{
err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, true)
if err != nil {
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
return
}
}
}
// wait 15 sec. // wait 15 sec.