Skip to content

Commit

Permalink
add anotations
Browse files Browse the repository at this point in the history
  • Loading branch information
puzant committed Aug 3, 2024
1 parent 65ecdf2 commit a1d59ca
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/api/account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import axios from "./axiosInstance";
import { IAccount, IMovieList } from "@/interfaces";

/**
*
* @param {string} sessionId
* @returns {Promise<IAccount}
*/
export const getAccountDetails = (sessionId: string): Promise<IAccount> => {
return axios.get(`/account?session_id=${sessionId}`);
};

/**
*
* @param {string} accountId
* @param {string} sessionId
* @param {string} language
* @returns {Promise<IMovieList[]>}
*/
export const getFavoriteMovies = (
accountId: string,
sessionId: string,
Expand All @@ -15,6 +27,13 @@ export const getFavoriteMovies = (
});
};

/**
*
* @param {string} accountId
* @param {string} sessionId
* @param {string} language
* @returns {Promise<IMovieList[]>}
*/
export const getMoviesInWatchlist = (
accountId: string,
sessionId: string,
Expand All @@ -25,6 +44,13 @@ export const getMoviesInWatchlist = (
});
};

/**
*
* @param {string} accountId
* @param {string} sessionId
* @param {string} language
* @returns {<IMovieList[]>}
*/
export const getRatedMovies = (
accountId: string,
sessionId: string,
Expand Down
27 changes: 23 additions & 4 deletions src/api/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import axios from './axiosInstance'
import { IPostLoginBody } from '@/interfaces'

/**
* Authenticates the user with the given credentials and request token.
*
* @param {Object} loginData
* @param {string} loginData.username
* @param {string} loginData.password
* @param {string} loginData.requestToken
* @returns {Promise<AxiosResponse>}
*/
export const login = ({ username, password, requestToken }: IPostLoginBody) => {
return axios.post('authentication/token/validate_with_login', {
username,
Expand All @@ -9,11 +18,21 @@ export const login = ({ username, password, requestToken }: IPostLoginBody) => {
})
}

/**
*
* @param {Object} sessionObject
* @param {string} requestToken
* @returns {Promise<AxiosResponse>}
*/
export const createSession = ({ requestToken }: { requestToken: string }) =>
axios.post('/authentication/session/new', { request_token: requestToken });

export const deleteSession = (sessionId: string) => {
return axios.delete('/authentication/session', { data: { session_id: sessionId } });
}
/**
*
* @param sessionId
* @returns {Promise<AxiosResponse>}
*/
export const deleteSession = (sessionId: string) =>
axios.delete('/authentication/session', { data: { session_id: sessionId } });

export const getRequestToken = () => axios.get('/authentication/token/new')
export const getRequestToken = () => axios.get('/authentication/token/new')
58 changes: 58 additions & 0 deletions src/api/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
IMovieResponse,
} from "@/interfaces";

/**
* Fetches a list of movies based on various filters.
*
* @param {IPopularMoviesParams} params - The parameters for fetching popular movies.
* @returns {Promise<IMovie[]>} A promise that resolves to a list of movies.
*/
export const getMovies = ({
sortBy,
selectedGenres,
Expand All @@ -32,13 +38,27 @@ export const getMovies = ({
});
};

/**
* Fetches a list of upcoming movies.
*
* @param {string} selectedLanguage - The language for the movie data.
* @param {number} [page=1] - The page number for pagination.
* @returns {Promise<IMovie[]>} A promise that resolves to a list of upcoming movies.
*/
export const getUpcomingMovies = (
selectedLanguage: string,
page: number = 1
): Promise<IMovie[]> => {
return axios.get(`/movie/upcoming?language=${selectedLanguage}&page=${page}`);
};

/**
* Searches for movies based on a query string.
*
* @param {string} query - The search query.
* @param {number} [page=1] - The page number for pagination.
* @returns {Promise<IMovie[]>} A promise that resolves to a list of movies matching the query.
*/
export const searchMovies = async (query: string, page: number = 1): Promise<IMovie[]> => {
const response = await axios.get("/search/movie", {
params: {
Expand All @@ -49,6 +69,14 @@ export const searchMovies = async (query: string, page: number = 1): Promise<IMo
return response.data;
};

/**
* Fetches details for a specific movie.
*
* @param {string | undefined} movieId - The ID of the movie.
* @param {string} sessionId - The session ID for the user.
* @param {string} selectedLanguage - The language for the movie data.
* @returns {Promise<IMovie>} A promise that resolves to the movie details.
*/
export const getMovie = (
movieId: string | undefined,
sessionId: string,
Expand All @@ -62,10 +90,22 @@ export const getMovie = (
});
};

/**
* Fetches a list of movie genres.
*
* @param {string} selectedLanguage - The language for the genre data.
* @returns {Promise<any>} A promise that resolves to the list of genres.
*/
export const getGenres = (selectedLanguage: string): Promise<any> => {
return axios.get(`/genre/movie/list?language=${selectedLanguage}`);
};

/**
* Marks a movie as favorite for the user.
*
* @param {IFavoriteMoviePayload} payload - The payload containing account ID, session ID, movie ID, and favorite status.
* @returns {Promise<IMovieResponse>} A promise that resolves to the response of the favorite action.
*/
export const setFavoriteMovie = ({
accountId,
sessionId,
Expand All @@ -79,6 +119,12 @@ export const setFavoriteMovie = ({
});
};

/**
* Adds or removes a movie from the user's watchlist.
*
* @param {IWatchListPayload} payload - The payload containing account ID, session ID, movie ID, and watchlist status.
* @returns {Promise<IMovieResponse>} A promise that resolves to the response of the watchlist action.
*/
export const setMovieInWatchList = ({
accountId,
sessionId,
Expand All @@ -92,12 +138,24 @@ export const setMovieInWatchList = ({
});
};

/**
* Rates a movie for the user.
*
* @param {IRatingPayload} payload - The payload containing movie ID, rating, and session ID.
* @returns {Promise<IMovieResponse>} A promise that resolves to the response of the rating action.
*/
export const rateMovie = ({ id, rating, sessionId }: IRatingPayload): Promise<IMovieResponse> => {
return axios.post(`/movie/${id}/rating?session_id=${sessionId}`, {
value: rating,
});
};

/**
* Deletes the user's rating for a movie.
*
* @param {IDeleteRatingPayload} payload - The payload containing movie ID and session ID.
* @returns {Promise<IMovieResponse>} A promise that resolves to the response of the delete rating action.
*/
export const deleteMovieRating = ({
id,
sessionId,
Expand Down

0 comments on commit a1d59ca

Please sign in to comment.