Skip to content

Commit a997f11

Browse files
committed
feat: implement auth controller with login and register ops
1 parent 677d3d3 commit a997f11

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package br.com.catalog.controller;
2+
3+
import br.com.catalog.controller.responses.Response;
4+
import br.com.catalog.services.IAuthenticationService;
5+
import br.com.catalog.services.impls.AuthenticationServiceImpl;
6+
import br.com.catalog.services.impls.dtos.AuthenticationDTO;
7+
import br.com.catalog.services.impls.dtos.RegisterDTO;
8+
import br.com.catalog.services.impls.dtos.UserResponseDTO;
9+
import jakarta.validation.Valid;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
18+
@RestController
19+
@RequestMapping("/auth")
20+
public class AuthenticationController {
21+
private final IAuthenticationService<AuthenticationDTO, UserResponseDTO, RegisterDTO> authenticationService;
22+
23+
public AuthenticationController(AuthenticationServiceImpl authenticationServiceImpl) {
24+
this.authenticationService = authenticationServiceImpl;
25+
}
26+
27+
@PostMapping("/login")
28+
public ResponseEntity<Response<String>> login(@RequestBody @Valid AuthenticationDTO dto) {
29+
return ResponseEntity.ok(new Response<>(
30+
HttpStatus.OK.toString(),
31+
"User logged in successfully",
32+
authenticationService.login(dto)));
33+
}
34+
35+
@PostMapping("/register")
36+
public ResponseEntity<Response<UserResponseDTO>> register(@RequestBody @Valid RegisterDTO dto) {
37+
return ResponseEntity.ok(new Response<>(
38+
HttpStatus.CREATED.toString(),
39+
"User created successfully",
40+
authenticationService.register(dto)));
41+
}
42+
}

0 commit comments

Comments
 (0)