team-forAdhd / forAdhd-server

For ADHD 서버
1 stars 2 forks source link

약 탭 수정 및 보완 사항 #48

Closed newoceanwave closed 1 month ago

newoceanwave commented 2 months ago

💻 구현 내용

  1. 약 성분순 정렬 : 공공데이터 api에서 받아와 저장하는 약 정보에는 약 성분이 itemname에 들어있는 경우도 있고 chart에 들어있는 경우도 있고 성분을 따로 검색해서 보여주기가 애매해서 medicine 엔티티에 성분 타입을 구분할 수 있는 int ingredientType 을 추가했습니다. (1: 메틸페니데이트 염산염, 2: 아토목세틴 염산염, 3: 클로니딘 염산염).

  2. 약 모양으로 검색 시 제형 처리 : 약 성분순 정렬과 마찬가지로 제형 또한 정보가 하나로 모아져있지 않아서, medicine 엔티티에 제형 타입을 구분할 수 있는 int tabletType을 추가했습니다. (1: 정제, 2: 경질캡슐, 3: 연질캡슐)

  3. 약 리뷰 responsedto custom paging : 약 리뷰 또한 다은님께서 작성해주신 pagingresponse를 사용하도록 수정했습니다. 응답값은 다음과 같습니다.

    {
    "data": [
        {
            "id": 1,
            "medicineId": 1,
            "content": "{\"header\":{\"resultCode\":\"00\",\"resultMsg\":\"NORMAL SERVICE.\"},\"body\":{\"pageNo\":1,\"totalCount\":0,\"numOfRows\":10}}",
            "images": [
                "http://example.com/image1.jpg",
                "http://example.com/image2.jpg"
            ],
            "grade": 5,
            "helpCount": 0,
            "coMedications": [
                2,
                3
            ],
            "nickname": "이헨",
            "profileImage": "http://",
            "ageRange": "20대",
            "gender": "FEMALE",
            "averageGrade": 4,
            "createdAt": 1722060126,
            "lastModifiedAt": 1722060126
        },
        {
            "id": 2,
            "medicineId": 1,
            "content": "{\"header\":{\"resultCode\":\"00\",\"resultMsg\":\"NORMAL SERVICE.\"},\"body\":{\"pageNo\":1,\"totalCount\":0,\"numOfRows\":10}}",
            "images": [
                "http://example.com/image1.jpg",
                "http://example.com/image2.jpg"
            ],
            "grade": 4.5,
            "helpCount": 0,
            "coMedications": [
                2,
                3
            ],
            "nickname": "이헨",
            "profileImage": "http://",
            "ageRange": "20대",
            "gender": "FEMALE",
            "averageGrade": 4,
            "createdAt": 1722060133,
            "lastModifiedAt": 1722060133
        },
        {
            "id": 3,
            "medicineId": 1,
            "content": "{\"header\":{\"resultCode\":\"00\",\"resultMsg\":\"NORMAL SERVICE.\"},\"body\":{\"pageNo\":1,\"totalCount\":0,\"numOfRows\":10}}",
            "images": [
                "http://example.com/image1.jpg",
                "http://example.com/image2.jpg"
            ],
            "grade": 4,
            "helpCount": 0,
            "coMedications": [
                2,
                3
            ],
            "nickname": "이헨",
            "profileImage": "http://",
            "ageRange": "20대",
            "gender": "FEMALE",
            "averageGrade": 4,
            "createdAt": 1722060143,
            "lastModifiedAt": 1722060143
        },
        {
            "id": 4,
            "medicineId": 1,
            "content": "{\"header\":{\"resultCode\":\"00\",\"resultMsg\":\"NORMAL SERVICE.\"},\"body\":{\"pageNo\":1,\"totalCount\":0,\"numOfRows\":10}}",
            "images": [
                "http://example.com/image1.jpg",
                "http://example.com/image2.jpg"
            ],
            "grade": 2.5,
            "helpCount": 0,
            "coMedications": [
                2,
                3
            ],
            "nickname": "이헨",
            "profileImage": "http://",
            "ageRange": "20대",
            "gender": "FEMALE",
            "averageGrade": 4,
            "createdAt": 1722060150,
            "lastModifiedAt": 1722060150
        }
    ],
    "paging": {
        "page": 0,
        "size": 10,
        "totalPages": 1,
        "numberOfElements": 4,
        "totalElements": 4,
        "isFirst": true,
        "isLast": true,
        "isEmpty": false
    }
    }
  4. 약 리뷰 작성 시 해당 약에 대한 별점 실시간 반영 : 사용자들이 약에 대해 리뷰를 작성할 때마다 해당 약에 대한 rating에 반영되도록 수정하였습니다.

    private void updateMedicineRating(Medicine medicine) {
        double averageGrade = medicine.calculateAverageGrade();
        Medicine updatedMedicine = medicine.toBuilder()
                .rating(averageGrade)
                .build();
        medicineRepository.save(updatedMedicine);
    }
  5. 약 리뷰 도움돼요 한 번 누르면 +1, 다시 누르면 -1 : 한 번 클릭하면 +1, 다시 누르면 취소되도록 수정했습니다.

🛠️ 개발 오류 사항

다음과 같이 요청값을 넣을 경우 db에는

스크린샷 2024-07-27 오후 3 27 11

content가 요청값과 동일하게 저장되는데, postman으로 테스트 시 응답값이

{
    "id": 4,
    "medicineId": 1,
    "content": "{\"header\":{\"resultCode\":\"00\",\"resultMsg\":\"NORMAL SERVICE.\"},\"body\":{\"pageNo\":1,\"totalCount\":0,\"numOfRows\":10}}",
    "images": [
        "http://example.com/image1.jpg",
        "http://example.com/image2.jpg"
    ],
    "grade": 2.5,
    "helpCount": 0,
    "coMedications": [
        2,
        3
    ],
    "nickname": "이헨",
    "profileImage": "http://",
    "ageRange": "20대",
    "gender": "FEMALE",
    "averageGrade": 4.0,
    "createdAt": 1722060150,
    "lastModifiedAt": 1722060150
}

다음과 같이 반환됩니다. 관련 매퍼와 컨트롤러, 서비스 구현체 등 확인해보았지만 이유를 찾지 못했습니다..!

🗣️ For 리뷰어

close #44