64 lines
2.8 KiB
Plaintext
64 lines
2.8 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.CompanyProfileDto;
|
|
import com.healthcare.ohctech.entity.CompanyProfile;
|
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
|
import com.healthcare.ohctech.service.impl.CompanyProfileServiceImpl;
|
|
import com.healthcare.ohctech.util.PaginationUtil;
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/company-profiles")
|
|
public class CompanyProfileController {
|
|
|
|
@Autowired
|
|
private CompanyProfileServiceImpl companyProfileServiceImpl;
|
|
|
|
@Autowired
|
|
private AuthServiceImpl authServiceImpl;
|
|
|
|
@GetMapping("/{companyId}")
|
|
public ResponseEntity<?> getCompanyProfileById(@PathVariable Long companyId) {
|
|
CompanyProfile companyProfile = companyProfileServiceImpl.getCompanyProfileById(companyId);
|
|
return new ResponseEntity<>(companyProfile, HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllCompanyProfiles(@RequestParam(required = false) Integer page,
|
|
@RequestParam(required = false) Integer size,
|
|
@RequestParam(required = false) String sortBy,
|
|
@RequestParam(required = false) String sortOrder) {
|
|
Pageable pageable = PaginationUtil.getPageableWithDefaults(page, size, sortBy, sortOrder);
|
|
Page<CompanyProfile> companyProfilePage = companyProfileServiceImpl.getAllCompanyProfiles(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(companyProfilePage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addCompanyProfile(@Valid @RequestBody CompanyProfileDto companyProfileDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
companyProfileServiceImpl.addCompanyProfile(companyProfileDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{companyId}")
|
|
public ResponseEntity<?> updateCompanyProfile(@Valid @RequestBody CompanyProfileDto companyProfileDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
companyProfileServiceImpl.updateCompanyProfile(companyProfileDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{companyId}")
|
|
public ResponseEntity<?> deleteCompanyProfile(@PathVariable Long companyId) {
|
|
companyProfileServiceImpl.deleteCompanyProfile(companyId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
} |