-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 모든 보관함 조회 api 추가 * feat:보관함 생성 api * feat: 보관함 수정 api 완성 * feat: 보관함 삭제 api * docs: 보관함 crud api 문서화 * fix: signature를 대문자로 비교하기 위해 코드 수정
- Loading branch information
1 parent
8eb301d
commit 8ee8085
Showing
10 changed files
with
411 additions
and
2 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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/upbrella/be/store/controller/LockerController.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,73 @@ | ||
package upbrella.be.store.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import upbrella.be.rent.service.LockerService; | ||
import upbrella.be.store.dto.request.CreateLockerRequest; | ||
import upbrella.be.store.dto.request.UpdateLockerRequest; | ||
import upbrella.be.store.dto.response.AllLockerResponse; | ||
import upbrella.be.util.CustomResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class LockerController { | ||
|
||
private final LockerService lockerService; | ||
|
||
@GetMapping("/admin/lockers") | ||
public ResponseEntity<CustomResponse<AllLockerResponse>> getLockers() { | ||
|
||
AllLockerResponse lockers = lockerService.findAll(); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(new CustomResponse<>( | ||
"success", | ||
200, | ||
"보관함 조회 성공", | ||
lockers)); | ||
} | ||
|
||
@PostMapping("/admin/lockers") | ||
public ResponseEntity<CustomResponse<Void>> createLocker(@RequestBody CreateLockerRequest request) { | ||
|
||
lockerService.createLocker(request); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(new CustomResponse<>( | ||
"success", | ||
200, | ||
"보관함 생성 성공", | ||
null)); | ||
} | ||
|
||
@PatchMapping("/admin/lockers/{lockerId}") | ||
public ResponseEntity<CustomResponse<Void>> updateLocker(@PathVariable Long lockerId, @RequestBody UpdateLockerRequest request) { | ||
|
||
lockerService.updateLocker(lockerId, request); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(new CustomResponse<>( | ||
"success", | ||
200, | ||
"보관함 업데이트 성공", | ||
null)); | ||
} | ||
|
||
@DeleteMapping("/admin/lockers/{lockerId}") | ||
public ResponseEntity<CustomResponse<Void>> deleteLocker(@PathVariable Long lockerId) { | ||
|
||
lockerService.deleteLocker(lockerId); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(new CustomResponse<>( | ||
"success", | ||
200, | ||
"보관함 삭제 성공", | ||
null)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/upbrella/be/store/controller/LockerExceptionHandler.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,21 @@ | ||
package upbrella.be.store.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import upbrella.be.util.CustomErrorResponse; | ||
|
||
@RestControllerAdvice | ||
public class LockerExceptionHandler { | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
public ResponseEntity<CustomErrorResponse> nonExistingStoreDetail(IllegalArgumentException ex) { | ||
|
||
return ResponseEntity | ||
.badRequest() | ||
.body(new CustomErrorResponse( | ||
"bad request", | ||
400, | ||
ex.getMessage())); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/upbrella/be/store/dto/request/CreateLockerRequest.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,16 @@ | ||
package upbrella.be.store.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CreateLockerRequest { | ||
|
||
private long storeId; | ||
private String secretKey; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/upbrella/be/store/dto/request/UpdateLockerRequest.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,16 @@ | ||
package upbrella.be.store.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UpdateLockerRequest { | ||
|
||
private long storeId; | ||
private String secretKey; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/upbrella/be/store/dto/response/AllLockerResponse.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,17 @@ | ||
package upbrella.be.store.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AllLockerResponse { | ||
|
||
private List<SingleLockerResponse> lockers; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/upbrella/be/store/dto/response/SingleLockerResponse.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,27 @@ | ||
package upbrella.be.store.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import upbrella.be.rent.entity.Locker; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SingleLockerResponse { | ||
|
||
private long id; | ||
private long storeMetaId; | ||
private String secretKey; | ||
|
||
public static SingleLockerResponse fromLocker(Locker locker) { | ||
|
||
return SingleLockerResponse.builder() | ||
.id(locker.getId()) | ||
.storeMetaId(locker.getStoreMeta().getId()) | ||
.secretKey(locker.getSecretKey()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.