Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alba María Álvarez
/
AppRecetas
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
080302b2
authored
Sep 01, 2025
by
Alba María Álvarez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
perf(recipe/controller): añadida ordenación y devolver RecipeListDto
parent
b29e7aa7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
src/main/java/com/example/apprecetas/recipe/infrastructure/controller/ReadRecipeController.java
src/main/java/com/example/apprecetas/recipe/infrastructure/controller/ReadRecipeController.java
View file @
080302b2
package
com
.
example
.
apprecetas
.
recipe
.
infrastructure
.
controller
;
import
com.example.apprecetas.recipe.application.ReadRecipeUseCase
;
import
com.example.apprecetas.recipe.infrastructure.controller.dto.output.RecipeListDto
;
import
com.example.apprecetas.recipe.infrastructure.controller.dto.output.RecipeOutputDto
;
import
com.example.apprecetas.recipe.infrastructure.mapper.RecipeMapper
;
import
com.example.apprecetas.user.application.ReadUserUseCase
;
import
lombok.RequiredArgsConstructor
;
import
org.mapstruct.factory.Mappers
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -20,8 +21,6 @@ public class ReadRecipeController {
private
final
ReadRecipeUseCase
service
;
private
final
ReadUserUseCase
readUserUseCase
;
private
final
RecipeMapper
mapper
=
Mappers
.
getMapper
(
RecipeMapper
.
class
);
@GetMapping
(
"/{id}"
)
...
...
@@ -30,21 +29,25 @@ public class ReadRecipeController {
}
@GetMapping
public
ResponseEntity
<
Page
<
RecipeOutputDto
>>
readAll
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"6"
)
int
size
)
{
Pageable
pageable
=
PageRequest
.
of
(
page
,
size
);
public
ResponseEntity
<
Page
<
RecipeListDto
>>
readAll
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"6"
)
int
size
,
@RequestParam
(
required
=
false
,
defaultValue
=
"DESC"
)
String
sortDirection
)
{
Sort
sort
=
sortDirection
.
equalsIgnoreCase
(
"asc"
)
?
Sort
.
by
(
"createdAt"
).
ascending
()
:
Sort
.
by
(
"createdAt"
).
descending
();
Pageable
pageable
=
PageRequest
.
of
(
page
,
size
,
sort
);
String
userId
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
();
return
ResponseEntity
.
ok
().
body
(
service
.
readAllByUser
(
userId
,
pageable
).
map
(
mapper:
:
map
));
return
ResponseEntity
.
ok
().
body
(
service
.
readAllByUser
(
userId
,
pageable
).
map
(
mapper:
:
map
List
));
}
@GetMapping
(
"/favorites"
)
public
ResponseEntity
<
Page
<
RecipeOutputDto
>>
readFavorites
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"6"
)
int
size
)
{
Pageable
pageable
=
PageRequest
.
of
(
page
,
size
);
public
ResponseEntity
<
Page
<
RecipeListDto
>>
readFavorites
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"6"
)
int
size
,
@RequestParam
(
required
=
false
,
defaultValue
=
"DESC"
)
String
sortDirection
)
{
Sort
sort
=
sortDirection
.
equalsIgnoreCase
(
"asc"
)
?
Sort
.
by
(
"createdAt"
).
ascending
()
:
Sort
.
by
(
"createdAt"
).
descending
();
Pageable
pageable
=
PageRequest
.
of
(
page
,
size
,
sort
);
String
userId
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
();
return
ResponseEntity
.
ok
().
body
(
service
.
readFavoritesByUser
(
userId
,
pageable
).
map
(
mapper:
:
map
));
return
ResponseEntity
.
ok
().
body
(
service
.
readFavoritesByUser
(
userId
,
pageable
).
map
(
mapper:
:
map
List
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment