본문 바로가기
자기개발/새싹톤_POA

아직도 잘 모르겠는 ...

by 금화맘 2023. 6. 10.

아직도 잘 모르겠다.

jpa를 사용하지만 일단 entity를 스네이크로 만들어서 query만 죽도록 만지고 있지만..

update를 만들어야 하는데 이게 지금 작동하는 건지 안작동하는 건지 모르겠다..

일단 되는거 같아서 전달했다.

 

일단 로직은

구매를 하고 그 구매를 취소버튼을 누른 상태이다.

구매정보에 상태를 변경하고

구매를 한 게시물의 상태도 변경하고 보이는 상태도 변경해야 한다.

일단 구매정보 상태를 변경하는건 성공했는데

게시물의 상태를 변경하는게 안됐다..

@ResponseBody
    @PostMapping("/saveBuyInfo/{buyInfo_id}")
    public BuyInfoDto updateBuyInfo(@PathParam("buyInfo_id") Integer buyInfo_id){
        BuyInfoDto buyInfoDto = buyInfoService.findBuyInfoById(buyInfo_id);  

        if (buyInfoDto == null) { 
            return null;
        }

buyInfoDto.setDelete_time(LocalDateTime.now());

        boolean result = buyInfoService.updateBuyInfoByBuyStateDeleteTime(buyInfo_id, 0, LocalDateTime.now());

        ArtworkDto artworkDto = new ArtworkDto();
        artworkDto.setArtwork_id(buyInfoDto.getArtwork_id());
        artworkDto.setVisible(1);
        artworkDto.setArtwork_state(1);

        boolean result1 = artworkService.updateArtworkVisibleArtworkState(artworkDto.getArtwork_id(), 1,1);
        return null;


    }

처음엔 

      boolean result = buyInfoService.updateBuyInfoByBuyStateDeleteTime(buyInfo_id, 0, LocalDateTime.now());
      BuyInfoDto buyInfoDto = new BuyInfo();
        boolean result1 = artworkService.updateArtworkVisibleArtworkState(buyInfoDto.getArtwork_id(), 1,1);
        return null;

이것만 했는데 이게 변경이 안되는...

그래서 

    buyInfoDto.setVisible(1);
        buyInfoDto.setArtwork_state(1);

로 했는데도 변경이 안됐다..

그래서 뭐가 이상한가 봤더니 dto가.. artworkService는 artworkDto를 넣어야 하는건가 해서 변경해봤다.

        ArtworkDto artworkDto = new ArtworkDto();
        artworkDto.setArtwork_id(buyInfoDto.getArtwork_id());
        artworkDto.setVisible(1);
        artworkDto.setArtwork_state(1);

 boolean result1 = artworkService.updateArtworkVisibleArtworkState(artworkDto.getArtwork_id(), 1,1);

됐다.

 

작동했다. 변경이 됐다... 왜지..? 암튼.. 그렇게 얘는 작동을 했다.

 

근데 또 작동안할 까봐 두렵다.. 이게 진짜 맞는 코드라서 어디서든 언제든 작동되면 참 좋겠다..