-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: streamline and use sqlc for media and resource media
- Loading branch information
Showing
24 changed files
with
485 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package media | ||
|
||
type Type string | ||
|
||
const ( | ||
TypeImage Type = "image" | ||
) | ||
|
||
func (mt Type) String() string { | ||
return string(mt) | ||
} | ||
|
||
type ViewForSOSPost struct { | ||
ID int64 `field:"id" json:"id"` | ||
MediaType Type `field:"media_type" json:"media_type"` | ||
URL string `field:"url" json:"url"` | ||
CreatedAt string `field:"created_at" json:"created_at"` | ||
UpdatedAt string `field:"updated_at" json:"updated_at"` | ||
DeletedAt string `field:"deleted_at" json:"deleted_at"` | ||
} | ||
|
||
type ViewListForSOSPost []*ViewForSOSPost |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,80 @@ | ||
package media | ||
|
||
type MediaView struct { | ||
ID int `json:"id"` | ||
MediaType MediaType `json:"mediaType"` | ||
import ( | ||
"time" | ||
|
||
databasegen "github.com/pet-sitter/pets-next-door-api/internal/infra/database/gen" | ||
) | ||
|
||
type DetailView struct { | ||
ID int64 `json:"id"` | ||
MediaType Type `json:"mediaType"` | ||
URL string `json:"url"` | ||
CreatedAt string `json:"createdAt"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
} | ||
|
||
type ListView []*DetailView | ||
|
||
func ToDetailView(media databasegen.FindSingleMediaRow) *DetailView { | ||
return &DetailView{ | ||
ID: int64(media.ID), | ||
MediaType: Type(media.MediaType), | ||
URL: media.Url, | ||
CreatedAt: media.CreatedAt, | ||
} | ||
} | ||
|
||
func ToDetailViewFromCreated(media databasegen.CreateMediaRow) *DetailView { | ||
return &DetailView{ | ||
ID: int64(media.ID), | ||
MediaType: Type(media.MediaType), | ||
URL: media.Url, | ||
CreatedAt: media.CreatedAt, | ||
} | ||
} | ||
|
||
type MediaViewList []*MediaView | ||
func ToDetailViewFromResourceMediaRows(resourceMedia databasegen.FindResourceMediaRow) *DetailView { | ||
return &DetailView{ | ||
ID: int64(resourceMedia.MediaID), | ||
MediaType: Type(resourceMedia.MediaType), | ||
URL: resourceMedia.Url, | ||
CreatedAt: resourceMedia.CreatedAt, | ||
} | ||
} | ||
|
||
func (media *Media) ToMediaView() *MediaView { | ||
return &MediaView{ | ||
func ToDetailViewFromViewForSOSPost(media ViewForSOSPost) *DetailView { | ||
createdAt, err := time.Parse(time.RFC3339, media.CreatedAt) | ||
if err != nil { | ||
createdAt = time.Time{} | ||
} | ||
|
||
return &DetailView{ | ||
ID: media.ID, | ||
MediaType: media.MediaType, | ||
URL: media.URL, | ||
CreatedAt: media.CreatedAt, | ||
CreatedAt: createdAt, | ||
} | ||
} | ||
|
||
func (mediaList *MediaList) ToMediaViewList() MediaViewList { | ||
mediaViewList := make(MediaViewList, len(*mediaList)) | ||
for i, media := range *mediaList { | ||
mediaViewList[i] = media.ToMediaView() | ||
func ToListViewFromResourceMediaRows(resourceMediaList []databasegen.FindResourceMediaRow) ListView { | ||
mediaViewList := make(ListView, len(resourceMediaList)) | ||
for i, resourceMedia := range resourceMediaList { | ||
mediaViewList[i] = ToDetailViewFromResourceMediaRows(resourceMedia) | ||
} | ||
return mediaViewList | ||
} | ||
|
||
type ResourceMediaView struct { | ||
ID int `field:"id"` | ||
ResourceType ResourceType `field:"resource_type"` | ||
ResourceID int `field:"resource_id"` | ||
MediaID int `field:"media_id"` | ||
func ToListViewFromViewListForSOSPost(mediaList ViewListForSOSPost) ListView { | ||
mediaViewList := make(ListView, len(mediaList)) | ||
for i, media := range mediaList { | ||
mediaViewList[i] = ToDetailViewFromViewForSOSPost( | ||
ViewForSOSPost{ | ||
ID: media.ID, | ||
MediaType: media.MediaType, | ||
URL: media.URL, | ||
CreatedAt: media.CreatedAt, | ||
}, | ||
) | ||
} | ||
return mediaViewList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package resourcemedia | ||
|
||
type ResourceType string | ||
|
||
const ( | ||
SOSResourceType ResourceType = "sos_posts" | ||
) | ||
|
||
func (r ResourceType) String() string { | ||
return string(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.