Added API for getting notifications by compnayId and userId.

This commit is contained in:
piyushkag
2024-12-28 12:19:39 +05:30
parent 5d32e19dd4
commit 8074d5d73d
6 changed files with 48 additions and 3 deletions

View File

@@ -83,6 +83,18 @@ public interface NotificationApi {
ResponseEntity<Response<Void>> deleteNotification(HttpServletRequest request,
@Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id);
@Operation(summary = "API to get notifications by user ID and company ID", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json")
ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,
@Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId,
@Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId);
}

View File

@@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.NotificationEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.model.request.NotificationReq;
import net.gepafin.tendermanagement.model.response.NotificationResponse;
import net.gepafin.tendermanagement.model.util.Response;
@@ -19,8 +18,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/notification}")
public class NotificationApiController implements NotificationApi {
@@ -67,4 +64,11 @@ public class NotificationApiController implements NotificationApi {
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_DELETED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<List<NotificationResponse>>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId) {
List<NotificationResponse> notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY)));
}
}