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

feat: added avatar admin controller #72

Merged
merged 4 commits into from
Oct 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ h| Version
| onecx-permissions

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-permissions.html[Link]
| https://github.com/onecx/onecx-quarkus/blob/0.33.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link]
| 0.33.0
| https://github.com/onecx/onecx-quarkus/blob/0.34.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link]
| 0.34.0

| quarkus-oidc

Expand All @@ -108,7 +108,7 @@ h| Version

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.33.0
| 0.34.0

| quarkus-micrometer-registry-prometheus

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.tkit.onecx.user.profile.bff.rs.controllers;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.onecx.user.profile.bff.rs.mappers.ExceptionMapper;
import org.tkit.onecx.user.profile.bff.rs.mappers.UserProfileMapper;
import org.tkit.quarkus.log.cdi.LogService;

import gen.org.tkit.onecx.image.bff.clients.api.AvatarInternalApi;
import gen.org.tkit.onecx.image.bff.clients.model.ImageInfo;
import gen.org.tkit.onecx.user.profile.bff.rs.internal.UserAvatarAdminApiService;
import gen.org.tkit.onecx.user.profile.bff.rs.internal.model.RefTypeDTO;

@ApplicationScoped
@Transactional(value = Transactional.TxType.NOT_SUPPORTED)
@LogService
public class UserAvatarAdminRestController implements UserAvatarAdminApiService {

@Inject
HttpHeaders headers;

@Inject
ExceptionMapper exceptionMapper;

@Inject
UserProfileMapper mapper;

@Inject
@RestClient
AvatarInternalApi client;

@ServerExceptionMapper
public Response restException(WebApplicationException ex) {
return exceptionMapper.restException(ex);
}

@Override
public Response deleteUserAvatarById(String id) {
try (Response response = client.deleteImage(id)) {
return Response.status(response.getStatus()).build();
}
}

@Override
public Response getUserAvatarById(String id, RefTypeDTO refType) {
Response.ResponseBuilder responseBuilder = null;
try (Response response = client.getImage(id, mapper.map(refType))) {
var contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
var contentLength = response.getHeaderString(HttpHeaders.CONTENT_LENGTH);
var body = response.readEntity(byte[].class);

if (contentType != null && body.length != 0) {
responseBuilder = Response.status(response.getStatus())
.header(HttpHeaders.CONTENT_TYPE, contentType)
.header(HttpHeaders.CONTENT_LENGTH, contentLength)
.entity(body);
} else {
responseBuilder = Response.status(Response.Status.BAD_REQUEST);
}

return responseBuilder.build();
}

}

@Override
public Response uploadAvatarById(String id, RefTypeDTO refType, byte[] body) {
try (Response response = client.uploadImage(headers.getLength(), id, mapper.map(refType), body)) {
var imageInfo = response.readEntity(ImageInfo.class);
return Response.status(response.getStatus())
.entity(mapper.map(imageInfo)).build();
}
}
}
87 changes: 87 additions & 0 deletions src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,93 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
/userProfile/{id}/avatar:
get:
x-onecx:
permissions:
userProfile:
- read
tags:
- userAvatarAdmin
description: Get user avatar image
operationId: getUserAvatarById
parameters:
- $ref: '#/components/parameters/id'
- name: refType
in: query
required: true
schema:
$ref: "#/components/schemas/RefType"
responses:
"200":
description: OK
content:
image/*:
schema:
minimum: 1
maximum: 310000
type: string
format: binary
"404":
description: User avatar not found
post:
x-onecx:
permissions:
userProfile:
- write
tags:
- userAvatarAdmin
description: Upload user avatar
operationId: uploadAvatarById
parameters:
- $ref: '#/components/parameters/id'
- name: refType
in: query
required: true
schema:
$ref: "#/components/schemas/RefType"
requestBody:
required: true
content:
'image/*':
schema:
minimum: 1
maximum: 310000
type: string
format: binary
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ImageInfo'
"400":
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
delete:
x-onecx:
permissions:
userProfile:
- delete
tags:
- userAvatarAdmin
description: Delete user's avatar
operationId: deleteUserAvatarById
parameters:
- $ref: '#/components/parameters/id'
responses:
'204':
description: No Content
"400":
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
/userProfiles/search:
post:
x-onecx:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.tkit.onecx.user.profile.bff.rs;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class UserAvatarAdminRestControllerIT extends UserAvatarAdminRestControllerTest {
}
Loading
Loading