Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/secur #18

Open
wants to merge 6 commits into
base: release/movie-api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.idea
Starlexxx marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/go-park-mail-ru/2024_2_GOATS
go 1.22.2

require (
github.com/docker/go-connections v0.5.0
github.com/go-redis/redis/v8 v8.11.5
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
github.com/labstack/gommon v0.4.2
github.com/lib/pq v1.10.9
github.com/microcosm-cc/bluemonday v1.0.27
github.com/rs/zerolog v1.33.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.33.0
Expand All @@ -17,8 +19,8 @@ require (
require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.7.18 // indirect
Expand All @@ -29,7 +31,6 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -38,6 +39,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand All @@ -57,7 +59,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
Expand All @@ -70,8 +71,6 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand Down
17 changes: 6 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down Expand Up @@ -63,6 +63,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
Expand All @@ -71,15 +73,12 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
Expand All @@ -92,6 +91,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
Expand Down Expand Up @@ -171,10 +172,6 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down Expand Up @@ -237,8 +234,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
70 changes: 40 additions & 30 deletions internal/app/api/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package converter
import (
"database/sql"
"fmt"
"strings"
"time"

"github.com/go-park-mail-ru/2024_2_GOATS/internal/app/api"
Expand Down Expand Up @@ -154,53 +155,62 @@ func ToApiGetMovieResponse(mv *models.MovieInfo) *api.MovieResponse {
}

mvInfo := &api.MovieInfo{
Id: mv.Id,
Title: mv.Title,
Description: mv.Description,
CardUrl: mv.CardUrl,
AlbumUrl: mv.AlbumUrl,
Rating: mv.Rating,
ReleaseDate: mv.ReleaseDate,
MovieType: mv.MovieType,
Country: mv.Country,
VideoUrl: mv.VideoUrl,
}

actors := []*api.ActorShortInfo{}
for _, actor := range mv.Actors {
tempAct := &api.ActorShortInfo{
Id: actor.Id,
Name: actor.Name,
Surname: actor.Surname,
Patronymic: actor.Patronymic,
PhotoUrl: actor.PhotoUrl,
Country: actor.Country,
Id: mv.Id,
Title: mv.Title,
FullDescription: mv.FullDescription,
ShortDescription: mv.ShortDescription,
CardUrl: mv.CardUrl,
AlbumUrl: mv.AlbumUrl,
TitleUrl: mv.TitleUrl,
Rating: mv.Rating,
ReleaseDate: mv.ReleaseDate,
MovieType: mv.MovieType,
Country: mv.Country,
VideoUrl: mv.VideoUrl,
}

actors := []*api.StaffShortInfo{}
directors := []*api.StaffShortInfo{}
staffs := mv.Actors
staffs = append(staffs, mv.Directors...)

for _, staff := range staffs {
tempSt := &api.StaffShortInfo{
Id: staff.Id,
FullName: strings.TrimSpace(fmt.Sprintf("%s %s %s", staff.Name, staff.Surname, staff.Patronymic)),
PhotoUrl: staff.SmallPhotoUrl,
Country: staff.Country,
}

actors = append(actors, tempAct)
if staff.Post == "actor" {
actors = append(actors, tempSt)
}

if staff.Post == "director" {
directors = append(directors, tempSt)
}
}

mvInfo.Actors = actors
mvInfo.Directors = directors

return &api.MovieResponse{
Success: true,
MovieInfo: mvInfo,
}
}

func ToApiGetActorResponse(ac *models.ActorInfo) *api.ActorResponse {
func ToApiGetActorResponse(ac *models.StaffInfo) *api.ActorResponse {
if ac == nil {
return nil
}

actor := &api.Actor{
Id: ac.Id,
Name: ac.Name,
Surname: ac.Surname,
Patronymic: ac.Patronymic,
Biography: ac.Biography,
PhotoUrl: ac.PhotoUrl,
Country: ac.Country,
Id: ac.Id,
FullName: strings.TrimSpace(fmt.Sprintf("%s %s %s", ac.Name, ac.Surname, ac.Patronymic)),
Biography: ac.Biography,
PhotoUrl: ac.BigPhotoUrl,
Country: ac.Country,
}

if ac.Birthdate.Valid {
Expand Down
51 changes: 25 additions & 26 deletions internal/app/api/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,41 @@ type MovieResponse struct {
}

type MovieInfo struct {
Id int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
CardUrl string `json:"card_url"`
AlbumUrl string `json:"album_url"`
Rating float32 `json:"rating"`
ReleaseDate time.Time `json:"release_date"`
MovieType string `json:"movie_type"`
Country string `json:"country"`
VideoUrl string `json:"video_url"`
Actors []*ActorShortInfo `json:"actors_info"`
Id int `json:"id"`
Title string `json:"title"`
FullDescription string `json:"full_description"`
ShortDescription string `json:"short_description"`
CardUrl string `json:"card_url"`
AlbumUrl string `json:"album_url"`
TitleUrl string `json:"title_url"`
Rating float32 `json:"rating"`
ReleaseDate time.Time `json:"release_date"`
MovieType string `json:"movie_type"`
Country string `json:"country"`
VideoUrl string `json:"video_url"`
Actors []*StaffShortInfo `json:"actors_info"`
Directors []*StaffShortInfo `json:"directors_info"`
}

type ActorResponse struct {
Success bool `json:"success"`
ActorInfo *Actor `json:"actor_info"`
}

type ActorShortInfo struct {
Id int `json:"id"`
Name string `json:"name"`
Surname string `json:"surname"`
Patronymic string `json:"patronymic"`
PhotoUrl string `json:"photo_url"`
Country string `json:"country"`
type StaffShortInfo struct {
Id int `json:"id"`
FullName string `json:"full_name"`
PhotoUrl string `json:"photo_url"`
Country string `json:"country"`
}

type Actor struct {
Id int `json:"id"`
Name string `json:"name"`
Surname string `json:"surname"`
Patronymic string `json:"patronymic"`
Biography string `json:"biography"`
Birthdate string `json:"birthdate"`
PhotoUrl string `json:"photo_url"`
Country string `json:"country"`
Id int `json:"id"`
FullName string `json:"full_name"`
Biography string `json:"biography"`
Birthdate string `json:"birthdate"`
PhotoUrl string `json:"photo_url"`
Country string `json:"country"`
}

type ErrorResponse struct {
Expand Down
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func New(isTest bool, port *nat.Port) (*App, error) {
delMov := movieApi.NewMovieHandler(ctx, srvMov)

mx := mux.NewRouter()
router.SetupCsrf(mx)
router.ActivateMiddlewares(mx)
router.SetupAuth(delAuth, mx)
router.SetupMovie(delMov, mx)
Expand Down
45 changes: 25 additions & 20 deletions internal/app/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,33 @@ type Collection struct {
}

type MovieInfo struct {
Id int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
CardUrl string `json:"card_url"`
AlbumUrl string `json:"album_url"`
Rating float32 `json:"rating"`
ReleaseDate time.Time `json:"release_date"`
MovieType string `json:"movie_type"`
Country string `json:"country"`
VideoUrl string `json:"video_url"`
Actors []*ActorInfo `json:"actors_info"`
Id int `json:"id"`
Title string `json:"title"`
ShortDescription string `json:"short_description"`
FullDescription string `json:"full_description"`
CardUrl string `json:"card_url"`
AlbumUrl string `json:"album_url"`
TitleUrl string `json:"title_url"`
Rating float32 `json:"rating"`
ReleaseDate time.Time `json:"release_date"`
MovieType string `json:"movie_type"`
Country string `json:"country"`
VideoUrl string `json:"video_url"`
Actors []*StaffInfo `json:"actors_info"`
Directors []*StaffInfo `json:"directors_info"`
}

type ActorInfo struct {
Id int `json:"id"`
Name string `json:"name"`
Surname string `json:"surname"`
Patronymic string `json:"patronymic"`
Biography string `json:"biography"`
Birthdate sql.NullTime `json:"birthdate"`
PhotoUrl string `json:"photo_url"`
Country string `json:"country"`
type StaffInfo struct {
Id int `json:"id"`
Name string `json:"name"`
Surname string `json:"surname"`
Patronymic string `json:"patronymic"`
Biography string `json:"biography"`
Post string `json:"post"`
Birthdate sql.NullTime `json:"birthdate"`
SmallPhotoUrl string `json:"small_photo_url"`
BigPhotoUrl string `json:"big_photo_url"`
Country string `json:"country"`
}

type CookieData struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/movie/delivery/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
type MovieServiceInterface interface {
GetCollection(ctx context.Context) (*models.CollectionsRespData, *models.ErrorRespData)
GetMovie(ctx context.Context, mvId int) (*models.MovieInfo, *models.ErrorRespData)
GetActor(ctx context.Context, actorId int) (*models.ActorInfo, *models.ErrorRespData)
GetActor(ctx context.Context, actorId int) (*models.StaffInfo, *models.ErrorRespData)
}
Loading