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

11 implement the api for registeruser with smartphone #147

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
3e9c86d
feat(backend): configure web security to disable cross sight request …
nancymuyeh Jun 12, 2024
604891d
feat(backend): Implement RESTAPI for user registration
nancymuyeh Jun 12, 2024
8f891a7
Merge branch 'ADORSYS-GIS:main' into 11-implement-the-api-for-registe…
nancymuyeh Jun 13, 2024
51a0b38
feat(backend): Implemented integration test for user registration API
mbunwe-victor Jun 17, 2024
a28d1b6
Merge branch '11-implement-the-api-for-registeruser-with-smartphone' …
mbunwe-victor Jun 17, 2024
1f91de7
Merge branch 'main' into 11-implement-the-api-for-registeruser-with-s…
nancymuyeh Jun 20, 2024
28ea447
Merge branch '11-implement-the-api-for-registeruser-with-smartphone' …
nancymuyeh Jun 20, 2024
a65f3b0
fix(backend): added annotation to make procedure table be created in …
nancymuyeh Jun 21, 2024
62f4926
refactor(backend): refactored user registration-related files
nancymuyeh Jun 21, 2024
b74d9f2
Update: updated the UserRegistrationIntegrationTest file
mbunwe-victor Jun 22, 2024
27cc785
Merge branch '11-implement-the-api-for-registeruser-with-smartphone' …
mbunwe-victor Jun 22, 2024
a331b7d
Merge branch 'ADORSYS-GIS:main' into 11-implement-the-api-for-registe…
mbunwe-victor Jun 22, 2024
3e52f4f
refactor(backend): migrated from http ResponseEntity to springs Respo…
nancymuyeh Jun 22, 2024
9b6f7db
feat(User registration) : catch user exist error to make sure no two …
nancymuyeh Jun 22, 2024
9be66f2
feat(User registration) : Implement otp check for phone number valida…
nancymuyeh Jun 30, 2024
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
nancymuyeh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.adorsys.gis.powerpay.powerpaybackend.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@EnableMethodSecurity(prePostEnabled = true)
@Configuration
public class WebSecurityConfig {


@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
http
.csrf((csrf) -> csrf.disable())
.authorizeHttpRequests((authorize) -> authorize.requestMatchers(HttpMethod.POST, "/**").permitAll()
.requestMatchers("/**").permitAll()
.anyRequest().authenticated());

return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.adorsys.gis.powerpay.powerpaybackend.services;

import com.adorsys.gis.powerpay.powerpaybackend.domain.User;
import com.adorsys.gis.powerpay.powerpaybackend.domain.UserRegistration;
import jakarta.validation.Valid;
import lombok.Getter;
import lombok.Setter;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/registration")
public class userRegistrationController {
nancymuyeh marked this conversation as resolved.
Show resolved Hide resolved
nancymuyeh marked this conversation as resolved.
Show resolved Hide resolved
private final UserRegistrationService userRegistrationService;

public userRegistrationController(UserRegistrationService userRegistrationService) {
this.userRegistrationService = userRegistrationService;
}
Motouom marked this conversation as resolved.
Show resolved Hide resolved

@PostMapping
public ResponseEntity<Object> registerUser(@RequestBody @Valid RegistrationRequest registrationRequest) {
UserRegistration userRegistration = userRegistrationService.createProcedure(registrationRequest.getPhoneNumber(), registrationRequest.getUserName());
return new ResponseEntity<>(userRegistration, HttpStatus.CREATED);
}

@PostMapping("/{registrationId}")
public ResponseEntity<Object> completeRegistration(@PathVariable("registrationId") Integer registrationId, @RequestBody @Valid CompletionRequest completionRequest) {
User user = userRegistrationService.registerUser(registrationId, completionRequest.getPin(), completionRequest.getOtp());
return new ResponseEntity<>(user, HttpStatus.CREATED);
}

// Define request bodies for endpoints
@Getter
@Setter
public
static class RegistrationRequest {
private String phoneNumber;
private String userName;


}
@Getter
@Setter
public
static class CompletionRequest {
private String pin;
private String otp;

}
Motouom marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.adorsys.gis.powerpay.powerpaybackend.services_tests;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.adorsys.gis.powerpay.powerpaybackend.services.userRegistrationController.CompletionRequest;
import com.adorsys.gis.powerpay.powerpaybackend.services.userRegistrationController.RegistrationRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest
@AutoConfigureMockMvc
public class UserRegistrationIntegrationTest {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@Test
public void testRegisterUser() throws Exception {
RegistrationRequest request = new RegistrationRequest();
request.setPhoneNumber("1234567890");
request.setUserName("testuser");

mockMvc.perform(post("/api/registration")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.phoneNumber").value("1234567890"))
.andExpect(jsonPath("$.userName").value("testuser"));
}

@Test
public void testCompleteRegistration() throws Exception {
// Register a user
RegistrationRequest registrationRequest = new RegistrationRequest();
registrationRequest.setPhoneNumber("1234567890");
registrationRequest.setUserName("testuser");

mockMvc.perform(post("/api/registration")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(registrationRequest)))
.andExpect(status().isCreated())
.andReturn()
.getResponse()
.getContentAsString();

// Complete the registration
CompletionRequest completionRequest = new CompletionRequest();
completionRequest.setPin("1234");
completionRequest.setOtp("5678");

mockMvc.perform(post("/api/registration/{registrationId}", 1) // Assuming registrationId is 1
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(completionRequest)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.phoneNumber").value("1234567890"))
.andExpect(jsonPath("$.userName").value("testuser"));
}
}