-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement all repository functions and move away from mongoClient
Part of #34
- Loading branch information
Hiep
committed
Aug 11, 2020
1 parent
8195778
commit a03d116
Showing
11 changed files
with
1,522 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/theycallmemac/odin/odin-engine/pkg/jobs" | ||
"github.com/valyala/fasthttp" | ||
"github.com/valyala/fasthttp" | ||
) | ||
|
||
// LinkJobs is used to link two jobs together | ||
func LinkJobs(ctx *fasthttp.RequestCtx) { | ||
func LinkJobs(client *jobs.Client, ctx *fasthttp.RequestCtx) { | ||
split := strings.Split(string(ctx.PostBody()), "_") | ||
from, to, uid := split[0], split[1], split[2] | ||
client, _ := jobs.SetupClient() | ||
updated := jobs.AddJobLink(client, from, to, uid) | ||
if updated == 1 { | ||
fmt.Fprintf(ctx, "Job " + from + " linked to " + to + "!\n") | ||
if err := client.Repo.AddJobLink(ctx, from, to, uid); err != nil { | ||
fmt.Fprintf(ctx, "[FAILED] Job %s could not be linked to %s: %v\n", from, to, err) | ||
} else { | ||
fmt.Fprintf(ctx, "Job " + from + " could not be linked to " + to + ".\n") | ||
fmt.Fprintf(ctx, "[SUCCESS] Job %s linked to %s\n", from, to) | ||
} | ||
} | ||
|
||
// UnlinkJobs is used to delete a job link | ||
func UnlinkJobs(ctx *fasthttp.RequestCtx) { | ||
func UnlinkJobs(client *jobs.Client, ctx *fasthttp.RequestCtx) { | ||
split := strings.Split(string(ctx.PostBody()), "_") | ||
from, to, uid := split[0], split[1], split[2] | ||
client, _ := jobs.SetupClient() | ||
updated := jobs.DeleteJobLink(client, from, to, uid) | ||
if updated == 1 { | ||
fmt.Fprintf(ctx, "Job " + to + " unlinked from " + from + "!\n") | ||
if err := client.Repo.DeleteJobLink(ctx, from, to, uid); err != nil { | ||
fmt.Fprintf(ctx, "[FAILED] Link %s could not be unlinked from %s: %v\n", to, from, err) | ||
} else { | ||
fmt.Fprintf(ctx, "Job " + to + " has no links!\n") | ||
fmt.Fprintf(ctx, "[SUCCESS] Link %s unlinked from %s\n", to, from) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.