-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from nck974/item-location
Item location
- Loading branch information
Showing
73 changed files
with
4,641 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
diogenes/src/main/java/dev/nichoko/diogenes/controller/LocationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dev.nichoko.diogenes.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import dev.nichoko.diogenes.model.LocationSummary; | ||
import dev.nichoko.diogenes.model.domain.Location; | ||
import dev.nichoko.diogenes.service.LocationService; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/locations") | ||
public class LocationController { | ||
private LocationService locationService; | ||
|
||
@Autowired | ||
public LocationController(LocationService locationService) { | ||
this.locationService = locationService; | ||
} | ||
|
||
@PostMapping("/") | ||
public ResponseEntity<Location> createLocation(@Valid @RequestBody Location location) { | ||
Location createdLocation = locationService.createLocation(location); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(createdLocation); | ||
} | ||
|
||
@GetMapping("/") | ||
public ResponseEntity<List<Location>> getAllLocations() { | ||
return ResponseEntity | ||
.ok(locationService.getAllLocations()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<Location> getLocationById(@Valid @PathVariable int id) { | ||
return ResponseEntity.ok(locationService.getLocationById(id)); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Location> updateLocation(@Valid @RequestBody Location updateLocation, @PathVariable int id) { | ||
return ResponseEntity.ok().body(locationService.updateLocation(id, updateLocation)); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Object> deleteLocation(@Valid @PathVariable int id) { | ||
locationService.deleteLocation(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@GetMapping("/summary") | ||
public ResponseEntity<List<LocationSummary>> getLocationsSummary() { | ||
return ResponseEntity | ||
.ok(locationService.getLocationsSummary()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
diogenes/src/main/java/dev/nichoko/diogenes/exception/InvalidLocationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.nichoko.diogenes.exception; | ||
|
||
public class InvalidLocationException extends RuntimeException { | ||
|
||
public InvalidLocationException(int id) { | ||
super("Invalid location with id '" + id + "'."); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
diogenes/src/main/java/dev/nichoko/diogenes/exception/MissingLocationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.nichoko.diogenes.exception; | ||
|
||
public class MissingLocationException extends RuntimeException { | ||
|
||
public MissingLocationException() { | ||
super("An item needs to have a location assigned."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
diogenes/src/main/java/dev/nichoko/diogenes/model/LocationSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.nichoko.diogenes.model; | ||
|
||
import dev.nichoko.diogenes.model.domain.Location; | ||
|
||
public class LocationSummary { | ||
private Location location; | ||
private int itemsNumber; | ||
|
||
public LocationSummary(Location location, int itemsNumber) { | ||
this.location = location; | ||
this.itemsNumber = itemsNumber; | ||
} | ||
|
||
public Location getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(Location location) { | ||
this.location = location; | ||
} | ||
|
||
public int getItemsNumber() { | ||
return itemsNumber; | ||
} | ||
|
||
public void setItemsNumber(int itemsNumber) { | ||
this.itemsNumber = itemsNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.