Skip to content

Commit 0b4f15c

Browse files
committed
dtoフォルダ切り離し
1 parent 891050a commit 0b4f15c

File tree

11 files changed

+359
-315
lines changed

11 files changed

+359
-315
lines changed

server/database/mysql/sql/1_create_table.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ CREATE TABLE `users` (
22
`id` varchar(255) COLLATE utf8mb4_bin NOT NULL ,
33
`name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
44
`img` varchar(255) COLLATE utf8mb4_bin NOT NULL,
5-
PRIMARY KEY (`id`)
5+
PRIMARY KEY (`id`)
66
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package dto
2+
3+
import (
4+
"time"
5+
6+
"github.com/Doer-org/glyph/internal/domain/entity"
7+
)
8+
9+
type LoginSessionsDto struct {
10+
Id string `db:"id"`
11+
UserID string `db:"user_id"`
12+
Expiry time.Time `db:"expiry"`
13+
}
14+
15+
type AuthStatesDto struct {
16+
State string `db:"state"`
17+
RedirectURL string `db:"redirect_url"`
18+
}
19+
20+
type DiscordAuthDto struct {
21+
UserID string `db:"user_id"`
22+
AccessToken string `db:"access_token"`
23+
RefreshToken string `db:"refresh_token"`
24+
Expiry time.Time `db:"expiry"`
25+
}
26+
27+
func LoginSessionDtoToEntity(dto *LoginSessionsDto) *entity.LoginSessions {
28+
return &entity.LoginSessions{
29+
ID: dto.Id,
30+
UserID: dto.UserID,
31+
Expiry: dto.Expiry,
32+
}
33+
}
34+
35+
func LoginSessionEntityToDto(u *entity.LoginSessions) LoginSessionsDto {
36+
return LoginSessionsDto{
37+
Id: u.ID,
38+
UserID: u.UserID,
39+
Expiry: u.Expiry,
40+
}
41+
}
42+
43+
func AuthStatesEntityToDto(u *entity.AuthStates) AuthStatesDto {
44+
return AuthStatesDto{
45+
State: u.State,
46+
RedirectURL: u.RedirectURL,
47+
}
48+
}
49+
50+
func AuthStatesDtoToEntity(dto *AuthStatesDto) *entity.AuthStates {
51+
return &entity.AuthStates{
52+
State: dto.State,
53+
RedirectURL: dto.RedirectURL,
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package dto
2+
3+
import (
4+
"time"
5+
6+
"github.com/Doer-org/glyph/internal/domain/entity"
7+
)
8+
9+
type CommentDto struct {
10+
Id string `db:"id"`
11+
User_id string `db:"user_id"`
12+
Glyph_id string `db:"glyph_id"`
13+
Contents string `db:"contents"`
14+
Created_at time.Time `db:"created_at"`
15+
}
16+
type CommentByUserIdDto struct {
17+
Id string `db:"id"`
18+
Glyph_id string `db:"glyph_id"`
19+
Glyph_title string `db:"title"`
20+
Contents string `db:"contents"`
21+
Created_at time.Time `db:"created_at"`
22+
}
23+
24+
type CommentsDto []CommentDto
25+
type CommentsByUserIdDto []CommentByUserIdDto
26+
27+
func CommentEntityToDto(comment *entity.Comment) CommentDto {
28+
return CommentDto{
29+
Id: comment.Id,
30+
User_id: comment.User_id,
31+
Glyph_id: comment.Glyph_id,
32+
Contents: comment.Contents,
33+
Created_at: comment.Created_at,
34+
}
35+
}
36+
37+
func CommentDtoToEntity(dto *CommentDto) *entity.Comment {
38+
dto.Created_at = dto.Created_at.In(time.FixedZone("Asia/Tokyo", 9*60*60))
39+
return &entity.Comment{
40+
Id: dto.Id,
41+
User_id: dto.User_id,
42+
Glyph_id: dto.Glyph_id,
43+
Contents: dto.Contents,
44+
Created_at: dto.Created_at,
45+
}
46+
}
47+
48+
func CommentDtosToEntity(dtos CommentsDto) entity.Comments {
49+
var comments entity.Comments
50+
for _, dto := range dtos {
51+
comments = append(comments, CommentDtoToEntity(&dto))
52+
}
53+
return comments
54+
}
55+
56+
func CommentByUserIdDtoToEntity(dto *CommentByUserIdDto) *entity.CommentByUserId {
57+
dto.Created_at = dto.Created_at.In(time.FixedZone("Asia/Tokyo", 9*60*60))
58+
return &entity.CommentByUserId{
59+
Id: dto.Id,
60+
Glyph_id: dto.Glyph_id,
61+
Glyph_title: dto.Glyph_title,
62+
Contents: dto.Contents,
63+
Created_at: dto.Created_at,
64+
}
65+
}
66+
67+
func CommentByUserIdDtosToEntity(dtos CommentsByUserIdDto) entity.CommentsByUserId {
68+
var comments entity.CommentsByUserId
69+
for _, dto := range dtos {
70+
comments = append(comments, CommentByUserIdDtoToEntity(&dto))
71+
}
72+
return comments
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package dto
2+
3+
import (
4+
"time"
5+
6+
"github.com/Doer-org/glyph/internal/domain/entity"
7+
)
8+
9+
type GlyphDto struct {
10+
Id string `db:"id"`
11+
Author_id string `db:"author_id"`
12+
Title string `db:"title"`
13+
Content string `db:"content"`
14+
Prev_glyph string `db:"prev_glyph"`
15+
Next_glyph string `db:"next_glyph"`
16+
Status string `db:"status"`
17+
Created_at time.Time `db:"created_at"`
18+
Updated_at time.Time `db:"updated_at"`
19+
Is_study bool `db:"is_study"`
20+
}
21+
type GlyphDtos []GlyphDto
22+
23+
func GlyphDtoToEntity(dto *GlyphDto) *entity.Glyph {
24+
dto.Created_at = dto.Created_at.In(time.FixedZone("Asia/Tokyo", 9*60*60))
25+
dto.Updated_at = dto.Updated_at.In(time.FixedZone("Asia/Tokyo", 9*60*60))
26+
return &entity.Glyph{
27+
Id: dto.Id,
28+
Author_id: dto.Author_id,
29+
Title: dto.Title,
30+
Content: dto.Content,
31+
Prev_glyph: dto.Prev_glyph,
32+
Next_glyph: dto.Next_glyph,
33+
Status: dto.Status,
34+
Created_at: dto.Created_at,
35+
Updated_at: dto.Updated_at,
36+
Is_study: dto.Is_study,
37+
}
38+
}
39+
40+
func GlyphEntityToDto(u *entity.Glyph) GlyphDto {
41+
return GlyphDto{
42+
Id: u.Id,
43+
Author_id: u.Author_id,
44+
Title: u.Title,
45+
Content: u.Content,
46+
Prev_glyph: u.Prev_glyph,
47+
Next_glyph: u.Next_glyph,
48+
Status: u.Status,
49+
Created_at: u.Created_at,
50+
Updated_at: u.Updated_at,
51+
Is_study: u.Is_study,
52+
}
53+
}
54+
55+
func GlyphsDtosToEntity(dtos GlyphDtos) entity.Glyphs {
56+
var glyphs entity.Glyphs
57+
for _, dto := range dtos {
58+
glyph := GlyphDtoToEntity(&dto)
59+
glyphs = append(glyphs, glyph)
60+
}
61+
return glyphs
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dto
2+
3+
import "github.com/Doer-org/glyph/internal/domain/entity"
4+
5+
type ImageDto struct {
6+
Id string `db:"id"`
7+
Img []byte `db:"img"`
8+
}
9+
10+
type ImageDtos []*ImageDto
11+
12+
func ImageDtoToEntity(dto *ImageDto) *entity.Image {
13+
return &entity.Image{
14+
Id: dto.Id,
15+
Img: dto.Img,
16+
}
17+
}
18+
19+
func ImageDtosToEntity(dtos ImageDtos) entity.Images {
20+
var images entity.Images
21+
for _, d := range dtos {
22+
images = append(images, ImageDtoToEntity(d))
23+
}
24+
return images
25+
}
26+
27+
func ImageEntityToDto(img *entity.Image) ImageDto {
28+
return ImageDto{
29+
Id: img.Id,
30+
Img: img.Img,
31+
}
32+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dto
2+
3+
import "github.com/Doer-org/glyph/internal/domain/entity"
4+
5+
type UserDto struct {
6+
Id string `db:"id"`
7+
Name string `db:"name"`
8+
Img string `db:"img"`
9+
}
10+
11+
func UserDtoToEntity(dto *UserDto) *entity.User {
12+
return &entity.User{
13+
Id: dto.Id,
14+
Name: dto.Name,
15+
Img: dto.Img,
16+
}
17+
}
18+
19+
func UserEntityToDto(u *entity.User) UserDto {
20+
return UserDto{
21+
Id: u.Id,
22+
Name: u.Name,
23+
Img: u.Img,
24+
}
25+
}

0 commit comments

Comments
 (0)