All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.brihaspathee.zeus.web.resource.impl.FileAPIImpl Maven / Gradle / Ivy

package com.brihaspathee.zeus.web.resource.impl;

import com.brihaspathee.zeus.constants.ApiResponseConstants;
import com.brihaspathee.zeus.dto.transaction.FileDetailDto;
import com.brihaspathee.zeus.services.interfaces.FileStorageService;
import com.brihaspathee.zeus.web.model.FileResponseDto;
import com.brihaspathee.zeus.web.resource.interfaces.FileAPI;
import com.brihaspathee.zeus.web.response.ZeusApiResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * Created in Intellij IDEA
 * User: Balaji Varadharajan
 * Date: 06, March 2022
 * Time: 4:57 PM
 * Project: Zeus
 * Package Name: com.brihaspathee.zeus.web.resource.impl
 * To change this template use File | Settings | File and Code Template
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class FileAPIImpl implements FileAPI {

    /**
     * Service that contains the methods to store and retrieve the details of the file
     */
    private final FileStorageService fileStorageService;

    /**
     * Method to get the details of the file by file id
     * @param fileId
     * @return
     */
    @Override
    public ResponseEntity> getFileDetail(String fileId) {
        FileDetailDto fileDetailDto = FileDetailDto.builder().fileName("Test").build();
        ZeusApiResponse apiResponse = ZeusApiResponse.builder()
                .response(fileDetailDto)
                .build();
        return ResponseEntity.ok(apiResponse);
    }

    /**
     * The method that is invoked to receive the file information from file management service
     * @param fileDetailDto
     * @return
     * @throws JsonProcessingException
     */
    @Override
    public ResponseEntity> postFileDetails(FileDetailDto fileDetailDto)
            throws JsonProcessingException {
        log.info("Got the file details:{}", fileDetailDto);
        FileResponseDto fileResponseDto = fileStorageService.saveFileDetail(fileDetailDto);
        ZeusApiResponse apiResponse = ZeusApiResponse.builder()
                .response(fileResponseDto)
                .message(ApiResponseConstants.SUCCESS)
                .status(HttpStatus.CREATED)
                .statusCode(201)
                .build();
        return new ResponseEntity<>(apiResponse, HttpStatus.CREATED);
    }

    /**
     * Clean up the entire db
     * @return
     */
    @Override
    public ResponseEntity> cleanUp() {
        fileStorageService.deleteAll();
        ZeusApiResponse apiResponse = ZeusApiResponse.builder()
                .response("Request deleted successfully")
                .statusCode(204)
                .status(HttpStatus.NO_CONTENT)
                .developerMessage(ApiResponseConstants.SUCCESS)
                .message(ApiResponseConstants.SUCCESS_REASON)
                .timestamp(LocalDateTime.now())
                .build();
        return new ResponseEntity<>(apiResponse, HttpStatus.NO_CONTENT);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy