Skip to content

Commit

Permalink
Merge pull request #75 from vicheanath/optimize
Browse files Browse the repository at this point in the history
Optimize code
  • Loading branch information
DBunthai authored Feb 19, 2024
2 parents 5f09a31 + c5a47bd commit 369cce7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
26 changes: 25 additions & 1 deletion backend/pms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ CREATE DATABASE "pms-db";

<br>

#### 5. Create Access Token
#### 5. Create Access / Refresh Token

<br>

##### Access Token

You can paste this in Postman or run in a terminal

Expand All @@ -66,6 +70,26 @@ response:
```
<br>

##### Refresh Token

```shell
curl --location --request POST 'http://localhost:8080/api/v1/token/refresh' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJI...'

```

response:

```json
{
"accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJyb2xlcyI6W3sicm9sZSI6IkFkbWluIn1dLCJleHAiOjE3MDcwNzYxNjAsImlhdCI6MTcwNzA3NTU2MCwiZW1haWwiOiJhQGEuY29tIn0.rw0kPwa9Jpi8vNgBtej3X4QH0rDN69h1jg-sQtUY4w-sjnjYJSrpMq1S3CKOoiYL8ZWffrvX9b2uSDQNhP4GVw",
"refreshToken": "eyJhbGciOiJIUzUxMiJ9.eyJyb2xlcyI6W3sicm9sZSI6IkFkbWluIn1dLCJleHAiOjE3MDcwNzY3NjEsImlhdCI6MTcwNzA3NTU2MSwiZW1haWwiOiJhQGEuY29tIn0.HmEI79h6_IZBsZDv73kMd6XTcfz5PJBq2WrZPXNXBt1vco-osuq5PiEzDPIAn_KYTVvlb8CSlEybyJMqss8tKQ"
}
```

<br>

---

<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface FavoriteRepo extends JpaRepository<Favorite,Long> {

boolean existsByMemberAndProperty(Member member, Property property);

void deleteByMemberAndProperty(Member member, Property property);
int deleteByMemberAndProperty(Member member, Property property);

List<Favorite> findByMemberId(long memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
import com.mini.pms.service.MemberService;
import com.mini.pms.util.Util;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.security.Principal;

import java.util.List;

@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("api/v1/users")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public void addFavorite(long propertyId, long memberId) {
public void removeFavorite(long propertyId, long memberId) {
Member member = memberService.profile(memberId);
Property property = propertyService.findById(propertyId);
favoriteRepo.deleteByMemberAndProperty(member, property);
int isDeleted = favoriteRepo.deleteByMemberAndProperty(member, property);
if (isDeleted == 0) {
throw new PlatformException("Favorite not found", HttpStatus.NOT_FOUND);
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion backend/pms/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: false
format_sql: true
show-sql: true
defer-datasource-initialization: true
generate-ddl: true
Expand Down

0 comments on commit 369cce7

Please sign in to comment.