Newer
Older
tampopo-server-dtram / src / main / java / org / example / tampoposerverdtram / resources / Users.java
package org.example.tampoposerverdtram.resources;

import java.util.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.client.*;
import jakarta.ws.rs.core.*;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;

@Path("/users")
@Component
public class Users {
	private Map<String, User> value = new HashMap<>();
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public Map<String, User> getValue() {
		return new HashMap<>(this.value);
	}
	public User getUser(String userId) {
		return this.value.get(userId);
	}
	@POST
	public void createUser(@FormParam("userId") String userId) {
		Map<String, User> temp_if38;
		if (this.value.containsKey(userId)) {
			temp_if38 = this.value;
		} else {
			this.value.put(userId,new User(null, null, null, new HashMap<>()));
			temp_if38 = this.value;
		}
		this.value = temp_if38;
	}
	@DELETE
	public void deleteUser(@FormParam("userId") String userId) {
		Map<String, User> temp_if40;
		if (this.value.containsKey(userId)) {
			this.value.remove(userId);
			temp_if40 = this.value;
		} else {
			temp_if40 = this.value;
		}
		this.value = temp_if40;
	}
	@Path("/{userId}/activities/{activityId}")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public Map<String, Object> getActivityValue(@PathParam("userId") String userId, @PathParam("activityId") int activityId) {
		return getUser(userId).getActivities().getActivity(activityId).getValue();
	}
	@Path("/{userId}/lastUpdatedTime")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public String getLastUpdatedTimeValue(@PathParam("userId") String userId) {
		return getUser(userId).getLastUpdatedTime();
	}
	@Path("/{userId}/name")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public String getNameValue(@PathParam("userId") String userId) {
		return getUser(userId).getName();
	}
	@Path("/{userId}/name")
	@PUT
	public void updateName(@PathParam("userId") String userId, @FormParam("name") String name) {
		getUser(userId).updateName(userId, name);
	}
	@Path("/{userId}")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public Map<String, Object> getUserValue(@PathParam("userId") String userId) {
		return getUser(userId).getValue();
	}
	@Path("/{userId}/email")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public String getEmailValue(@PathParam("userId") String userId) {
		return getUser(userId).getEmail();
	}
	@Path("/{userId}/email")
	@PUT
	public void updateEmail(@PathParam("userId") String userId, @FormParam("email") String email) {
		getUser(userId).updateEmail(userId, email);
	}
	@Path("/{userId}/activities")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public List<Activity> getActivitiesValue(@PathParam("userId") String userId) {
		return getUser(userId).getActivities().getValue();
	}
	@Path("/{userId}/activities")
	@POST
	public void postActivity(@PathParam("userId") String userId, @FormParam("updatedTime") String updatedTime, @FormParam("text") String text) {
		getUser(userId).getActivities().postActivity(userId, updatedTime, text);
	}
	@Path("/{user1Id}/friends")
	@DELETE
	public void updateFriendsFromDeletedFriendPair(@PathParam("user1Id") String user1Id, @FormParam("deletedFriendPair") Map<String, Object> deletedFriendPair) {
		getUser(user1Id).updateFriendsFromDeletedFriendPair(user1Id, deletedFriendPair);
	}
	@Path("/{user1Id}/friends")
	@DELETE
	public void updateFriendsFromDeletedFriendPair(@PathParam("user1Id") String user1Id, @FormParam("deletedFriendPair") Map<String, Object> deletedFriendPair) {
		getUser(user1Id).updateFriendsFromDeletedFriendPair(user1Id, deletedFriendPair);
	}
	@Path("/{user1Id}/friends")
	@POST
	public void updateFriendsFromPair(@PathParam("user1Id") String user1Id, @FormParam("pid") String pid, @FormParam("pair") Map<String, Object> pair) {
		getUser(user1Id).updateFriendsFromPair(user1Id, pid, pair);
	}
	@Path("/{user1Id}/friends")
	@POST
	public void updateFriendsFromPair(@PathParam("user1Id") String user1Id, @FormParam("pid") String pid, @FormParam("pair") Map<String, Object> pair) {
		getUser(user1Id).updateFriendsFromPair(user1Id, pid, pair);
	}
	@Path("/{user1Id}/friends")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public Map<String, String> getFriendsValue(@PathParam("user1Id") String user1Id) {
		return getUser(user1Id).getFriends();
	}
	@Path("/{userId}/activities/{activityId}/updatedTime")
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	public String getUpdatedTimeValue(@PathParam("userId") String userId, @PathParam("activityId") int activityId) {
		return getUser(userId).getActivities().getActivity(activityId).getUpdatedTime();
	}
}