SearchController to create/edit
This commit is contained in:
parent
b06c322ebb
commit
2dd84a1011
@ -46,4 +46,12 @@ public class Search {
|
|||||||
priceMax = create.getPriceMax();
|
priceMax = create.getPriceMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void edit(final SearchDto edit) {
|
||||||
|
enabled = edit.isEnabled();
|
||||||
|
query = edit.getQuery();
|
||||||
|
radius = edit.getRadius();
|
||||||
|
priceMin = edit.getPriceMin();
|
||||||
|
priceMax = edit.getPriceMax();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
package de.ph87.kleinanzeigen.kleinanzeigen.search;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("Kleinanzeigen/Search")
|
||||||
|
public class SearchController {
|
||||||
|
|
||||||
|
private final SearchService searchService;
|
||||||
|
|
||||||
|
@PostMapping("create")
|
||||||
|
public SearchDto create(@RequestBody SearchCreate create) {
|
||||||
|
return searchService.create(create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("edit")
|
||||||
|
public SearchDto edit(@RequestBody SearchDto edit) {
|
||||||
|
return searchService.edit(edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,8 +3,10 @@ package de.ph87.kleinanzeigen.kleinanzeigen.search;
|
|||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -32,4 +34,18 @@ public class SearchService {
|
|||||||
return new SearchDto(search);
|
return new SearchDto(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchDto create(final SearchCreate create) {
|
||||||
|
final SearchDto dto = toDto(searchRepository.save(new Search(create)));
|
||||||
|
log.info("Search CREATED: {}", dto);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchDto edit(final SearchDto edit) {
|
||||||
|
final Search search = searchRepository.findById(edit.getId()).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));
|
||||||
|
search.edit(edit);
|
||||||
|
final SearchDto dto = toDto(search);
|
||||||
|
log.info("Search EDITED: {}", dto);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user