feat(customer vue , store service): favorite store 등록 및 취소 로직 추가
- favorite store 등록 및 취소 로직 추가
This commit is contained in:
@@ -41,5 +41,12 @@ export default {
|
||||
},
|
||||
requestStore(storeId) {
|
||||
return axios.get(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL + "/store-service/store/" + storeId);
|
||||
},
|
||||
getFavoriteStoreByStoreId(storeId) {
|
||||
return axios.get(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL + "/store-service/api/customer/favoriteStore/" + storeId);
|
||||
},
|
||||
markStar(storeId) {
|
||||
return axios.patch(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL + "/store-service/api/customer/favoriteStore/" + storeId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,16 +15,69 @@
|
||||
<b>{{store.name}}</b>
|
||||
</v-toolbar-title>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn icon>
|
||||
<v-icon>mdi-magnify</v-icon>
|
||||
<v-btn
|
||||
icon
|
||||
@click="markStar()"
|
||||
>
|
||||
<v-icon
|
||||
:color="favoriteStore.color"
|
||||
>{{ favoriteStore.icon }}</v-icon>
|
||||
</v-btn>
|
||||
</v-app-bar>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import storeApi from "@/api/store";
|
||||
|
||||
export default {
|
||||
name: "StoreNavigation",
|
||||
props: ["store"],
|
||||
data: function() {
|
||||
return {
|
||||
storeId:-1,
|
||||
favoriteStore:{
|
||||
status:true,
|
||||
color:null,
|
||||
icon: 'mdi-star-outline'
|
||||
}
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
|
||||
markStar:function () {
|
||||
this.changeStarStatus()
|
||||
var vm = this
|
||||
storeApi.markStar(this.storeId)
|
||||
.then(()=>{
|
||||
vm.favoriteStore.status?
|
||||
alert('즐겨찾는 매장에서 제외되었습니다.') : alert('즐겨찾는 매장에 등록되었습니다.')
|
||||
})
|
||||
},
|
||||
getFavoriteStoreByStoreId: function (storeId){
|
||||
var vm = this
|
||||
storeApi.getFavoriteStoreByStoreId(storeId)
|
||||
.then((response)=>{
|
||||
if(response.data.data.exist) vm.changeStarStatus()
|
||||
})
|
||||
},
|
||||
changeStarStatus(){
|
||||
|
||||
if(this.favoriteStore.status){
|
||||
this.favoriteStore.color = "rgb(255, 152, 0)"
|
||||
this.favoriteStore.icon = "mdi-star"
|
||||
}else{
|
||||
this.favoriteStore.color = null
|
||||
this.favoriteStore.icon = "mdi-star-outline"
|
||||
}
|
||||
this.favoriteStore.status= !this.favoriteStore.status
|
||||
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log(this.$route.params)
|
||||
this.storeId =this.$route.params.storeId
|
||||
this.getFavoriteStoreByStoreId(this.storeId)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<v-col >
|
||||
<v-container>
|
||||
<v-text-field
|
||||
readonly
|
||||
v-model="setItem.count"
|
||||
append-outer-icon="mdi-plus"
|
||||
prepend-icon="mdi-minus"
|
||||
@@ -111,7 +112,7 @@ export default {
|
||||
itemOptions:[],
|
||||
},
|
||||
setItem:{
|
||||
count:0,
|
||||
count:1,
|
||||
storeId:-1,
|
||||
itemId:-1,
|
||||
price:0,
|
||||
@@ -145,9 +146,12 @@ export default {
|
||||
},
|
||||
addItemCount: function (v){
|
||||
this.setItem.count =
|
||||
this.setItem.count+v >=0? this.setItem.count+v: 0;
|
||||
this.setItem.count+v >=1? this.setItem.count+v: 1;
|
||||
},
|
||||
addItem: function(){
|
||||
if(!this.validItem())
|
||||
return;
|
||||
|
||||
orderApi.addItemToBasket(this.setItem)
|
||||
.then(response=>{
|
||||
console.log(response)
|
||||
@@ -156,7 +160,16 @@ export default {
|
||||
.catch(error=>{
|
||||
console.log(error.response)
|
||||
})
|
||||
},
|
||||
validItem(){
|
||||
if(this.setItem.count <= 0 || isNaN(this.setItem.count)){
|
||||
alert("수량이 잘못되었습니다.")
|
||||
this.setItem.count =1
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -56,11 +56,6 @@
|
||||
@click="saveOrder"
|
||||
color="primary"
|
||||
>주문하기</v-btn>
|
||||
<!-- <v-btn-->
|
||||
<!-- style="position: absolute; bottom: 0;transform: translateY(-100%); width: 100%"-->
|
||||
<!-- @click="orderItems"-->
|
||||
<!-- >주문하기</v-btn>-->
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -90,6 +85,7 @@ export default {
|
||||
|
||||
orderApi.saveOrder()
|
||||
.then(()=>{
|
||||
this.$emit('plusCount')
|
||||
alert('주문되었습니다.')
|
||||
this.$router.push("/history")
|
||||
})
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.justpickup.storeservice.domain.favoritestore.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GetFavoriteStoreByStoreIdDto {
|
||||
|
||||
private Long userId;
|
||||
private Long storeId;
|
||||
private boolean isExist;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.justpickup.storeservice.domain.favoritestore.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.FavoriteStore;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface FavoriteStoreRepository extends JpaRepository<FavoriteStore,Long> {
|
||||
|
||||
Optional<FavoriteStore> findByUserIdAndStore(Long userId, Store store);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.justpickup.storeservice.domain.favoritestore.service;
|
||||
|
||||
import com.justpickup.storeservice.domain.favoritestore.dto.GetFavoriteStoreByStoreIdDto;
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.FavoriteStore;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.exception.NotExistStoreException;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class FavoriteStoreService {
|
||||
|
||||
private final FavoriteStoreRepository favoriteStoreRepository;
|
||||
private final StoreRepository storeRepository;
|
||||
|
||||
@Transactional
|
||||
public void patchFavoriteStore(Long userId, Long storeId){
|
||||
Store store = storeRepository.findById(storeId)
|
||||
.orElseThrow(()-> new NotExistStoreException("매장이 존재하지않습니다."));
|
||||
|
||||
favoriteStoreRepository
|
||||
.findByUserIdAndStore(userId, store)
|
||||
.ifPresentOrElse(
|
||||
favoriteStoreRepository::delete,
|
||||
()->favoriteStoreRepository.save(FavoriteStore.of(userId, store))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public GetFavoriteStoreByStoreIdDto getFavoriteStoreByStoreId(Long userId, Long storeId){
|
||||
Store store = storeRepository.findById(storeId)
|
||||
.orElseThrow(()-> new NotExistStoreException("매장이 존재하지않습니다."));
|
||||
|
||||
Optional<FavoriteStore> byUserIdAndStore = favoriteStoreRepository
|
||||
.findByUserIdAndStore(userId, store);
|
||||
|
||||
if(byUserIdAndStore.isPresent()){
|
||||
return new GetFavoriteStoreByStoreIdDto(userId,storeId, true);
|
||||
}else {
|
||||
return new GetFavoriteStoreByStoreIdDto(userId,storeId, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.justpickup.storeservice.domain.favoritestore.web;
|
||||
|
||||
import com.justpickup.storeservice.domain.favoritestore.dto.GetFavoriteStoreByStoreIdDto;
|
||||
import com.justpickup.storeservice.domain.favoritestore.service.FavoriteStoreService;
|
||||
import com.justpickup.storeservice.global.dto.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/customer/favoriteStore")
|
||||
public class FavoriteStoreCustomerApiController {
|
||||
|
||||
private final FavoriteStoreService favoriteStoreService;
|
||||
|
||||
@GetMapping("/{storeId}")
|
||||
public ResponseEntity getFavoriteStoreByStoreId(@RequestHeader(value = "user-id") String userId, @PathVariable Long storeId){
|
||||
|
||||
GetFavoriteStoreByStoreIdDto favoriteStoreByStoreId = favoriteStoreService.getFavoriteStoreByStoreId(Long.parseLong(userId), storeId);
|
||||
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.body(Result.createSuccessResult(favoriteStoreByStoreId));
|
||||
}
|
||||
|
||||
|
||||
@PatchMapping("/{storeId}")
|
||||
public ResponseEntity patchFavoriteStore(@RequestHeader(value = "user-id") String userId, @PathVariable Long storeId){
|
||||
|
||||
favoriteStoreService.patchFavoriteStore(Long.parseLong(userId),storeId);
|
||||
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.NO_CONTENT)
|
||||
.body(Result.success());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user