Completing the CRUD for the widget domain.
This commit is contained in:
parent
e4f59ff941
commit
9cea9f94f2
|
|
@ -29,19 +29,19 @@ public class WidgetController extends BaseController {
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public Flux<ResponseDto<Widget>> getAllWidgets() {
|
public Flux<ResponseDto<Widget>> getAllWidgets() {
|
||||||
return widgetService.get()
|
return widgetService.get()
|
||||||
.map(user -> new ResponseDto<>(HttpStatus.OK.value(), user, null));
|
.map(widgets -> new ResponseDto<>(HttpStatus.OK.value(), widgets, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{name}")
|
@GetMapping("/{name}")
|
||||||
public Mono<ResponseDto<Widget>> getByName(@PathVariable String id) {
|
public Mono<ResponseDto<Widget>> getByName(@PathVariable String name) {
|
||||||
return widgetService.getByName(id)
|
return widgetService.getByName(name)
|
||||||
.map(user -> new ResponseDto<>(HttpStatus.OK.value(), user, null));
|
.map(widget -> new ResponseDto<>(HttpStatus.OK.value(), widget, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("")
|
||||||
public Mono<ResponseDto<Widget>> getCureFitUser(@PathVariable Long id) {
|
public Mono<ResponseDto<Widget>> update(@RequestBody Widget widget) throws Exception {
|
||||||
return widgetService.update(id)
|
return widgetService.update(widget)
|
||||||
.map(cfUser -> new ResponseDto<>(HttpStatus.OK.value(), cfUser, null));
|
.map(updatedWidget -> new ResponseDto<>(HttpStatus.OK.value(), updatedWidget, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.mobtools.server.domains;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
import org.springframework.data.annotation.CreatedBy;
|
import org.springframework.data.annotation.CreatedBy;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.annotation.LastModifiedBy;
|
import org.springframework.data.annotation.LastModifiedBy;
|
||||||
|
|
@ -18,6 +19,7 @@ import java.util.Date;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString
|
||||||
|
@DynamicUpdate
|
||||||
public abstract class BaseDomain implements Serializable {
|
public abstract class BaseDomain implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7459916000501322517L;
|
private static final long serialVersionUID = 7459916000501322517L;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
// Specially adding the table name here because the keyword "User" is reserved in Postgres
|
// Specially adding the table name here because the keyword "User" is reserved in Postgres
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,5 @@ import org.springframework.stereotype.Repository;
|
||||||
@Repository
|
@Repository
|
||||||
public interface WidgetRepository extends BaseRepository<Widget, Long> {
|
public interface WidgetRepository extends BaseRepository<Widget, Long> {
|
||||||
|
|
||||||
|
Widget findByName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public interface WidgetService {
|
public interface WidgetService {
|
||||||
|
|
||||||
Mono<Widget> getByName(String id);
|
Mono<Widget> getByName(String name);
|
||||||
|
|
||||||
Flux<Widget> get();
|
Flux<Widget> get();
|
||||||
|
|
||||||
Mono<Widget> create(Widget widget);
|
Mono<Widget> create(Widget widget);
|
||||||
|
|
||||||
Mono<Widget> update(Long id);
|
Mono<Widget> update(Widget widget) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,16 @@ public class WidgetServiceImpl extends BaseService implements WidgetService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Widget> getByName(String id) {
|
public Mono<Widget> getByName(String name) {
|
||||||
return null;
|
return Mono.fromCallable(() -> widgetRepository.findByName(name))
|
||||||
|
.subscribeOn(scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<Widget> get() {
|
public Flux<Widget> get() {
|
||||||
return null;
|
return Mono.fromCallable(() -> widgetRepository.findAll())
|
||||||
|
.flatMapMany(Flux::fromIterable)
|
||||||
|
.subscribeOn(scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -39,7 +42,13 @@ public class WidgetServiceImpl extends BaseService implements WidgetService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Widget> update(Long id) {
|
public Mono<Widget> update(Widget widget) throws Exception {
|
||||||
return null;
|
if(widget.getId() == null) {
|
||||||
|
throw new Exception("Invalid id provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Mono.fromCallable(
|
||||||
|
() -> widgetRepository.save(widget)
|
||||||
|
).subscribeOn(this.scheduler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user