Initial commit

This commit is contained in:
KamilM1205 2025-09-16 13:26:27 +04:00
commit c0cb826917
63 changed files with 2069 additions and 0 deletions

View 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
}

View 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
}

View 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
}

View 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
}