Skip to content

Commit 15b2f19

Browse files
authored
Merge pull request #9 from RxssA/gets-all-booking
retrieves all bookings
2 parents cd8d08d + f3c7669 commit 15b2f19

File tree

9 files changed

+173
-4
lines changed

9 files changed

+173
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.data.annotation.Id;
4+
import org.springframework.data.mongodb.core.mapping.Document;
5+
6+
@Document(collection = "bookings")
7+
public class Booking {
8+
9+
@Id
10+
private String id;
11+
private String details;
12+
13+
// Getters and setters
14+
public String getId() {
15+
return id;
16+
}
17+
18+
public void setId(String id) {
19+
this.id = id;
20+
}
21+
22+
public String getDetails() {
23+
return details;
24+
}
25+
26+
public void setDetails(String details) {
27+
this.details = details;
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.*;
6+
7+
import java.util.List;
8+
9+
@RestController
10+
@RequestMapping("/bookings")
11+
public class BookingController {
12+
13+
@Autowired
14+
private BookingService bookingService;
15+
16+
@GetMapping
17+
public ResponseEntity<List<?>> getAllBookings() {
18+
return ResponseEntity.ok(bookingService.getAllBookings());
19+
}
20+
21+
@DeleteMapping("/{id}")
22+
public ResponseEntity<Void> deleteBooking(@PathVariable String id) {
23+
bookingService.deleteBooking(id);
24+
return ResponseEntity.noContent().build();
25+
}
26+
}
27+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.data.mongodb.repository.MongoRepository;
4+
5+
public interface BookingRepository extends MongoRepository<Booking, String> {
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.stereotype.Service;
4+
import java.util.List;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
7+
8+
@Service
9+
public class BookingService {
10+
11+
@Autowired
12+
private BookingRepository bookingRepository;
13+
14+
public List<?> getAllBookings() {
15+
return bookingRepository.findAll();
16+
}
17+
18+
public void deleteBooking(String id) {
19+
bookingRepository.deleteById(id);
20+
}
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.data.annotation.Id;
4+
import org.springframework.data.mongodb.core.mapping.Document;
5+
6+
@Document(collection = "users")
7+
public class User {
8+
9+
@Id
10+
private String id;
11+
private String name;
12+
13+
// Getters and setters
14+
public String getId() {
15+
return id;
16+
}
17+
18+
public void setId(String id) {
19+
this.id = id;
20+
}
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ie.atu.adminservice;
2+
import org.springframework.beans.factory.annotation.Autowired;
3+
import org.springframework.http.ResponseEntity;
4+
import org.springframework.web.bind.annotation.*;
5+
6+
7+
import java.util.List;
8+
9+
@RestController
10+
@RequestMapping("/users")
11+
public class UserController {
12+
13+
@Autowired
14+
private UserService userService;
15+
16+
@GetMapping
17+
public ResponseEntity<List<?>> getAllUsers() {
18+
return ResponseEntity.ok(userService.getAllUsers());
19+
}
20+
21+
@DeleteMapping("/{id}")
22+
public ResponseEntity<Void> deleteUser(@PathVariable String id) {
23+
userService.deleteUser(id);
24+
return ResponseEntity.noContent().build();
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.data.mongodb.repository.MongoRepository;
4+
5+
6+
public interface UserRepository extends MongoRepository<User, String> {
7+
}
8+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ie.atu.adminservice;
2+
3+
import org.springframework.stereotype.Service;
4+
import java.util.List;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
7+
8+
@Service
9+
public class UserService {
10+
11+
@Autowired
12+
private UserRepository userRepository;
13+
14+
public List<?> getAllUsers() {
15+
return userRepository.findAll();
16+
}
17+
18+
public void deleteUser(String id) {
19+
userRepository.deleteById(id);
20+
}
21+
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
spring.application.name=AdminService
2-
spring.data.mongodb.uri=mongodb://localhost:27019/adminservice
3-
spring.data.mongodb.database=adminservice
4-
server.port=8081
1+
server.port=8084
2+
spring.data.mongodb.uri=mongodb://localhost:27017/admin_service
3+
4+
spring.security.user.name=admin
5+
spring.security.user.password=admin123
6+
57

0 commit comments

Comments
 (0)