Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
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
88f01d4a
authored
May 11, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [SeguimientoController]: Añadidas las funciones para la red social
parent
6e80b2d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/SeguimientoController.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/SeguimientoController.java
0 → 100644
View file @
88f01d4a
package
com
.
ujaen
.
tfg
.
mangaffinity
.
rest
;
import
com.ujaen.tfg.mangaffinity.entidades.Usuario
;
import
com.ujaen.tfg.mangaffinity.excepciones.SeguimientoExiste
;
import
com.ujaen.tfg.mangaffinity.excepciones.SeguimientoNoExiste
;
import
com.ujaen.tfg.mangaffinity.excepciones.UsuarioNoExiste
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTOUsuario
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.Mapper
;
import
com.ujaen.tfg.mangaffinity.servicios.ServicioSeguimiento
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"/seguimientos"
)
public
class
SeguimientoController
{
@Autowired
private
ServicioSeguimiento
servicioSeguimientos
;
@Autowired
private
Mapper
mapper
;
/**
* Permite a un usuario seguir a otro.
*/
@PostMapping
(
"/{nombreSeguido}"
)
public
ResponseEntity
<?>
seguir
(
@RequestHeader
(
"nombreUsuario"
)
String
nombreSeguidor
,
@PathVariable
String
nombreSeguido
)
{
try
{
servicioSeguimientos
.
seguir
(
nombreSeguidor
,
nombreSeguido
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
build
();
}
catch
(
SeguimientoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
CONFLICT
).
build
();
}
catch
(
UsuarioNoExiste
|
IllegalArgumentException
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
/**
* Permite dejar de seguir a un usuario.
*/
@DeleteMapping
(
"/{nombreSeguido}"
)
public
ResponseEntity
<?>
dejarDeSeguir
(
@RequestHeader
(
"nombreUsuario"
)
String
nombreSeguidor
,
@PathVariable
String
nombreSeguido
)
{
try
{
servicioSeguimientos
.
dejarDeSeguir
(
nombreSeguidor
,
nombreSeguido
);
return
ResponseEntity
.
noContent
().
build
();
}
catch
(
SeguimientoNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
catch
(
UsuarioNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
/**
* Lista de usuarios que sigue un usuario.
*/
@GetMapping
(
"/seguidos/{nombreUsuario}"
)
public
ResponseEntity
<
List
<
DTOUsuario
>>
obtenerSeguidos
(
@PathVariable
String
nombreUsuario
)
{
try
{
List
<
Usuario
>
seguidos
=
servicioSeguimientos
.
obtenerSeguidos
(
nombreUsuario
);
List
<
DTOUsuario
>
dto
=
seguidos
.
stream
().
map
(
mapper:
:
dto
).
collect
(
Collectors
.
toList
());
return
ResponseEntity
.
ok
(
dto
);
}
catch
(
UsuarioNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
}
/**
* Lista de seguidores de un usuario.
*/
@GetMapping
(
"/seguidores/{nombreUsuario}"
)
public
ResponseEntity
<
List
<
DTOUsuario
>>
obtenerSeguidores
(
@PathVariable
String
nombreUsuario
)
{
try
{
List
<
Usuario
>
seguidores
=
servicioSeguimientos
.
obtenerSeguidores
(
nombreUsuario
);
List
<
DTOUsuario
>
dto
=
seguidores
.
stream
().
map
(
mapper:
:
dto
).
collect
(
Collectors
.
toList
());
return
ResponseEntity
.
ok
(
dto
);
}
catch
(
UsuarioNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
}
/**
* Verifica si un usuario sigue a otro.
*/
@GetMapping
(
"/existe"
)
public
ResponseEntity
<
Boolean
>
estaSiguiendo
(
@RequestParam
String
seguidor
,
@RequestParam
String
seguido
)
{
try
{
boolean
resultado
=
servicioSeguimientos
.
estaSiguiendo
(
seguidor
,
seguido
);
return
ResponseEntity
.
ok
(
resultado
);
}
catch
(
UsuarioNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
}
}
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