Skip to content

Commit

Permalink
feat(app): can retrieve all roles
Browse files Browse the repository at this point in the history
  • Loading branch information
chukitipok committed Jul 5, 2022
1 parent 041feaa commit 0718195
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.sweetiez.api.adapter.delivery.role;

import fr.sweetiez.api.core.roles.Role;
import fr.sweetiez.api.core.roles.RoleService;
import org.springframework.http.ResponseEntity;

import java.util.Collection;

public class RoleEndPoints {

private final RoleService roleService;

public RoleEndPoints(RoleService roleService) {
this.roleService = roleService;
}

public ResponseEntity<Collection<Role>> retrieveAll() {
return roleService.retrieveAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import fr.sweetiez.api.adapter.shared.AccountMapper;
import fr.sweetiez.api.core.authentication.models.Account;
import fr.sweetiez.api.core.authentication.models.Role;
import fr.sweetiez.api.core.roles.Role;
import fr.sweetiez.api.core.authentication.ports.AuthenticationRepository;
import fr.sweetiez.api.infrastructure.repository.accounts.AccountRepository;
import fr.sweetiez.api.infrastructure.repository.accounts.RoleRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.sweetiez.api.adapter.repository.roles;

import fr.sweetiez.api.adapter.shared.RoleMapper;
import fr.sweetiez.api.core.roles.Role;
import fr.sweetiez.api.core.roles.Roles;
import fr.sweetiez.api.infrastructure.repository.accounts.RoleRepository;

import java.util.Collection;

public class RolesAdapter implements Roles {
private final RoleRepository repository;
private final RoleMapper mapper;

public RolesAdapter(RoleRepository roleRepository, RoleMapper roleMapper) {
repository = roleRepository;
mapper = roleMapper;
}

public Collection<Role> findAll() {
return repository.findAll().stream().map(mapper::toDto).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.sweetiez.api.adapter.shared;

import fr.sweetiez.api.core.authentication.models.Account;
import fr.sweetiez.api.core.authentication.models.Role;
import fr.sweetiez.api.core.roles.Role;
import fr.sweetiez.api.infrastructure.repository.accounts.AccountEntity;
import fr.sweetiez.api.infrastructure.repository.accounts.RoleEntity;

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/fr/sweetiez/api/adapter/shared/RoleMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fr.sweetiez.api.adapter.shared;

import fr.sweetiez.api.core.roles.Role;
import fr.sweetiez.api.infrastructure.repository.accounts.RoleEntity;

public class RoleMapper {

public Role toDto(RoleEntity entity) {
return new Role(entity.getId(), entity.getName());
}

public RoleEntity toEntity(Role role) {
return new RoleEntity(role.id(), role.name());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.sweetiez.api.core.authentication.models;

import fr.sweetiez.api.core.roles.Role;

import java.util.Collection;
import java.util.UUID;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.sweetiez.api.core.authentication.ports;

import fr.sweetiez.api.core.authentication.models.Account;
import fr.sweetiez.api.core.authentication.models.Role;
import fr.sweetiez.api.core.roles.Role;

import java.util.Optional;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/fr/sweetiez/api/core/roles/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.sweetiez.api.core.roles;

public record Role(Long id, String name) {}
18 changes: 18 additions & 0 deletions src/main/java/fr/sweetiez/api/core/roles/RoleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.sweetiez.api.core.roles;

import org.springframework.http.ResponseEntity;

import java.util.Collection;

public class RoleService {

private final Roles roles;

public RoleService(Roles roles) {
this.roles = roles;
}

public ResponseEntity<Collection<Role>> retrieveAll() {
return ResponseEntity.ok(roles.findAll());
}
}
7 changes: 7 additions & 0 deletions src/main/java/fr/sweetiez/api/core/roles/Roles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.sweetiez.api.core.roles;

import java.util.Collection;

public interface Roles {
Collection<Role> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import fr.sweetiez.api.adapter.delivery.order.OrderEndPoints;
import fr.sweetiez.api.adapter.delivery.payment.PaymentWebhookEndpoint;
import fr.sweetiez.api.adapter.delivery.report.ReportEndPoints;
import fr.sweetiez.api.adapter.delivery.role.RoleEndPoints;
import fr.sweetiez.api.adapter.delivery.sweet.AdminSweetEndPoints;
import fr.sweetiez.api.adapter.delivery.sweet.SweetEndPoints;
import fr.sweetiez.api.adapter.delivery.tray.AdminTrayEndPoints;
Expand All @@ -39,6 +40,7 @@
import fr.sweetiez.api.adapter.repository.products.tray.TrayReaderAdapter;
import fr.sweetiez.api.adapter.repository.products.tray.TrayWriterAdapter;
import fr.sweetiez.api.adapter.repository.reports.ReportRepositoryAdapter;
import fr.sweetiez.api.adapter.repository.roles.RolesAdapter;
import fr.sweetiez.api.adapter.shared.*;
import fr.sweetiez.api.core.authentication.ports.AuthenticationRepository;
import fr.sweetiez.api.core.authentication.services.AuthenticationService;
Expand Down Expand Up @@ -78,6 +80,8 @@
import fr.sweetiez.api.core.recipes.ports.RecipeWriter;
import fr.sweetiez.api.core.recipes.services.RecipeService;
import fr.sweetiez.api.core.reports.services.ReportService;
import fr.sweetiez.api.core.roles.RoleService;
import fr.sweetiez.api.core.roles.Roles;
import fr.sweetiez.api.infrastructure.app.security.TokenProvider;
import fr.sweetiez.api.infrastructure.notification.email.GmailSender;
import fr.sweetiez.api.infrastructure.payments.StripePaymentService;
Expand Down Expand Up @@ -260,6 +264,11 @@ public StreamingEventMapper streamingEventMapper() {
return new StreamingEventMapper(customerMapper());
}

@Bean
public RoleMapper roleMapper() {
return new RoleMapper();
}

// ADAPTERS
// REPOSITORY ADAPTERS

Expand Down Expand Up @@ -395,6 +404,11 @@ public DashboardReader dashboardReader() {
orderDetailRepository);
}

@Bean
public Roles roles() {
return new RolesAdapter(roleRepository, roleMapper());
}

@Bean
public AccountNotifierAdapter accountNotifierAdapter() {
return new AccountNotifierAdapter(gmailSender());
Expand Down Expand Up @@ -489,7 +503,18 @@ public SpaceService spaceService() {
return new SpaceService(spaces(), animators());
}

@Bean
public RoleService roleService() {
return new RoleService(roles());
}

// END POINTS

@Bean
public RoleEndPoints roleEndPoints() {
return new RoleEndPoints(roleService());
}

@Bean
public StreamingEventEndPoints streamingEventEndPoints() {
return new StreamingEventEndPoints(animators(), streamingEvents(), customerReader());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.sweetiez.api.infrastructure.delivery.roles;

import fr.sweetiez.api.adapter.delivery.role.RoleEndPoints;
import fr.sweetiez.api.core.roles.Role;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

@RestController
public class SpringRoleController {

private final RoleEndPoints roleEndPoints;

public SpringRoleController(RoleEndPoints roleEndPoints) {
this.roleEndPoints = roleEndPoints;
}

@GetMapping("/roles")
public ResponseEntity<Collection<Role>> retrieveAll() {
return roleEndPoints.retrieveAll();
}
}

0 comments on commit 0718195

Please sign in to comment.