-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f16744e
commit a869a9f
Showing
26 changed files
with
365 additions
and
456 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ bin/main | |
!.secrets/*.secret | ||
config.yml | ||
config.yaml | ||
kratos |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Changelog | ||
|
||
## 09/02/2021 `v0.1.0` | ||
|
||
- Initial Commit for web app | ||
|
||
## 10/02/2021 `v0.1.1` | ||
|
||
- GraphQL support added! | ||
|
||
## 03/02/2021 `v0.1.2` | ||
|
||
- Ory KETO has been phased out in support of Custom MongoDB Solution. | ||
- Nodemailer has been phased out in support of go `net/smtp` package. |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/Mshivam2409/AnC-Courses/database" | ||
"github.com/Mshivam2409/AnC-Courses/models" | ||
"github.com/Mshivam2409/AnC-Courses/services" | ||
"github.com/gofiber/fiber/v2" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
// CreateFile sdfs | ||
func CreateFile(c *fiber.Ctx) error { | ||
d := services.GetService() | ||
n, err := strconv.Atoi(c.FormValue("length")) | ||
cno := c.FormValue("course") | ||
if err != nil { | ||
return &fiber.Error{Code: 422, Message: "Length of files must be a number"} | ||
} | ||
files := []string{} | ||
for i := 0; i < n; i++ { | ||
f, err := c.FormFile("file" + fmt.Sprint(n)) | ||
if err != nil { | ||
return &fiber.Error{Code: 422, Message: "Unable to process file!"} | ||
} | ||
r, err := d.CreateFile("", f) | ||
if err != nil { | ||
return &fiber.Error{Code: 422, Message: "Unable to upload file!"} | ||
} | ||
out, err := json.Marshal(r) | ||
if err != nil { | ||
return &fiber.Error{Code: 422, Message: "Unable to get file ID!"} | ||
} | ||
files = append(files, string(out)) | ||
} | ||
update := bson.D{ | ||
{Key: "$push", Value: bson.D{ | ||
{Key: "driveFiles", Value: bson.A{"$each", files}}, | ||
}}, | ||
} | ||
err = database.MongoClient.Courses.Collection("courses").FindOneAndUpdate(context.TODO(), bson.D{{Key: "number", Value: cno}}, update).Decode(&models.MGMCourse{}) | ||
return c.Status(200).JSON(fiber.Map{"message": "success"}) | ||
} | ||
|
||
func DownloadFile(ctx *fiber.Ctx) error { | ||
d := services.GetService() | ||
s, err := d.GetFile(ctx.Params("fid")) | ||
if err != nil { | ||
return &fiber.Error{Code: 500, Message: "Unable to download file!"} | ||
} | ||
return ctx.Status(200).SendStream(s) | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 +1,39 @@ | ||
package database | ||
|
||
import "go.mongodb.org/mongo-driver/mongo" | ||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/spf13/viper" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
type mongoClient struct { | ||
Users *mongo.Database | ||
Courses *mongo.Database | ||
} | ||
|
||
var usersClient = ConnectUsersDB() | ||
var coursesClinet = ConnectCoursesDB() | ||
// MongoClient ... | ||
var MongoClient = &mongoClient{} | ||
|
||
// ConnectMongo .. | ||
func ConnectMongo() { | ||
MongoClient.Users = connect(viper.GetString("mongo.users"), "primarydb") | ||
MongoClient.Courses = connect(viper.GetString("mongo.courses"), "students") | ||
} | ||
|
||
var MongoClient = &mongoClient{Users: usersClient, Courses: coursesClinet} | ||
func connect(url string, dbname string) *mongo.Database { | ||
clientOptions := options.Client().ApplyURI(url) | ||
client, err := mongo.Connect(context.TODO(), clientOptions) | ||
if err != nil { | ||
log.Fatalf("Unable to Connect to MongoDB %v", err) | ||
} | ||
err = client.Ping(context.TODO(), nil) | ||
if err != nil { | ||
log.Fatalf("Unable to Connect to MongoDB %v", err) | ||
} | ||
log.Printf("Connected to MongoDB! URL : %s", url) | ||
database := client.Database(dbname) | ||
return database | ||
} |
This file was deleted.
Oops, something went wrong.
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.