Skip to content

Commit

Permalink
chore (SRS-06) : add timestamp to users collections
Browse files Browse the repository at this point in the history
  • Loading branch information
PickHD committed May 8, 2023
1 parent e8e8339 commit 6fd24f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions auth/internal/v1/model/user.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package model

import "go.mongodb.org/mongo-driver/bson/primitive"
import (
"time"

"go.mongodb.org/mongo-driver/bson/primitive"
)

type (
// User consist data of users
User struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
FullName string `bson:"fullname,omitempty"`
Email string `bson:"email,omitempty"`
Password string `bson:"password,omitempty"`
ID primitive.ObjectID `bson:"_id,omitempty"`
FullName string `bson:"fullname,omitempty"`
Email string `bson:"email,omitempty"`
Password string `bson:"password,omitempty"`
CreatedAt time.Time `bson:"created_at,omitempty"`
}
)
8 changes: 5 additions & 3 deletions auth/internal/v1/repository/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repository

import (
"context"
"time"

"github.com/PickHD/singkatin-revamp/auth/internal/v1/config"
"github.com/PickHD/singkatin-revamp/auth/internal/v1/model"
Expand Down Expand Up @@ -44,9 +45,10 @@ func (ar *AuthRepositoryImpl) CreateUser(ctx context.Context, req *model.User) (
// if doc not exists, create new one
if err == mongo.ErrNoDocuments {
res, err := ar.DB.Collection(ar.Config.Database.UsersCollection).InsertOne(ctx, model.User{
FullName: req.FullName,
Email: req.Email,
Password: req.Password,
FullName: req.FullName,
Email: req.Email,
Password: req.Password,
CreatedAt: time.Now(),
})
if err != nil {
ar.Logger.Error("AuthRepositoryImpl.CreateUser InsertOne ERROR, ", err)
Expand Down

0 comments on commit 6fd24f4

Please sign in to comment.