-
Notifications
You must be signed in to change notification settings - Fork 4
<WIP> Admin Data Editor #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CasperL1218
wants to merge
10
commits into
main
Choose a base branch
from
admin-data-edit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
175c655
Added data tab with apartment data in admin page
CasperL1218 fca6e1c
doc for data tab
CasperL1218 1f98ab2
add export apartment name script
CasperL1218 590a533
Implemented Admin Page Apartment Editing UI\
CasperL1218 f5f8c65
Refactor apartment schema to support multiple room types
CasperL1218 f7a2dfb
Implement Room Types Admin UI and Display Utilities
CasperL1218 887d5ca
Implement apartment card display and search filtering for room types
CasperL1218 3831489
Enhance Admin Apartment Data tab with search, filters, and improved l…
CasperL1218 f26cff8
Add Create New Apartment functionality to Admin Data tab
CasperL1218 e2839fe
Fix search UX and improve results page layout
CasperL1218 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import axios from 'axios'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
|
|
||
| // Define the structure of the API response based on the AdminPage usage | ||
| interface ApartmentData { | ||
| buildingData: { | ||
| id: string; | ||
| name: string; | ||
| address: string; | ||
| area: string; | ||
| numBeds: number; | ||
| numBaths: number; | ||
| landlordId: string; | ||
| photos: string[]; | ||
| urlName: string; | ||
| latitude: number; | ||
| longitude: number; | ||
| distanceToCampus: number; | ||
| }; | ||
| numReviews: number; | ||
| company: string; | ||
| avgRating: number; | ||
| avgPrice: number; | ||
| } | ||
|
|
||
| interface ApiResponse { | ||
| buildingData: ApartmentData[]; | ||
| isEnded: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Script to export apartment names to a CSV file | ||
| * | ||
| * This script fetches all apartment data from the API endpoint used in AdminPage | ||
| * and exports just the apartment names to a CSV file. | ||
| */ | ||
| const exportApartmentNames = async () => { | ||
| try { | ||
| console.log('Fetching apartment data...'); | ||
|
|
||
| // Use the same API endpoint as AdminPage | ||
| const response = await axios.get<ApiResponse>( | ||
| 'http://localhost:8080/api/page-data/home/1000/numReviews' | ||
| ); | ||
|
|
||
| if (!response.data || !response.data.buildingData) { | ||
| throw new Error('No apartment data received from API'); | ||
| } | ||
|
|
||
| const apartments = response.data.buildingData; | ||
| console.log(`Found ${apartments.length} apartments`); | ||
|
|
||
| // Extract apartment names | ||
| const apartmentNames = apartments.map((apt) => apt.buildingData.name); | ||
|
|
||
| // Create CSV content | ||
| const csvHeader = 'Apartment Name\n'; | ||
| const csvContent = apartmentNames.map((name) => `"${name}"`).join('\n'); | ||
| const fullCsvContent = csvHeader + csvContent; | ||
|
|
||
| // Write to CSV file | ||
| const outputPath = path.join(__dirname, 'apartment_names.csv'); | ||
| fs.writeFileSync(outputPath, fullCsvContent, 'utf8'); | ||
|
|
||
| console.log(`Successfully exported ${apartmentNames.length} apartment names to: ${outputPath}`); | ||
| console.log('First few apartment names:'); | ||
| apartmentNames.slice(0, 5).forEach((name, index) => { | ||
| console.log(`${index + 1}. ${name}`); | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error exporting apartment names:', error); | ||
|
|
||
| if (axios.isAxiosError(error)) { | ||
| if (error.code === 'ECONNREFUSED') { | ||
| console.error( | ||
| 'Could not connect to the server. Make sure the backend server is running on localhost:3000' | ||
| ); | ||
| } else { | ||
| console.error('API request failed:', error.message); | ||
| } | ||
| } | ||
|
|
||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| // Run the script | ||
| exportApartmentNames(); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message says
localhost:3000but the code useslocalhost:8080.