Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91ee248
commit 4c17813
Showing
10 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.tms.oknapvh.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
|
||
@Entity | ||
@Table(name = "users") | ||
public class UserEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
private String name; | ||
|
||
private String email; | ||
|
||
private String phone; | ||
|
||
private String address; | ||
|
||
private Integer order_id; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.tms.oknapvh.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
|
||
@Entity | ||
@Table(name = "windows") | ||
public class WindowEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
private String model; | ||
|
||
private Integer width; | ||
|
||
private Integer height; | ||
|
||
private Double price; | ||
|
||
private String manufacturer; | ||
|
||
private boolean availability; | ||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/tms/oknapvh/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tms.oknapvh.repository; | ||
|
||
import com.tms.oknapvh.model.UserEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<UserEntity, Integer> { | ||
|
||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/tms/oknapvh/repository/WindowRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tms.oknapvh.repository; | ||
|
||
import com.tms.oknapvh.model.WindowEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface WindowRepository extends JpaRepository<WindowEntity, Integer> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.tms.oknapvh.service; | ||
|
||
public interface UserService { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.tms.oknapvh.service; | ||
|
||
import com.tms.oknapvh.model.WindowEntity; | ||
|
||
import java.util.List; | ||
|
||
public interface WindowService { | ||
|
||
List<WindowEntity> getAll(); | ||
|
||
WindowEntity save(WindowEntity window); | ||
|
||
WindowEntity getById(Integer id); | ||
|
||
void delete(Integer id); | ||
|
||
WindowEntity update(WindowEntity window); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/tms/oknapvh/service/impl/WindowServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.tms.oknapvh.service.impl; | ||
|
||
import com.tms.oknapvh.model.WindowEntity; | ||
import com.tms.oknapvh.repository.WindowRepository; | ||
import com.tms.oknapvh.service.WindowService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WindowServiceImpl implements WindowService { | ||
|
||
private final WindowRepository repository; | ||
|
||
@Override | ||
public List<WindowEntity> getAll() { | ||
return repository.findAll(); | ||
} | ||
|
||
@Override | ||
public WindowEntity save(WindowEntity window) { | ||
return repository.save(window); | ||
} | ||
|
||
@Override | ||
public WindowEntity getById(Integer id) { | ||
return repository.findById(id).orElse(null); | ||
} | ||
|
||
@Override | ||
public void delete(Integer id) { | ||
repository.findById(id).ifPresent(repository::delete); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public WindowEntity update(WindowEntity window) { | ||
var windowFromDB = repository.findById(window.getId()).orElseThrow(RuntimeException::new); | ||
|
||
windowFromDB.setModel(window.getModel()); | ||
windowFromDB.setHeight(window.getHeight()); | ||
windowFromDB.setWidth(window.getWidth()); | ||
windowFromDB.setPrice(window.getPrice()); | ||
windowFromDB.setManufacturer(window.getManufacturer()); | ||
windowFromDB.setAvailability(window.isAvailability()); | ||
|
||
return windowFromDB; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.tms.oknapvh.web; | ||
|
||
import com.tms.oknapvh.model.WindowEntity; | ||
import com.tms.oknapvh.service.WindowService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/window") | ||
@RequiredArgsConstructor | ||
public class WindowResource { | ||
|
||
private final WindowService service; | ||
|
||
@GetMapping | ||
public List<WindowEntity> getAll() { | ||
return service.getAll(); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public WindowEntity getById(@PathVariable(name = "id") Integer id) { | ||
return service.getById(id); | ||
} | ||
|
||
@PostMapping | ||
public WindowEntity save(@RequestBody WindowEntity window) { | ||
return service.save(window); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public void deleteById(@PathVariable(name = "id") Integer id) { | ||
service.delete(id); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public WindowEntity update( | ||
@PathVariable(name = "id") String id, | ||
@RequestBody WindowEntity window) { | ||
window.setId(Integer.parseInt(id)); | ||
return service.update(window); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
server: | ||
port: 8080 | ||
|
||
spring: | ||
datasource: | ||
url: jdbc:postgresql://localhost:5432/postgres | ||
username: postgres | ||
password: admin | ||
jpa: | ||
hibernate: | ||
ddl-auto: create-drop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello from home jsp |