Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .vscode/inote-rest-api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"type": "java",
"name": "Inote API application",
"request": "launch",
"mainClass": "fr.inote.inoteApi.InoteApiApplication",
"mainClass": "fr.inote.inote_api.InoteApiApplication",
"projectName": "InoteApi"

/* Ceci n'est plus utile, tout la configuration pour le runner des test
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

7 changes: 7 additions & 0 deletions requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
@passwordBis = chichi@@YYY14646_
@email = sangoku@kame-house.com

# HELLO !

GET http://localhost:8080/api/hello?user=Truc HTTP/1.1
Accept-Language: en

# USER ACCOUNT
#=================================================================

Expand All @@ -16,6 +21,7 @@
# http://localhost:5000
POST http://localhost:8080/api/auth/register HTTP/1.1
Content-Type: {{contentType}}
Accept-Language: fr

{
"pseudo":"{{pseudo}}",
Expand All @@ -28,6 +34,7 @@ Content-Type: {{contentType}}
# or open fictionous mail box http://localhost:5000 (smtp-dev must be running)
POST http://localhost:8080/api/auth/activation HTTP/1.1
Content-Type: {{contentType}}
Accept-Language: fr

{
"code":"231978"
Expand Down

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/fr/inote/inoteApi/service/CommentService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.inote.inoteApi;
package fr.inote.inote_api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package fr.inote.inoteApi.controller;

import fr.inote.inoteApi.crossCutting.constants.Endpoint;
import fr.inote.inoteApi.crossCutting.exceptions.*;
import fr.inote.inoteApi.crossCutting.constants.MessagesEn;
import fr.inote.inoteApi.crossCutting.security.impl.JwtServiceImpl;
import fr.inote.inoteApi.dto.*;
import fr.inote.inoteApi.entity.User;
import fr.inote.inoteApi.service.impl.UserServiceImpl;
package fr.inote.inote_api.controller;

import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,12 +15,22 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import fr.inote.inote_api.cross_cutting.constants.Endpoint;
import fr.inote.inote_api.cross_cutting.constants.MessagesEn;
import fr.inote.inote_api.cross_cutting.exceptions.*;
import fr.inote.inote_api.cross_cutting.security.impl.JwtServiceImpl;
import fr.inote.inote_api.dto.*;
import fr.inote.inote_api.entity.User;
import fr.inote.inote_api.service.impl.UserServiceImpl;

import java.util.Locale;
import java.util.Map;

import static fr.inote.inoteApi.crossCutting.constants.HttpRequestBody.BEARER;
import static fr.inote.inoteApi.crossCutting.constants.HttpRequestBody.REFRESH;
import static fr.inote.inote_api.cross_cutting.constants.HttpRequestBody.BEARER;
import static fr.inote.inote_api.cross_cutting.constants.HttpRequestBody.REFRESH;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;

Expand Down Expand Up @@ -80,14 +84,17 @@ public class AuthController {
private final AuthenticationManager authenticationManager;
private final UserServiceImpl userService;
private final JwtServiceImpl jwtService;
private final ResourceBundleMessageSource source;

public AuthController(
AuthenticationManager authenticationManager,
UserServiceImpl userService,
JwtServiceImpl jwtService) {
JwtServiceImpl jwtService,
ResourceBundleMessageSource source) {
this.authenticationManager = authenticationManager;
this.userService = userService;
this.jwtService = jwtService;
this.source = source;
}

/* PUBLIC METHODS */
Expand All @@ -111,9 +118,17 @@ public AuthController(
*/

@PostMapping(path = Endpoint.REGISTER)
public ResponseEntity<String> register(@RequestBody RegisterRequestDto registerRequestDto)
throws MailException, InoteExistingEmailException, InoteInvalidEmailException, InoteRoleNotFoundException,
InoteInvalidPasswordFormatException, InoteMailException {
public ResponseEntity<String> register(
@RequestHeader(name = "Accept-Language", required = false)
final Locale locale,
@RequestBody
final RegisterRequestDto registerRequestDto)
throws MailException,
InoteExistingEmailException,
InoteInvalidEmailException,
InoteRoleNotFoundException,
InoteInvalidPasswordFormatException,
InoteMailException {

User userToRegister = User.builder()
.email(registerRequestDto.username())
Expand All @@ -125,7 +140,10 @@ public ResponseEntity<String> register(@RequestBody RegisterRequestDto registerR

return ResponseEntity
.status(HttpStatusCode.valueOf(201))
.body(MessagesEn.ACTIVATION_NEED_ACTIVATION);
.body(source.getMessage(
"activation.ACTIVATION_NEED_ACTIVATION",
null,
locale));
}

/**
Expand All @@ -144,14 +162,23 @@ public ResponseEntity<String> register(@RequestBody RegisterRequestDto registerR
* @date 19-05-2024
*/
@PostMapping(path = Endpoint.ACTIVATION)
public ResponseEntity<String> activation(@RequestBody ActivationRequestDto activationRequestDto)
throws InoteValidationNotFoundException, InoteValidationExpiredException, InoteUserNotFoundException {
public ResponseEntity<String> activation(
@RequestHeader(name = "Accept-Language", required = false)
final Locale locale,
@RequestBody
ActivationRequestDto activationRequestDto)
throws InoteValidationNotFoundException,
InoteValidationExpiredException,
InoteUserNotFoundException {

this.userService.activation(activationRequestDto.code());

return ResponseEntity
.status(OK)
.body(MessagesEn.ACTIVATION_OF_USER_OK);
.body(source.getMessage(
"user.ACTIVATION_OF_USER_OK",
null,
locale));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
package fr.inote.inoteApi.controller;

import fr.inote.inoteApi.crossCutting.constants.Endpoint;
import fr.inote.inoteApi.crossCutting.exceptions.InoteEmptyMessageCommentException;
import fr.inote.inoteApi.crossCutting.security.impl.JwtServiceImpl;
import fr.inote.inoteApi.dto.CommentRequestDto;
import fr.inote.inoteApi.dto.CommentResponseDto;
import fr.inote.inoteApi.entity.Comment;
import fr.inote.inoteApi.service.CommentService;
import fr.inote.inoteApi.service.impl.UserServiceImpl;
package fr.inote.inote_api.controller;

import java.util.List;

Expand All @@ -21,6 +12,15 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import fr.inote.inote_api.cross_cutting.constants.Endpoint;
import fr.inote.inote_api.cross_cutting.exceptions.InoteEmptyMessageCommentException;
import fr.inote.inote_api.cross_cutting.security.impl.JwtServiceImpl;
import fr.inote.inote_api.dto.CommentRequestDto;
import fr.inote.inote_api.dto.CommentResponseDto;
import fr.inote.inote_api.entity.Comment;
import fr.inote.inote_api.service.CommentService;
import fr.inote.inote_api.service.impl.UserServiceImpl;

/**
* Controller for account user routes
*
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/fr/inote/inote_api/controller/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fr.inote.inote_api.controller;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

private final MessageSource source;

public HelloController(MessageSource source){
this.source = source;
}

@GetMapping(path = "/api/hello")
public ResponseEntity<String> hello(
@RequestHeader(name = "Accept-Language", required = false)
final Locale locale,
@RequestParam(name = "user", required = false, defaultValue = "")
final String USER){
return ResponseEntity
.status(HttpStatus.OK)
.header("Content-Type", "text/plain")
.body(source.getMessage("hello", new Object[]{USER}, locale));
}
}
Loading