Skip to content
Snippets Groups Projects
Commit 10272809 authored by Bruno Teixeira's avatar Bruno Teixeira
Browse files

started Backend User functionality

parent ea648b2e
No related branches found
No related tags found
No related merge requests found
package com.mobilecomputing.pecunia.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/api", method = RequestMethod.GET)
public class TestController {
@GetMapping
public String test(){
return "hello World";
}
}
package com.mobilecomputing.pecunia.controller;
import com.mobilecomputing.pecunia.repository.TripRepository;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/trip", method = RequestMethod.GET)
public class TripController {
@Autowired
TripRepository tripRepository;
@GetMapping("/getTripById")
public String getTripById(@RequestParam String id){
return String.valueOf(tripRepository.findById(new ObjectId(id)));
}
@GetMapping("/getAllTrips")
public String getAllTrips(){
tripRepository.findAll().forEach(trip->{
System.out.println(trip.toString());
});
return "to do";
}
}
package com.mobilecomputing.pecunia.controller;
import com.mobilecomputing.pecunia.model.User;
import com.mobilecomputing.pecunia.repository.UserRepository;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/user", method = RequestMethod.GET)
public class UserController {
@Autowired
UserRepository userRepository;
@GetMapping("/getById")
public String getUserById(@RequestParam String id){
return String.valueOf(userRepository.findById(new ObjectId(id)));
}
@GetMapping("/getAll")
public String getAllUsers(){
String response ="";
userRepository.findAll().forEach(user -> {
System.out.println(user.toString());
});
return String.valueOf(userRepository.findAll());
}
@PostMapping("/registrateUser")
public String registrateUser(@RequestParam String eMail, @RequestParam String name, @RequestParam String surname,
@RequestParam String password){
User user = new User();
user.seteMail(eMail); // überprüfen ob email schon vergeben ist
user.setName(name);
user.setSurname(surname);
user.setPassword(password);
userRepository.save(user);
return "ok?";
}
@DeleteMapping("/deleteUser")
public void deleteUser(@RequestParam String eMail){
userRepository.deleteById(new ObjectId(eMail));
}
}
package com.mobilecomputing.pecunia.model;
import org.springframework.data.annotation.Id;
import java.util.Date;
import java.util.List;
public class Trip {
@Id
private String tripId;
private String tripName;
private Date startOfTrip;
private Date endOfTrip;
private List<User> tripParticipants;
public Trip(String tripId, String tripName, Date startOfTrip, Date endOfTrip, List<User> tripParticipants) {
this.tripId = tripId;
this.tripName = tripName;
this.startOfTrip = startOfTrip;
this.endOfTrip = endOfTrip;
this.tripParticipants = tripParticipants;
}
public String getTripId() {
return tripId;
}
public void setTripId(String tripId) {
this.tripId = tripId;
}
public String getTripName() {
return tripName;
}
public void setTripName(String tripName) {
this.tripName = tripName;
}
public Date getStartOfTrip() {
return startOfTrip;
}
public void setStartOfTrip(Date startOfTrip) {
this.startOfTrip = startOfTrip;
}
public Date getEndOfTrip() {
return endOfTrip;
}
public void setEndOfTrip(Date endOfTrip) {
this.endOfTrip = endOfTrip;
}
public List<User> getTripParticipants() {
return tripParticipants;
}
public void setTripParticipants(List<User> tripParticipants) {
this.tripParticipants = tripParticipants;
}
}
package com.mobilecomputing.pecunia.model;
import org.springframework.data.annotation.Id;
public class User {
@Id
private String eMail;
private String name;
private String surname;
private String password;
public String geteMail() {
return eMail;
}
public void seteMail(String eMail) {
this.eMail = eMail;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"eMail='" + eMail + '\'' +
", name='" + name + '\'' +
", surname='" + surname + '\'' +
", password='" + password + '\'' +
'}';
}
}
package com.mobilecomputing.pecunia.repository;
import com.mobilecomputing.pecunia.model.Trip;
import org.bson.types.ObjectId;
import org.springframework.data.repository.CrudRepository;
public interface TripRepository extends CrudRepository<Trip, ObjectId> {
}
package com.mobilecomputing.pecunia.repository;
import com.mobilecomputing.pecunia.model.Trip;
import com.mobilecomputing.pecunia.model.User;
import org.bson.types.ObjectId;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, ObjectId> {
}
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment