package au.gov.ga.geodesy.interfaces.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.PersistentEntityResource;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import au.gov.ga.geodesy.domain.model.SetupRepository;

@RepositoryRestController
@RequestMapping("/setups")
public class SetupEndpoint {

    @Autowired
    private SetupRepository setups;

    @RequestMapping(value = "/search/findCurrentBySiteId", method = RequestMethod.GET, produces = "application/hal+json")
    @Transactional("geodesyTransactionManager")
    @ResponseBody
    public PersistentEntityResource findCurrentBySiteId(Integer siteId, PersistentEntityResourceAssembler assembler) {
        return assembler.toResource(setups.findCurrentBySiteId(siteId));
    }
}

@@ -37,16 +37,45 @@
 .rest;%0A%0A
+import java.util.ArrayList;%0A%0A
 import o
@@ -129,16 +129,159 @@
 owired;%0A
+import org.springframework.data.domain.Page;%0Aimport org.springframework.data.domain.PageImpl;%0Aimport org.springframework.data.domain.Pageable;%0A
 import o
@@ -487,24 +487,318 @@
 Controller;%0A
+import org.springframework.data.web.PagedResourcesAssembler;%0Aimport org.springframework.hateoas.PagedResources;%0Aimport org.springframework.hateoas.Resource;%0Aimport org.springframework.http.HttpHeaders;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0A
 import org.s
@@ -1037,16 +1037,175 @@
 eBody;%0A%0A
+import au.gov.ga.geodesy.domain.model.GnssCorsSite;%0Aimport au.gov.ga.geodesy.domain.model.GnssCorsSiteRepository;%0Aimport au.gov.ga.geodesy.domain.model.Setup;%0A
 import a
@@ -1385,16 +1385,148 @@
  setups;
+%0A    %0A    @Autowired%0A    private GnssCorsSiteRepository sites;%0A%0A    @Autowired%0A    private PagedResourcesAssembler%3CSetup%3E assembler;
 %0A%0A    @R
@@ -1605,16 +1605,28 @@
 hod.GET,
+%0A           
  produce
@@ -1916,11 +1916,719 @@
 );%0A    %7D
+%0A%0A    @RequestMapping(value = %22/search/findByFourCharacterId%22, method = RequestMethod.GET,%0A            produces = %22application/hal+json%22)%0A    public ResponseEntity%3CPagedResources%3CResource%3CSetup%3E%3E%3E findByFourCharacterId(%0A            String id, Pageable pageRequest) %7B%0A%0A        Page%3CSetup%3E page = null;%0A        GnssCorsSite site = sites.findByFourCharacterId(id);%0A%0A        if (site != null) %7B%0A            page = setups.findBySiteId(site.getId(), pageRequest);%0A        %7D else %7B%0A            page = new PageImpl%3CSetup%3E(new ArrayList%3CSetup%3E());%0A        %7D%0A        PagedResources%3CResource%3CSetup%3E%3E paged = assembler.toResource(page);%0A        return new ResponseEntity%3C%3E(paged, new HttpHeaders(), HttpStatus.OK);%0A    %7D
 %0A%7D%0A

Add /setups/search/findByFourCharacterId.