The delete operation in JPA may respond with a 200 status code, however, it might fail

I have encountered an issue while testing my JPA delete method using Postman. Although the test returns a 200 response, it fails to actually delete records from my database.

Repository:

@Repository
public interface TeamUserRepository extends JpaRepository<TeamUser, Long> {
    void deleteByUserId(Integer userId);
}

Service:

public void removeTeamUser(Integer userId) {
    teamUserRepository.deleteByUserId(userId);
}

Controller:

@DeleteMapping(value = "/{teamId}/users/{userId}")
public void removeUserFromTeam(Integer userId) {
    teamService.removeTeamUser(userId);
}

Typescript:

export const removeUserFromTeam = (teamId: number | string, userId: number | string) =>
    axios.delete(`http://localhost:8080/api/v1/team/${teamId}/users/${userId}`)

Answer №1

To ensure the userId is null, no delete operation is necessary.

Make sure to connect the Path Parameters to the method parameters.

In the Controller, update

@DeleteMapping(value = "/{teamId}/users/{userId}")
public void removeUserFromTeam(Integer userId) {
    teamService.removeTeamUser(userId);
}

to

@DeleteMapping(value = "/{teamId}/users/{userId}")
public void removeUserFromTeam(@PathVariable("teamId") Integer teamId, @PathVariable("userId") Integer userId) {
    teamService.removeTeamUser(userId);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The problem with Android's convertView.getTag() method

public View getItemView(int position, View convertView, ViewGroup parent) { ViewHolder newsViewHolder = null; ViewHolder2 imageViewHolder = null; ViewHolder3 speakViewHolder = null; int itemType = getItem(position).getType() ...

What method is more effective: utilizing the removeAll() function with the same arraylist or generating a completely new arraylist?

In my Selenium WebDriver script, I am using an ArrayList to compare elements from two different pages. My question is: which method is more efficient? Is it better to use the same ArrayList or create a new one for each comparison? ...

Guide on invoking child components' functions from the parent component in Angular 6

Main Component import { Component } from '@angular/core'; import { DisplayComponent } from './display.component'; @Component({ selector: 'my-app', template: ` <button (click)="submit()">Call Child Com ...

When 'someField' is set to { $exists: true } in Mongoose, the database will retrieve a document even if 'someField' does not currently exist

Something peculiar is occurring with my Typescript code. Here's the snippet I'm running: for await (const expression of Expression.find({'definiton': { $exists: true }})) { console.log(Utils.stringize(expression)) } Despite this, the ...

Locate a particular instance based on the Java thread's name

When initiating threads in my Controller class, I want to first ensure that MyClass run() has been initiated previously. If it has been started, I need to locate the specific instance of MyClass that is currently running. This is because other classes may ...

Error Message: Angular Typescript: x function is not defined

UPDATE: Huge shoutout to everyone who caught my mistake with the code location... Haha I've been wrestling with this issue all day long - the button should trigger the menu to open and switch to "close menu" after displaying a list of 3 items. The co ...

Identifying imports from a barrel file (index.ts) using code analysis

Can anyone help me understand how the Typescript compiler works? I am trying to write a script that will parse each typescript file, search for import declarations, and if an import declaration is using a barrel-file script, it should display a message. Af ...

Extracting rows from a QueryResult array in Postgres: A comprehensive guide

I have received my database response in the form of an array after executing two queries. I want to extract the rows from the result that contain Objects. How can I accomplish this task? Alternatively, is there a different approach to retrieve the data ac ...

The 'toDataURL' property is not recognized on the 'HTMLElement' type

Hey there! I'm new to TypeScript and I've been experimenting with generating barcodes in a canvas using JSBarcode and then adding it to JSpdf as an image using the addImage function. However, I keep encountering the error mentioned above. barcod ...

When attempting to convert an image into a PDF, an exception is triggered

Issue Encountered: ClientAbortException: java.net.SocketException: Broken pipe at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:319) at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:288) at org.apache.catalina. ...

What is causing Next JS to display the message "Error: Connection closed. at e.exports.emit (node:events:530:35)" following a button click event?

Whenever I press one of the buttons in the Next.js component, instead of running the callback function passed to it, an error is sent to the output. I suspect there might be an issue with one of the three components. One of them is the UserPostControls co ...

Manage thrown errors using http.post().subscribe()

There is a backend API for logging in with the possibility of returning a 401 Unauthorized error if the password provided is incorrect. I am wondering how to effectively manage and handle exceptions raised in Angular when interacting with this API. this.h ...

Experiencing an abundance of issues with html-webpack-plugin while incorporating TypeScript

I am working on a project that involves using Webpack and TypeScript. However, when attempting to run the development server, I encountered numerous errors related to the html-webpack-plugin. This is a snippet of the output: > [email protected] dev ...

Personalized lucene scoring - Multiplication of field significance and query significance

I am interested in utilizing Lucene with a unique scoring logic where I assign a score/weight to each field during indexing and each query term during querying. It is important to note that there will never be multiple instances of the same field in eithe ...

Extent Report now displays relevant information based on the latest test, without mixing up categories

Is there a way to prevent overwriting the last category in my Extent Report when running multiple test classes with TestNG? In the following method, which is executed in the @BeforeMethod annotation, I initialize my tests: private void setupReportBeforeT ...

Guide on invoking JNA from VB.net for a ByRef String function

Is it possible to invoke a vb.net function that accepts ByRef parameters and Strings from Java? The vb.net dll has been created using UnmanagedExports. //java String[] str = {"testJavaWrited"}; String[] str2 = {"testJavaWrited2"}; final VbWrapper wr = (V ...

How to retrieve the value of a selected item in primeng using p-dropdown and angular

Encountering an issue when trying to send the selected item value while iterating over an array of strings like: "BMW", "FERRARI", "AUDI", "BENTLY" Here is the structure of my HTML: <p-dropdown optionLabel="type" [options]="cars" formControlName="name" ...

"Journey through the elements, yet encounter the ConcurrentModificationException

Hey team, I'm currently facing an issue with ConcurrentModificationException and I'm having trouble resolving it because I can't pinpoint where I might be modifying the list while iterating through it... Any suggestions?? The problem seems ...

Guide to setting up a Cordova and TypeScript project using the command line interface

For my mobile application development, I rely on Cordova and execute cordova create MyApp in the command-line to initiate a new project. I am familiar with JavaScript but now require TypeScript for my project. Please assist me in setting up a Cordova pro ...

Store the filereader output in a variable for future reference

I am struggling to find a simple answer, even though my code is simple. I attempted the following approach, but every time I try to console.log my testResult, it always returns null. How can I correctly save data from a file? public getFile( sourceFile ...