-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1158] API. Create POST endpoint for v1/production-locations to support SLC & API Mod. #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
Merged
vladsha-dev
merged 34 commits into
main
from
OSDEV-1158-api-create-post-endpoint-for-v1-production-locations-to-support-slc-and-api-mod
Dec 6, 2024
Merged
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
eee6d63
Create PR
vladsha-dev 31013ba
Create POST endpoint
vladsha-dev 63d1066
Set up the code structure to handle the contribution moderation event
vladsha-dev 512b79d
remove print
vladsha-dev c8bed49
Implemented source(API or SLC) validation.
vladsha-dev 81afe75
Implemented triggering of ContriCleaner within the processor to colle…
vladsha-dev 53160f5
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev 4afe200
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev 621e710
Implement geocoding for data if coordinates information is missing.
vladsha-dev 1734ba5
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev 32b88ce
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev abd6a08
Implemented the final saving of the moderation event with a PENDING s…
vladsha-dev 804e1a8
Fix MR conflict
vladsha-dev fe6127c
Add type hints
vladsha-dev 2e85972
Fix MR conflict
vladsha-dev 3a78e99
Fix and update ContriCleaner and Countries tests
vladsha-dev 3050a24
Revert setting of the OAR_CLIENT_KEY value in the compose file
vladsha-dev 5562d85
Create a test for throttling and permission checks.
vladsha-dev 6a3bda8
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev 6e89a04
Create tests
vladsha-dev 26e8f3f
Fix tests
vladsha-dev 2863bce
Add print for debugging
vladsha-dev 0eae448
Fix test
vladsha-dev de0bdad
Create tests
vladsha-dev cb7e536
Write tests
vladsha-dev 2739c14
Fix MRs
vladsha-dev c1d4732
Fix MR conflict
vladsha-dev c147bdc
Update release notes and fix flake8 errors
vladsha-dev 1d7d44b
Update release notes
vladsha-dev f26e9a1
Remove redundant space
vladsha-dev 2cda5bc
Merge branch 'main' into OSDEV-1158-api-create-post-endpoint-for-v1-p…
vladsha-dev 8d99859
Handle comments
vladsha-dev 1cc6465
Add dot in the end of the comment
vladsha-dev 9ee130d
Handle comments
vladsha-dev 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
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
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
54 changes: 54 additions & 0 deletions
54
src/django/api/migrations/0162_update_moderationevent_table_fields.py
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,54 @@ | ||
| # Generated by Django 3.2.17 on 2024-11-26 16:27 | ||
|
|
||
| import django.contrib.postgres.indexes | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
| import uuid | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| ''' | ||
| This migration performs the following updates to the ModerationEvent table: | ||
| 1. Set uuid as the primary key. | ||
| 2. Make geocode_result field optional. It can be blank if lat and lng | ||
| have been provided by user. | ||
| 3. Remove redundant blank=False and null=False constraints, as these are | ||
| the default values for model fields in Django and do not need to be | ||
| explicitly set. | ||
| 4. Make contributor field non-nullable, as the field should not be left | ||
| empty. It is required to have information about the contributor. | ||
| 5. Allow claim field to be blank. This change reflects the fact that | ||
| a moderation event may not always be related to a claim, so the field can | ||
| be left empty. | ||
| ''' | ||
|
|
||
| dependencies = [ | ||
| ('api', '0161_create_disable_list_uploading'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveField( | ||
| model_name='moderationevent', | ||
| name='id', | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moderationevent', | ||
| name='claim', | ||
| field=models.OneToOneField(blank=True, help_text='Linked claim id for this production location.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='moderation_event_claim', to='api.facilityclaim'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moderationevent', | ||
| name='contributor', | ||
| field=models.ForeignKey(help_text='Linked contributor responsible for this moderation event.', on_delete=django.db.models.deletion.PROTECT, related_name='moderation_event_contributor', to='api.contributor'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moderationevent', | ||
| name='geocode_result', | ||
| field=models.JSONField(blank=True, default=dict, help_text='Result of the geocode operation.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='moderationevent', | ||
| name='uuid', | ||
| field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, help_text='Unique identifier to make moderation event table more reusable across the app.', primary_key=True, serialize=False, unique=True), | ||
| ), | ||
| ] |
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
19 changes: 19 additions & 0 deletions
19
src/django/api/moderation_event_actions/creation/dtos/create_moderation_event_dto.py
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,19 @@ | ||
| from dataclasses import dataclass, field | ||
| from typing import Dict | ||
|
|
||
| from rest_framework import status | ||
|
|
||
| from api.models.moderation_event import ModerationEvent | ||
|
|
||
|
|
||
| @dataclass | ||
| class CreateModerationEventDTO: | ||
| contributor_id: int | ||
| raw_data: Dict | ||
| request_type: str | ||
| cleaned_data: Dict = field(default_factory=dict) | ||
| source: str = '' | ||
| geocode_result: Dict = field(default_factory=dict) | ||
| errors: Dict = field(default_factory=dict) | ||
| status_code: int = status.HTTP_202_ACCEPTED | ||
| moderation_event: ModerationEvent = None |
12 changes: 12 additions & 0 deletions
12
src/django/api/moderation_event_actions/creation/event_creation_strategy.py
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,12 @@ | ||
| from abc import ABC, abstractmethod | ||
|
|
||
| from api.moderation_event_actions.creation.dtos.create_moderation_event_dto \ | ||
| import CreateModerationEventDTO | ||
|
|
||
|
|
||
| class EventCreationStrategy(ABC): | ||
| @abstractmethod | ||
| def serialize( | ||
| self, | ||
| event_dto: CreateModerationEventDTO) -> CreateModerationEventDTO: | ||
| pass |
46 changes: 46 additions & 0 deletions
46
...ango/api/moderation_event_actions/creation/location_contribution/location_contribution.py
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,46 @@ | ||
| from api.moderation_event_actions.creation.event_creation_strategy \ | ||
| import EventCreationStrategy | ||
| from api.moderation_event_actions.creation.location_contribution \ | ||
| .processors.contribution_processor import ContributionProcessor | ||
| from api.moderation_event_actions.creation.location_contribution \ | ||
| .processors.source_processor import SourceProcessor | ||
| from api.moderation_event_actions.creation.location_contribution \ | ||
| .processors.production_location_data_processor \ | ||
| import ProductionLocationDataProcessor | ||
| from api.moderation_event_actions.creation.location_contribution \ | ||
| .processors.geocoding_processor import GeocodingProcessor | ||
| from api.moderation_event_actions.creation.dtos.create_moderation_event_dto \ | ||
| import CreateModerationEventDTO | ||
|
|
||
|
|
||
| class LocationContribution(EventCreationStrategy): | ||
| ''' | ||
| The class-based algorithm that validates, extracts, and geocodes the | ||
| retrieved location data from the user before saving it as | ||
| a moderation event. | ||
| ''' | ||
|
|
||
| def serialize( | ||
| self, | ||
| event_dto: CreateModerationEventDTO) -> CreateModerationEventDTO: | ||
| entry_location_data_processor = self.__setup_location_data_processors() | ||
|
|
||
| processed_location_data = entry_location_data_processor.process( | ||
| event_dto | ||
| ) | ||
|
|
||
| return processed_location_data | ||
|
|
||
| @staticmethod | ||
| def __setup_location_data_processors() -> ContributionProcessor: | ||
VadimKovalenkoSNF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| location_data_processors = ( | ||
| SourceProcessor(), | ||
| ProductionLocationDataProcessor(), | ||
| GeocodingProcessor() | ||
| ) | ||
| # Link each processor to the next one. | ||
| for current_processor, next_processor in zip( | ||
| location_data_processors, location_data_processors[1:]): | ||
| current_processor.set_next(next_processor) | ||
|
|
||
| return location_data_processors[0] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.