-
Notifications
You must be signed in to change notification settings - Fork 0
#8 Store CRUD 구현 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
#8 Store CRUD 구현 #12
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
74d2f76
feat(store): Stores 엔티티 클래스 추가 및 create 팩토리 메서드 구현
Jjiggu 664f9c7
feat(store): 스토어 생성 API 엔드포인트 추가
Jjiggu c5de1b1
feat(store): 스토어 생성 요청 DTO 추가 및 엔티티 변환 구현
Jjiggu 933ff8b
feat(store): add StoreRepository interface for data access
Jjiggu ef91f90
feat(store): 스토어 생성 기능 위한 StoreService 인터페이스 추가
Jjiggu 5193c7f
feat(store): 스토어 생성 createStore 구현
Jjiggu 1b590f7
chore(build): configure Gradle plugins and dependencies for Spring Bo…
Jjiggu facf48f
feat: add BaseTimeEntity for auditing createdAt field
Jjiggu 63d1715
feat: add @EnableJpaAuditing for auditing createdAt field
Jjiggu a47ce14
refactor(store): extend Store entity from BaseTimeEntity
Jjiggu 7e90e6e
feat: inherit BaseTimeEntity in StoreCreateRequest dto
Jjiggu af600f2
feat: inherit BaseTimeEntity in StoreCreateResponse dto
Jjiggu 89312e6
feat(store): return saved entity in createStore service method
Jjiggu 47ad3e5
test(store): add unit test for createStore in StoreService
Jjiggu 6f3a056
test(store): add unit test for StoreController
Jjiggu 79e987b
test(store): add unit test for storeRepository
Jjiggu e4faf9d
chore(todo): remove default Todo
Jjiggu b5fb761
refactor(store): add deleted column for soft delete
Jjiggu 40583a2
refactor(store): add deleted column for soft delete
Jjiggu 77a637d
feat(store): add StoreReadDto for store response
Jjiggu 0f8b627
feat(store): add StoreReadResponse for store list response
Jjiggu 4664576
feat(store): add StoreUpdateRequest for store update
Jjiggu dbe9fef
feat(store): add methods to query non-deleted stores in repository
Jjiggu b00d5bc
feat(store): add get, update, delete methods to StoreService interface
Jjiggu 1b4519c
feat(store): implements read, update, and delete methods in StoreServ…
Jjiggu 37b26e1
feat(store): add get, update, delete endpoints to StoreController
Jjiggu e25aa72
fix(store): remove manual setting createdAt for JPA auditing
Jjiggu 6384ffa
refactor(store): remove extends BaseTimeEntity inheritance from Store…
Jjiggu 7ac8913
fix(build): move spring-security-test to testImplementation scope
Jjiggu ca8f67d
refactor(store): rename SetIsDelete to SetDeleted for consistency
Jjiggu b917c71
refactor(store): use EntityNotFoundException instead of NotFoundExcep…
Jjiggu 005397c
refactor(store): remove deleted filed
Jjiggu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/gtable/global/entity/BaseTimeEntity.java
This file contains hidden or 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,39 @@ | ||
| package com.example.gtable.global.entity; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | ||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.EntityListeners; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| @Getter | ||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| @SuperBuilder | ||
| @NoArgsConstructor | ||
| @Schema(description = "시간 관련 VO") | ||
| public abstract class BaseTimeEntity { | ||
|
|
||
| @CreatedDate | ||
| @Column(updatable = false, name = "created_at") | ||
| @JsonSerialize(using = LocalDateTimeSerializer.class) | ||
| @JsonDeserialize(using = LocalDateTimeDeserializer.class) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| public BaseTimeEntity(LocalDateTime createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
|
|
||
| } |
89 changes: 89 additions & 0 deletions
89
src/main/java/com/example/gtable/store/controller/StoreController.java
This file contains hidden or 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,89 @@ | ||
| package com.example.gtable.store.controller; | ||
|
|
||
| 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.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.example.gtable.global.api.ApiUtils; | ||
| import com.example.gtable.store.dto.StoreCreateRequest; | ||
| import com.example.gtable.store.dto.StoreCreateResponse; | ||
| import com.example.gtable.store.dto.StoreUpdateRequest; | ||
| import com.example.gtable.store.service.StoreService; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/stores") | ||
| @RequiredArgsConstructor | ||
| public class StoreController { | ||
|
|
||
| private final StoreService storeService; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<?> createStore(@Valid @RequestBody StoreCreateRequest request) { | ||
| StoreCreateResponse response = storeService.createStore(request); | ||
|
|
||
| return ResponseEntity | ||
| .status(HttpStatus.CREATED) | ||
| .body( | ||
| ApiUtils.success( | ||
| response | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @GetMapping("/all-stores") | ||
| public ResponseEntity<?> getAllStores() { | ||
| return ResponseEntity | ||
| .status(HttpStatus.OK) | ||
| .body( | ||
| ApiUtils.success( | ||
| storeService.getAllStores() | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @GetMapping("/{storeId}") | ||
| public ResponseEntity<?> getStoreById(@PathVariable Long storeId) { | ||
| return ResponseEntity | ||
| .status(HttpStatus.OK) | ||
| .body( | ||
| ApiUtils.success( | ||
| storeService.getStoreByStoreId(storeId) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @PatchMapping("/{storeId}") | ||
| public ResponseEntity<?> updateStore( | ||
| @PathVariable Long storeId, | ||
| @Valid @RequestBody StoreUpdateRequest request | ||
| ) { | ||
| return ResponseEntity | ||
| .status(HttpStatus.OK) | ||
| .body( | ||
| ApiUtils.success( | ||
| storeService.updateStore(storeId, request) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @DeleteMapping("/{storeId}") | ||
| public ResponseEntity<?> deleteStore(@PathVariable Long storeId) { | ||
| return ResponseEntity | ||
| .ok() | ||
| .body( | ||
| ApiUtils.success( | ||
| storeService.deleteStore(storeId) | ||
| ) | ||
| ); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/example/gtable/store/dto/StoreCreateRequest.java
This file contains hidden or 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,40 @@ | ||
| package com.example.gtable.store.dto; | ||
|
|
||
| import com.example.gtable.global.entity.BaseTimeEntity; | ||
| import com.example.gtable.store.model.Store; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class StoreCreateRequest extends BaseTimeEntity { | ||
Jjiggu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @NotNull | ||
| private Long departmentId; | ||
|
|
||
| @NotBlank | ||
| private String name; | ||
|
|
||
| private String location; | ||
|
|
||
| private String description; | ||
|
|
||
| private String storeImageUrl; | ||
|
|
||
| public Store toEntity() { | ||
| return Store.builder() | ||
| .departmentId(departmentId) | ||
| .name(name) | ||
| .location(location) | ||
| .description(description) | ||
| .storeImageUrl(storeImageUrl) | ||
| .isActive(false) | ||
| .deleted(false) | ||
| .build(); | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
src/main/java/com/example/gtable/store/dto/StoreCreateResponse.java
This file contains hidden or 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,40 @@ | ||
| package com.example.gtable.store.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.example.gtable.global.entity.BaseTimeEntity; | ||
| import com.example.gtable.store.model.Store; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class StoreCreateResponse extends BaseTimeEntity { | ||
|
|
||
| private Long storeId; | ||
| private Long departmentId; | ||
| private String name; | ||
| private String location; | ||
| private String description; | ||
| private String storeImageUrl; | ||
| private Boolean isActive; | ||
| private Boolean deleted; | ||
| private LocalDateTime createdAt; | ||
Jjiggu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static StoreCreateResponse fromEntity(Store store) { | ||
| return StoreCreateResponse.builder() | ||
| .createdAt(store.getCreatedAt()) | ||
| .storeId(store.getStoreId()) | ||
| .departmentId(store.getDepartmentId()) | ||
| .name(store.getName()) | ||
| .location(store.getLocation()) | ||
| .description(store.getDescription()) | ||
| .storeImageUrl(store.getStoreImageUrl()) | ||
| .isActive(store.getIsActive()) | ||
| .deleted(store.getDeleted()) | ||
| .build(); | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/gtable/store/dto/StoreReadDto.java
This file contains hidden or 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,38 @@ | ||
| package com.example.gtable.store.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.example.gtable.store.model.Store; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class StoreReadDto { | ||
| private Long storeId; | ||
| private Long departmentId; | ||
| private String name; | ||
| private String location; | ||
| private String description; | ||
| private String storeImageUrl; | ||
| private Boolean isActive; | ||
| private Boolean deleted; | ||
| private LocalDateTime createdAt; | ||
|
|
||
| public static StoreReadDto fromEntity(Store store) { | ||
| return StoreReadDto.builder() | ||
| .createdAt(store.getCreatedAt()) | ||
| .storeId(store.getStoreId()) | ||
| .departmentId(store.getDepartmentId()) | ||
| .name(store.getName()) | ||
| .location(store.getLocation()) | ||
| .description(store.getDescription()) | ||
| .storeImageUrl(store.getStoreImageUrl()) | ||
| .isActive(store.getIsActive()) | ||
| .deleted(store.getDeleted()) | ||
| .build(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/gtable/store/dto/StoreReadResponse.java
This file contains hidden or 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,23 @@ | ||
| package com.example.gtable.store.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class StoreReadResponse { | ||
|
|
||
| private List<StoreReadDto> storeReadDtos; | ||
| private boolean hasNext; | ||
|
|
||
| public static StoreReadResponse fromEntity(List<StoreReadDto> storeReadDtos, boolean hasNext) { | ||
| return StoreReadResponse.builder() | ||
| .storeReadDtos(storeReadDtos) | ||
| .hasNext(hasNext) | ||
| .build(); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/gtable/store/dto/StoreUpdateRequest.java
This file contains hidden or 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,19 @@ | ||
| package com.example.gtable.store.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| public class StoreUpdateRequest { | ||
| private String name; | ||
| private String location; | ||
| private String description; | ||
| private String storeImageUrl; | ||
| private Boolean isActive; | ||
| private Boolean deleted; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.