Initial commit
This commit is contained in:
commit
c0cb826917
63 changed files with 2069 additions and 0 deletions
33
internal/domain/entities/images.go
Normal file
33
internal/domain/entities/images.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const ImagesTable = "images"
|
||||
|
||||
type Images struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
Path string `db:"path"`
|
||||
}
|
||||
|
||||
func CreateImage(path string) (image Images, err error) {
|
||||
image = Images{
|
||||
Id: uuid.New(),
|
||||
Path: path,
|
||||
}
|
||||
|
||||
err = image.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (i *Images) Validate() error {
|
||||
if i.Path == "" {
|
||||
return errors.New("Empty image.path")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
68
internal/domain/entities/post.go
Normal file
68
internal/domain/entities/post.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const PostTable = "post"
|
||||
|
||||
type Post struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
UserId uuid.UUID `db:"user_id"`
|
||||
Title string `db:"title"`
|
||||
Description string `db:"description"`
|
||||
Content string `db:"content"`
|
||||
CreatedAt time.Time `db:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updatedAt"`
|
||||
}
|
||||
|
||||
func CreatePost(userId uuid.UUID, title string, description string, content string) (post Post, err error) {
|
||||
post = Post{
|
||||
Id: uuid.New(),
|
||||
UserId: userId,
|
||||
Title: title,
|
||||
Description: description,
|
||||
Content: content,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
|
||||
err = post.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Post) Validate() error {
|
||||
if err := uuid.Validate(p.Id.String()); err != nil {
|
||||
return errors.New("Empty post.id")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(p.UserId.String()); err != nil {
|
||||
return errors.New("Empty post.userId")
|
||||
}
|
||||
|
||||
if p.Title == "" {
|
||||
return errors.New("Empty post.title")
|
||||
}
|
||||
|
||||
if p.Description == "" {
|
||||
return errors.New("Empty post.description")
|
||||
}
|
||||
|
||||
if p.Content == "" {
|
||||
return errors.New("Empty post.content path")
|
||||
}
|
||||
|
||||
if p.CreatedAt.IsZero() {
|
||||
return errors.New("Empty post.createdAt")
|
||||
}
|
||||
|
||||
if p.UpdatedAt.IsZero() {
|
||||
return errors.New("Empty post.updatedAt")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
43
internal/domain/entities/posts.go
Normal file
43
internal/domain/entities/posts.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const PostsTable = "posts"
|
||||
|
||||
type Posts struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
UserId uuid.UUID `db:"user_id"`
|
||||
PostId uuid.UUID `db:"post_id"`
|
||||
}
|
||||
|
||||
func CreatePosts(userId uuid.UUID, postId uuid.UUID) (posts Posts, err error) {
|
||||
posts = Posts{
|
||||
Id: uuid.New(),
|
||||
UserId: userId,
|
||||
PostId: postId,
|
||||
}
|
||||
|
||||
err = posts.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Posts) Validate() error {
|
||||
if err := uuid.Validate(p.Id.String()); err != nil {
|
||||
return errors.New("Invalid posts.id")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(p.UserId.String()); err != nil {
|
||||
return errors.New("Invalid posts.userId")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(p.PostId.String()); err != nil {
|
||||
return errors.New("Invalid posts.postId")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
42
internal/domain/entities/user.go
Normal file
42
internal/domain/entities/user.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const UserTable = "users"
|
||||
|
||||
type User struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
UserName string `db:"username"`
|
||||
Password string `db:"password"`
|
||||
}
|
||||
|
||||
func CreateUser(userName string, password string) (user User, err error) {
|
||||
user = User{
|
||||
Id: uuid.New(),
|
||||
UserName: userName,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
err = user.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (u *User) Validate() error {
|
||||
if err := uuid.Validate(u.Id.String()); err != nil {
|
||||
return errors.New("Invalid user.id")
|
||||
}
|
||||
if u.UserName == "" {
|
||||
return errors.New("Empty user.name")
|
||||
}
|
||||
|
||||
if u.Password == "" {
|
||||
return errors.New("Empty user.password")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
13
internal/domain/repository/images_repo.go
Normal file
13
internal/domain/repository/images_repo.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"58team_blog/internal/domain/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ImagesRepository interface {
|
||||
Create(*entities.Images) error
|
||||
FindById(uuid.UUID) (*entities.Images, error)
|
||||
Delete(uuid.UUID) error
|
||||
}
|
||||
16
internal/domain/repository/post_repo.go
Normal file
16
internal/domain/repository/post_repo.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"58team_blog/internal/domain/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type PostRepository interface {
|
||||
Create(*entities.Post) (*entities.Post, error)
|
||||
FindById(uuid.UUID) (*entities.Post, error)
|
||||
FindAllByUserName(string) ([]*entities.Post, error)
|
||||
GetAll() ([]*entities.Post, error)
|
||||
Update(*entities.Post) error
|
||||
Delete(uuid.UUID) error
|
||||
}
|
||||
17
internal/domain/repository/posts_repo.go
Normal file
17
internal/domain/repository/posts_repo.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"58team_blog/internal/domain/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type PostsRepository interface {
|
||||
Create(*entities.Posts) (*entities.Posts, error)
|
||||
FindById(uuid.UUID) (*entities.Posts, error)
|
||||
FindByPostId(uuid.UUID) (*entities.Posts, error)
|
||||
FindByUserId(uuid.UUID) (*entities.Posts, error)
|
||||
FindAllByUserId(uuid.UUID) ([]*entities.Posts, error)
|
||||
GetAll() ([]*entities.Posts, error)
|
||||
Delete(uuid.UUID) error
|
||||
}
|
||||
16
internal/domain/repository/user_repo.go
Normal file
16
internal/domain/repository/user_repo.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"58team_blog/internal/domain/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type UsersRepository interface {
|
||||
Create(*entities.User) (*entities.User, error)
|
||||
FindById(uuid.UUID) (*entities.User, error)
|
||||
FindByName(string) (*entities.User, error)
|
||||
GetAll() ([]*entities.User, error)
|
||||
Update(*entities.User) error
|
||||
Delete(uuid.UUID) error
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue