generated from alkemyTech/base-ong-server-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OT276-24] Endpoint datos públicos de la Organización (#26)
* feature done * sin comentarios extras * format code * ultimo cambio pre pull * get organization * cambio requerido * cambio organization * cambio nombre repo * transactional * terminado * todo terminado
- Loading branch information
1 parent
924fb4f
commit d17b87f
Showing
8 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/alkemy/ong/core/usecase/OrganizationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.alkemy.ong.core.usecase; | ||
|
||
import com.alkemy.ong.core.model.Organization; | ||
|
||
public interface OrganizationService { | ||
|
||
Organization getOrganizationEntity(Long id); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/alkemy/ong/core/usecase/impl/OrganizationServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.alkemy.ong.core.usecase.impl; | ||
|
||
import com.alkemy.ong.config.exception.NotFoundException; | ||
import com.alkemy.ong.core.model.Organization; | ||
import com.alkemy.ong.core.repository.OrganizationRepository; | ||
import com.alkemy.ong.core.usecase.OrganizationService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class OrganizationServiceImpl implements OrganizationService { | ||
|
||
private final OrganizationRepository organizationRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public Organization getOrganizationEntity(Long id) { | ||
return organizationRepository.findById(id).orElseThrow(() -> new NotFoundException(id)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/alkemy/ong/ports/input/rs/api/OrganizationApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.alkemy.ong.ports.input.rs.api; | ||
|
||
import com.alkemy.ong.ports.input.rs.response.OrganizationResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Validated | ||
public interface OrganizationApi { | ||
|
||
@Operation(summary = "get Organization", description = "get Organization", responses = { | ||
@ApiResponse(responseCode = "200", description = "Ok") | ||
}) | ||
ResponseEntity<OrganizationResponse> getOrganization(Long id); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/alkemy/ong/ports/input/rs/controller/OrganizationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alkemy.ong.ports.input.rs.controller; | ||
|
||
import com.alkemy.ong.core.model.Organization; | ||
import com.alkemy.ong.core.usecase.OrganizationService; | ||
import com.alkemy.ong.ports.input.rs.api.OrganizationApi; | ||
import com.alkemy.ong.ports.input.rs.mapper.OrganizationControllerMapper; | ||
import com.alkemy.ong.ports.input.rs.response.OrganizationResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import static com.alkemy.ong.ports.input.rs.api.ApiConstants.ORGANIZATIONS_URI; | ||
|
||
@RestController | ||
@RequestMapping(ORGANIZATIONS_URI) | ||
@RequiredArgsConstructor | ||
public class OrganizationController implements OrganizationApi { | ||
|
||
private final OrganizationService organizationService; | ||
|
||
private final OrganizationControllerMapper mapper; | ||
|
||
@Override | ||
@GetMapping("/{id}") | ||
public ResponseEntity<OrganizationResponse> getOrganization(@PathVariable("id") Long id) { | ||
Organization organization = organizationService.getOrganizationEntity(id); | ||
OrganizationResponse organizationResponse = mapper.organizationToOrganizationResponse(organization); | ||
return ResponseEntity.ok(organizationResponse); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/alkemy/ong/ports/input/rs/mapper/OrganizationControllerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.alkemy.ong.ports.input.rs.mapper; | ||
|
||
import com.alkemy.ong.core.model.Organization; | ||
import com.alkemy.ong.ports.input.rs.response.OrganizationResponse; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Named; | ||
|
||
@Mapper | ||
public interface OrganizationControllerMapper extends CommonMapper { | ||
|
||
@Named("organizationToOrganizationResponse") | ||
OrganizationResponse organizationToOrganizationResponse(Organization organization); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/alkemy/ong/ports/input/rs/response/OrganizationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.alkemy.ong.ports.input.rs.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class OrganizationResponse { | ||
|
||
private String name; | ||
private String image; | ||
private int phone; | ||
private String address; | ||
|
||
} |