Skip to content

Commit

Permalink
Sorted create functions
Browse files Browse the repository at this point in the history
  • Loading branch information
epadams committed Dec 6, 2023
1 parent bb28a11 commit 777f8ee
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 65 deletions.
63 changes: 0 additions & 63 deletions FU.SPA/src/services/createService.js

This file was deleted.

22 changes: 21 additions & 1 deletion FU.SPA/src/services/gameService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '../config';
const API_BASE_URL = config.API_URL;
const LOCAL_STORAGE_TOKEN_KEY = 'token';

/*
params = {
Expand All @@ -12,5 +13,24 @@ const searchGames = async (keyword) => {
return await response.json();
};

const GameService = { searchGames };
// Create game request
const createGame = async (params) => {
const response = await fetch(`${API_BASE_URL}/Games`, {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY),
},
body: JSON.stringify(params),
});

if (!response.ok) {
throw new Error('Error in game creation');
}
const jsonResponse = await response.json();

console.log(jsonResponse);
};

const GameService = { searchGames, createGame };
export default GameService;
25 changes: 25 additions & 0 deletions FU.SPA/src/services/postService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import config from '../config';
const API_BASE_URL = config.API_URL;
const LOCAL_STORAGE_TOKEN_KEY = 'token';

// Create post request
const createPost = async (params) => {
const response = await fetch(`${API_BASE_URL}/Posts`, {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY),
},
body: JSON.stringify(params),
});

if (!response.ok) {
throw new Error('Error in post creation');
}
const jsonResponse = await response.json();

console.log(jsonResponse);
};

const PostService = { createPost };
export default PostService;
22 changes: 21 additions & 1 deletion FU.SPA/src/services/tagService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '../config';
const API_BASE_URL = config.API_URL;
const LOCAL_STORAGE_TOKEN_KEY = 'token';

/*
params = {
Expand All @@ -12,5 +13,24 @@ const searchTags = async (keyword) => {
return await response.json();
};

const TagService = { searchTags };
// Create tag request
const createTag = async (params) => {
const response = await fetch(`${API_BASE_URL}/Tags`, {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY),
},
body: JSON.stringify(params),
});

if (!response.ok) {
throw new Error('Error in tag creation');
}
const jsonResponse = await response.json();

console.log(jsonResponse);
};

const TagService = { searchTags, createTag };
export default TagService;

0 comments on commit 777f8ee

Please sign in to comment.