trying to fix a broken repository

need to fix a broken repository and everything is broken can t use my own but would start all over again if i could right now i have a 500 error related to the orders
3 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @timo! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Timo
TimoOP10mo ago
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Order } from "../models/order.model";

@Injectable({
providedIn: 'root'
})
export class OrderService{
constructor(private http: HttpClient) {}

public getOrderHistory() {
return this.http.get<Order[]>('api/order/history')
}
}
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Order } from "../models/order.model";

@Injectable({
providedIn: 'root'
})
export class OrderService{
constructor(private http: HttpClient) {}

public getOrderHistory() {
return this.http.get<Order[]>('api/order/history')
}
}
package com.example.todoappdeel3.controller;


import com.example.todoappdeel3.dto.OrderDTO;
import com.example.todoappdeel3.models.CustomUser;
import com.example.todoappdeel3.models.Order;
import com.example.todoappdeel3.repository.OrderService;
import com.example.todoappdeel3.services.OrderServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService, OrderServiceImpl orderServiceImpl) {
this.orderService = orderService;
this.orderServiceImpl = orderServiceImpl;
}

private final OrderServiceImpl orderServiceImpl;

@PostMapping
public Order placeOrder(@RequestBody OrderDTO orderDTO) {
return orderService.placeOrder(orderDTO);
}

@GetMapping("/history")
public ResponseEntity<List<Order>> getOrderHistory(@AuthenticationPrincipal CustomUser customUser) {
Long userId = customUser.getId();
List<Order> orders = orderService.findOrdersByCustomUserId(userId);
if (orders.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(orders, HttpStatus.OK);
}
}
package com.example.todoappdeel3.controller;


import com.example.todoappdeel3.dto.OrderDTO;
import com.example.todoappdeel3.models.CustomUser;
import com.example.todoappdeel3.models.Order;
import com.example.todoappdeel3.repository.OrderService;
import com.example.todoappdeel3.services.OrderServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService, OrderServiceImpl orderServiceImpl) {
this.orderService = orderService;
this.orderServiceImpl = orderServiceImpl;
}

private final OrderServiceImpl orderServiceImpl;

@PostMapping
public Order placeOrder(@RequestBody OrderDTO orderDTO) {
return orderService.placeOrder(orderDTO);
}

@GetMapping("/history")
public ResponseEntity<List<Order>> getOrderHistory(@AuthenticationPrincipal CustomUser customUser) {
Long userId = customUser.getId();
List<Order> orders = orderService.findOrdersByCustomUserId(userId);
if (orders.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(orders, HttpStatus.OK);
}
}
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?