Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-22 09:54:24 +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 {
// use first user
user := users[0]
log.Info("%v", user)
remoteUser, err := user_model.GetUserByEmail(ctx, user.Email)
if err != nil {
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
return
}
// TODO: handle case of count > 1
// execute star action
// check if already starred by this user
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.