mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Implement starring
This commit is contained in:
parent
976256bf3d
commit
745598bba4
1 changed files with 24 additions and 6 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue