Skip to content

Commit

Permalink
feat: 떡국 랜덤 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Feb 8, 2024
1 parent 3d7365a commit 5c335b7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public RequestMatcher authEndpoints() {
public RequestMatcher mainPageEndPoints() {
return new OrRequestMatcher(
new AntPathRequestMatcher("/api/v1/tteokguk/new/**"),
new AntPathRequestMatcher("/api/v1/tteokguk/completion/**")
new AntPathRequestMatcher("/api/v1/tteokguk/completion/**"),
new AntPathRequestMatcher("/api/v1/tteokguk/random/**")
);
}

Expand All @@ -33,10 +34,10 @@ public RequestMatcher serverInfoEndpoints() {

public RequestMatcher userEndpoints() {
return new OrRequestMatcher(
new AntPathRequestMatcher("/api/v1/user", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/all", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/{id:\\d+}", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/random", HttpMethod.GET.toString())
new AntPathRequestMatcher("/api/v1/user", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/all", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/{id:\\d+}", HttpMethod.GET.toString()),
new AntPathRequestMatcher("/api/v1/user/random", HttpMethod.GET.toString())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public TteokgukResponse createTteokguk(
return TteokgukResponseAssembler.toTteokgukResponse(savedTteokguk);
}

public TteokgukResponse getRandomTteokguk() {
Tteokguk randomTteokguk = tteokgukRepository.findRandomTteokguk();
return TteokgukResponseAssembler.toTteokgukResponse(randomTteokguk);
}

public void deleteTteokguk(
Long id,
Long tteokgukId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public interface TteokgukRepository extends JpaRepository<Tteokguk, Long> {

@Query("SELECT t FROM Tteokguk t WHERE t.access = true and t.member.deleted = false and t.completion = true ORDER BY t.id DESC")
List<Tteokguk> findCompletionTteokguks(Pageable pageable);

@Query(value = "SELECT t FROM Tteokguk t WHERE t.deleted = false ORDER BY RAND() LIMIT 1")
Tteokguk findRandomTteokguk();
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public ResponseEntity<TteokgukResponse> useIngredient(
return ResponseEntity.ok(response);
}

@GetMapping("/random")
public ResponseEntity<TteokgukResponse> getRandomTteokguk() {
TteokgukResponse response = tteokgukService.getRandomTteokguk();
return ResponseEntity.ok(response);
}

@GetMapping("/new")
public ResponseEntity<ApiPageResponse<TteokgukResponse>> findNewTteokguks(
@AuthId Long id,
Expand Down

0 comments on commit 5c335b7

Please sign in to comment.