большая доработка чистоты кода в части бек
This commit is contained in:
@@ -8,86 +8,38 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.kayashov.bar.controller.dto.VisitorResponseDto;
|
||||
import ru.kayashov.bar.controller.dto.bar.BarResponseDto;
|
||||
import ru.kayashov.bar.controller.dto.cocktail.ReceiptResponseDto;
|
||||
import ru.kayashov.bar.model.entity.Category;
|
||||
import ru.kayashov.bar.model.entity.Glass;
|
||||
import ru.kayashov.bar.model.entity.Unit;
|
||||
import ru.kayashov.bar.model.entity.Visitor;
|
||||
import ru.kayashov.bar.repository.UnitRepository;
|
||||
import ru.kayashov.bar.service.SessionService;
|
||||
import ru.kayashov.bar.service.VisitorService;
|
||||
import ru.kayashov.bar.service.BarService;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@CrossOrigin(origins = {"*"})
|
||||
@RestController
|
||||
@RequestMapping("/api/bar/")
|
||||
@RequestMapping("/api/bar")
|
||||
@RequiredArgsConstructor
|
||||
public class BarController {
|
||||
|
||||
private final SessionService sessionService;
|
||||
private final VisitorService visitorService;
|
||||
private final UnitRepository unitRepository;
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/units")
|
||||
public List<Unit> getUnitList() {
|
||||
return unitRepository.findAll();
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/glass")
|
||||
public List<String> getGlass() {
|
||||
return Arrays.stream(Glass.values()).map(Glass::getName).toList();
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/category")
|
||||
public List<String> getCategory() {
|
||||
return Arrays.stream(Category.values()).map(Category::getName).toList();
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/receipt")
|
||||
public List<ReceiptResponseDto> getReceipt(@RequestParam("id") Long id) {
|
||||
return sessionService.getReceiptList(id);
|
||||
}
|
||||
private final BarService barService;
|
||||
|
||||
@PostMapping("/change/{id}")
|
||||
public void changeActiveBar(@PathVariable Long id) {
|
||||
sessionService.changeActiveBar(id);
|
||||
barService.changeActiveBar(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteBar(@PathVariable Long id) {
|
||||
sessionService.deleteBar(id);
|
||||
barService.deleteBar(id);
|
||||
}
|
||||
|
||||
@PostMapping("/{name}")
|
||||
public BarResponseDto createBar(@PathVariable String name) {
|
||||
return sessionService.createBar(name);
|
||||
return barService.createBar(name);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
public List<BarResponseDto> getAll() {
|
||||
return sessionService.findAllBar();
|
||||
}
|
||||
|
||||
@GetMapping("/getMe")
|
||||
public VisitorResponseDto getMe() {
|
||||
Visitor visitor = visitorService.getCurrentVisitor();
|
||||
VisitorResponseDto dto = VisitorResponseDto.mapToDto(visitor, true, visitor.getRole().toString(), true);
|
||||
log.info("Запрос информации о пользователе: {}-{} {}, вошел в бар",
|
||||
dto.getId(),
|
||||
dto.getName().strip(),
|
||||
dto.getLastName() != null ? dto.getLastName().strip() : "");
|
||||
return dto;
|
||||
return barService.findAllBar();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user