I am batman
This commit is contained in:
22
services/post-service/internal/database/database.go
Normal file
22
services/post-service/internal/database/database.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Init() (*gorm.DB, error) {
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
if dsn == "" {
|
||||
dsn = "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=UTC"
|
||||
}
|
||||
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
7
services/post-service/internal/models/models.go
Normal file
7
services/post-service/internal/models/models.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package models
|
||||
|
||||
// TODO: Add database models for post service
|
||||
// Example models:
|
||||
// - Post model for blog posts
|
||||
// - Comment model for post comments
|
||||
// - Category model for post categorization
|
||||
7
services/post-service/internal/repository/repository.go
Normal file
7
services/post-service/internal/repository/repository.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package repository
|
||||
|
||||
// TODO: Add database repository implementations
|
||||
// Example repositories:
|
||||
// - PostRepository for post data access
|
||||
// - CommentRepository for comment management
|
||||
// - CategoryRepository for category management
|
||||
13
services/post-service/internal/repository/repository_impl.go
Normal file
13
services/post-service/internal/repository/repository_impl.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewRepository(db *gorm.DB) *Repository {
|
||||
return &Repository{DB: db}
|
||||
}
|
||||
47
services/post-service/internal/server/server.go
Normal file
47
services/post-service/internal/server/server.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "go-microservices/proto/post"
|
||||
"go-microservices/services/post-service/internal/repository"
|
||||
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type PostServer struct {
|
||||
pb.UnimplementedPostServiceServer
|
||||
repo *repository.Repository
|
||||
}
|
||||
|
||||
func NewPostServer(repo *repository.Repository) *PostServer {
|
||||
return &PostServer{repo: repo}
|
||||
}
|
||||
|
||||
func (s *PostServer) CreatePost(ctx context.Context, req *pb.CreatePostRequest) (*pb.CreatePostResponse, error) {
|
||||
// TODO: Implement create post logic
|
||||
post := &pb.Post{Id: "1", AuthorId: req.AuthorId, Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
|
||||
return &pb.CreatePostResponse{Post: post}, nil
|
||||
}
|
||||
|
||||
func (s *PostServer) GetPost(ctx context.Context, req *pb.GetPostRequest) (*pb.GetPostResponse, error) {
|
||||
// TODO: Implement get post logic
|
||||
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: "title", Content: "content", CreatedAt: 0, UpdatedAt: 0}
|
||||
return &pb.GetPostResponse{Post: post}, nil
|
||||
}
|
||||
|
||||
func (s *PostServer) UpdatePost(ctx context.Context, req *pb.UpdatePostRequest) (*pb.UpdatePostResponse, error) {
|
||||
// TODO: Implement update post logic
|
||||
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
|
||||
return &pb.UpdatePostResponse{Post: post}, nil
|
||||
}
|
||||
|
||||
func (s *PostServer) DeletePost(ctx context.Context, req *pb.DeletePostRequest) (*emptypb.Empty, error) {
|
||||
// TODO: Implement delete post logic
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *PostServer) ListPosts(ctx context.Context, req *pb.ListPostsRequest) (*pb.ListPostsResponse, error) {
|
||||
// TODO: Implement list posts logic
|
||||
posts := []*pb.Post{}
|
||||
return &pb.ListPostsResponse{Posts: posts}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user