forked from shivamsouravjha/stock-backend
-
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
Showing
10 changed files
with
1,116 additions
and
1,020 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
stockbackend |
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,36 @@ | ||
package mongo_client | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
"go.uber.org/zap" | ||
"gopkg.in/mgo.v2/bson" | ||
) | ||
|
||
var ( | ||
Client *mongo.Client | ||
) | ||
|
||
func init() { | ||
serverAPI := options.ServerAPI(options.ServerAPIVersion1) | ||
mongoURI := os.Getenv("MONGO_URI") | ||
// zap.L().Info("Mongo URI", zap.String("uri", mongoURI)) | ||
opts := options.Client().ApplyURI(mongoURI).SetServerAPIOptions(serverAPI) | ||
// Create a new client and connect to the server | ||
var err error | ||
Client, err = mongo.Connect(context.TODO(), opts) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Send a ping to confirm a successful connection | ||
pingCmd := bson.M{"ping": 1} | ||
if err := Client.Database("admin").RunCommand(context.TODO(), pingCmd).Err(); err != nil { | ||
panic(err) | ||
} | ||
|
||
zap.L().Info("Connected to MongoDB") | ||
} |
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,45 @@ | ||
package controllers | ||
|
||
import ( | ||
"stockbackend/services" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type FileControllerI interface { | ||
ParseXLSXFile(ctx *gin.Context) | ||
} | ||
|
||
type fileController struct{} | ||
|
||
var FileController FileControllerI = &fileController{} | ||
|
||
func (f *fileController) ParseXLSXFile(ctx *gin.Context) { | ||
// Parse the form and retrieve the uploaded files | ||
form, err := ctx.MultipartForm() | ||
if err != nil { | ||
ctx.JSON(400, gin.H{"error": "Error parsing form data"}) | ||
return | ||
} | ||
|
||
// Retrieve the files from the form | ||
files := form.File["files"] | ||
if len(files) == 0 { | ||
ctx.JSON(400, gin.H{"error": "No files found"}) | ||
return | ||
} | ||
|
||
// Set headers for chunked transfer (if needed) | ||
ctx.Writer.Header().Set("Content-Type", "text/plain") | ||
ctx.Writer.Header().Set("Cache-Control", "no-cache") | ||
ctx.Writer.Header().Set("Connection", "keep-alive") | ||
|
||
err = services.FileService.ParseXLSXFile(ctx, files) | ||
if err != nil { | ||
ctx.JSON(500, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
ctx.Writer.Write([]byte("\nStream complete.\n")) | ||
ctx.Writer.Flush() // Ensure the final response is sent | ||
} |
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,15 @@ | ||
package controllers | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type HealthControllerI interface { | ||
IsRunning(ctx *gin.Context) | ||
} | ||
|
||
type healthController struct{} | ||
|
||
var HealthController HealthControllerI = &healthController{} | ||
|
||
func (h *healthController) IsRunning(ctx *gin.Context) { | ||
ctx.JSON(200, gin.H{"message": "Server is running"}) | ||
} |
Oops, something went wrong.