Skip to content
Snippets Groups Projects
Commit 093b6149 authored by Ester Vilímková's avatar Ester Vilímková Committed by Dominika Zemanovičová
Browse files

Certificate - Easy fixes from review

parent 24527032
No related branches found
No related tags found
1 merge request!45Certificate - Easy fixes from review
......@@ -10,6 +10,7 @@ import jakarta.validation.constraints.NotNull;
import org.fuseri.model.dto.certificate.CertificateCreateDto;
import org.fuseri.model.dto.certificate.CertificateSimpleDto;
import org.fuseri.modulecertificate.ModuleCertificateApplication;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -42,7 +43,7 @@ public class CertificateController {
* @param certificateCreateDto Dto with data used for generating certificate
* @return certificate file
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Generate certificate",
description = "Generates certificate, saves it into database and returns certificate file.")
@ApiResponses(value = {
......@@ -61,7 +62,7 @@ public class CertificateController {
* @param id ID of certificate to be retrieved
* @return CertificateDto with data of previously generated certificate with specified ID
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Get a certificate by ID", description = "Returns a certificate with the specified ID.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Certificate with the specified ID retrieved successfully."),
......@@ -80,13 +81,13 @@ public class CertificateController {
* @return List of CertificateDto objects with previously generated certificates
* for specified User.
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Get certificates for user", description = "Returns certificates for given user in list.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully retrieved certificates"),
@ApiResponse(responseCode = "500", description = "Internal server error."),
})
@GetMapping("/findForUser")
@GetMapping("/find-for-user")
public ResponseEntity<List<CertificateSimpleDto>> findForUser(@RequestParam Long userId) {
return ResponseEntity.ok(certificateFacade.findByUserId(userId));
}
......@@ -99,7 +100,7 @@ public class CertificateController {
* @return List of CertificateDto objects with previously generated certificates
* for specified User and Course.
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Get certificates for user and course",
description = "Returns certificates for given user and course in list.")
@ApiResponses(value = {
......@@ -107,7 +108,7 @@ public class CertificateController {
@ApiResponse(responseCode = "500", description = "Internal server error."),
@ApiResponse(responseCode = "400", description = "Invalid input."),
})
@GetMapping("/findForUserAndCourse")
@GetMapping("/find-for-user-and-course")
public ResponseEntity<List<CertificateSimpleDto>> findForUserAndCourse(@RequestParam Long userId, @RequestParam Long courseId) {
return ResponseEntity.ok(certificateFacade.findByUserIdAndCourseId(userId, courseId));
}
......@@ -117,7 +118,7 @@ public class CertificateController {
*
* @param id Id of certificate to be deleted.
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Delete a certificate with specified ID", description = "Deletes a certificate with the specified ID.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Certificate with the specified ID deleted successfully."),
......@@ -135,14 +136,14 @@ public class CertificateController {
*
* @return a Result object containing a list of CertificateDto objects and pagination information
*/
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Get certificates in paginated format", description = "Returns certificates in paginated format.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully retrieved paginated certificates"),
@ApiResponse(responseCode = "500", description = "Internal server error.")
})
@GetMapping
public ResponseEntity<Page<CertificateSimpleDto>> findAllCertificates(Pageable pageable) {
public ResponseEntity<Page<CertificateSimpleDto>> findAllCertificates(@ParameterObject Pageable pageable) {
return ResponseEntity.ok(certificateFacade.findAll(pageable));
}
}
......@@ -15,16 +15,15 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
public class AppSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable();
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { httpSecurity.csrf().disable();
httpSecurity.authorizeHttpRequests(x -> x
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
.requestMatchers(HttpMethod.POST, "/certificates/**").hasAuthority("SCOPE_test_1")
.requestMatchers(HttpMethod.DELETE, "/certificates/**").hasAuthority("SCOPE_test_1")
.requestMatchers(HttpMethod.PUT, "/certificates/**").hasAnyAuthority("SCOPE_test_1","SCOPE_test_2")
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/datainitializer").permitAll()
.requestMatchers(HttpMethod.POST, "/certificates/**").hasAnyAuthority( "SCOPE_test_1", "SCOPE_test_2")
.requestMatchers(HttpMethod.GET, "/certificates/**").hasAnyAuthority("SCOPE_test_1")
.requestMatchers(HttpMethod.DELETE, "/certificates/**").hasAnyAuthority("SCOPE_test_1")
.anyRequest().authenticated()
).oauth2ResourceServer(OAuth2ResourceServerConfigurer::opaqueToken)
;
).oauth2ResourceServer(OAuth2ResourceServerConfigurer::opaqueToken);
return httpSecurity.build();
}
}
......@@ -24,7 +24,7 @@ public class DataInitializerController {
this.dataInitializer = dataInitializer;
}
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1", "test_2"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Seed certificate database",
description = "Seeds certificate database. Drops all data first.")
@ApiResponses(value = {
......@@ -36,7 +36,7 @@ public class DataInitializerController {
return ResponseEntity.noContent().build();
}
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME,scopes = {"test_1", "test_2"}),
@Operation(security = @SecurityRequirement(name = ModuleCertificateApplication.SECURITY_SCHEME_NAME),
summary = "Drop certificate database",
description = "Drops all data from certificate database")
@ApiResponses(value = {
......
......@@ -120,7 +120,7 @@ class CertificateControllerTests {
void findCertificatesForUser() throws Exception {
Mockito.when(certificateFacade.findByUserId(ArgumentMatchers.anyLong())).thenReturn(List.of(certificateDto));
mockMvc.perform(get("/certificates/findForUser").param("userId", "0"))
mockMvc.perform(get("/certificates/find-for-user").param("userId", "0"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$").isNotEmpty());
......@@ -129,7 +129,7 @@ class CertificateControllerTests {
@WithMockUser(authorities = {"SCOPE_test_1"})
@Test
void findCertificatesWithoutUserId() throws Exception {
mockMvc.perform(get("/certificates/findForUser"))
mockMvc.perform(get("/certificates/find-for-user"))
.andExpect(status().is5xxServerError());
}
......@@ -140,7 +140,7 @@ class CertificateControllerTests {
ArgumentMatchers.anyLong()))
.thenReturn(List.of(certificateDto));
mockMvc.perform(get("/certificates/findForUserAndCourse")
mockMvc.perform(get("/certificates/find-for-user-and-course")
.param("userId", "0")
.param("courseId", "0"))
.andExpect(status().isOk())
......@@ -151,7 +151,7 @@ class CertificateControllerTests {
@WithMockUser(authorities = {"SCOPE_test_1"})
@Test
void findCertificateIdWithoutUserId() throws Exception {
mockMvc.perform(get("/certificates/findForUserAndCourse")
mockMvc.perform(get("/certificates/find-for-user-and-course")
.param("courseId", "0"))
.andExpect(status().is5xxServerError());
}
......@@ -159,7 +159,7 @@ class CertificateControllerTests {
@WithMockUser(authorities = {"SCOPE_test_1"})
@Test
void findCertificateIdWithoutCourseId() throws Exception {
mockMvc.perform(get("/certificates/findForUserAndCourse")
mockMvc.perform(get("/certificates/find-for-user-and-course")
.param("userId", "0"))
.andExpect(status().is5xxServerError());
}
......@@ -167,7 +167,7 @@ class CertificateControllerTests {
@WithMockUser(authorities = {"SCOPE_test_1"})
@Test
void findCertificateIdWithoutParams() throws Exception {
mockMvc.perform(get("/certificates/findForUserAndCourse"))
mockMvc.perform(get("/certificates/find-for-user-and-course"))
.andExpect(status().is5xxServerError());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment